@get-dx/cli 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +2 -0
- package/dist/commands/teams.js +69 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import { catalogCommand } from "./commands/catalog.js";
|
|
|
4
4
|
import { initCommand } from "./commands/init.js";
|
|
5
5
|
import { scorecardsCommand } from "./commands/scorecards.js";
|
|
6
6
|
import { studioCommand } from "./commands/studio.js";
|
|
7
|
+
import { teamsCommand } from "./commands/teams.js";
|
|
7
8
|
import { handleError } from "./commandHelpers.js";
|
|
8
9
|
import cliPackage from "../package.json" with { type: "json" };
|
|
9
10
|
export async function run(argv = process.argv) {
|
|
@@ -33,6 +34,7 @@ function createProgram() {
|
|
|
33
34
|
program.addCommand(initCommand());
|
|
34
35
|
program.addCommand(scorecardsCommand());
|
|
35
36
|
program.addCommand(studioCommand());
|
|
37
|
+
program.addCommand(teamsCommand());
|
|
36
38
|
applyExitOverride(program);
|
|
37
39
|
return program;
|
|
38
40
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { createExampleText, getContext, wrapAction, } from "../commandHelpers.js";
|
|
3
|
+
import { request } from "../http.js";
|
|
4
|
+
import { renderJson, renderRichText } from "../renderers.js";
|
|
5
|
+
import { buildRuntime } from "../runtime.js";
|
|
6
|
+
import * as ui from "../ui.js";
|
|
7
|
+
export function teamsCommand() {
|
|
8
|
+
const teams = new Command().name("teams").description("Manage DX teams");
|
|
9
|
+
teams
|
|
10
|
+
.command("list")
|
|
11
|
+
.description("List all teams in DX")
|
|
12
|
+
.addHelpText("afterAll", createExampleText([
|
|
13
|
+
{
|
|
14
|
+
label: "List all teams",
|
|
15
|
+
command: "dx teams list",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
label: "List all teams as JSON",
|
|
19
|
+
command: "dx --json teams list",
|
|
20
|
+
},
|
|
21
|
+
]))
|
|
22
|
+
.action(wrapAction(async (_options, command) => {
|
|
23
|
+
const runtime = buildRuntime(getContext(command));
|
|
24
|
+
const response = await listTeams(runtime);
|
|
25
|
+
if (runtime.context.json) {
|
|
26
|
+
renderJson(response);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
renderTeams(response.teams);
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
return teams;
|
|
33
|
+
}
|
|
34
|
+
async function listTeams(runtime) {
|
|
35
|
+
const response = await request(runtime, "/teams.list", {
|
|
36
|
+
method: "GET",
|
|
37
|
+
});
|
|
38
|
+
return response.body;
|
|
39
|
+
}
|
|
40
|
+
function renderTeams(teams) {
|
|
41
|
+
const blocks = [ui.h1("Teams")];
|
|
42
|
+
blocks.push(ui.p(`Displaying ${ui.bold(teams.length.toString())} teams.`));
|
|
43
|
+
for (const team of teams) {
|
|
44
|
+
blocks.push(ui.h2(`${team.name} (${ui.code(team.id)})`));
|
|
45
|
+
blocks.push(ui.dl([
|
|
46
|
+
ui.dli("Reference ID", formatText(team.reference_id)),
|
|
47
|
+
ui.dli("Parent ID", formatText(team.parent_id)),
|
|
48
|
+
ui.dli("Manager ID", formatText(team.manager_id)),
|
|
49
|
+
ui.dli("Ancestors", team.ancestors && team.ancestors.length > 0
|
|
50
|
+
? team.ancestors.map((ancestor) => ui.code(ancestor)).join(", ")
|
|
51
|
+
: ui.dim("(None)")),
|
|
52
|
+
ui.dli("Contributors", typeof team.contributors === "number"
|
|
53
|
+
? team.contributors.toString()
|
|
54
|
+
: ui.dim("(Unknown)")),
|
|
55
|
+
ui.dli("Parent team", typeof team.parent === "boolean"
|
|
56
|
+
? team.parent
|
|
57
|
+
? "Yes"
|
|
58
|
+
: "No"
|
|
59
|
+
: ui.dim("(Unknown)")),
|
|
60
|
+
ui.dli("Last changed", team.last_changed_at
|
|
61
|
+
? ui.timestampSummary(team.last_changed_at)
|
|
62
|
+
: ui.dim("(None)")),
|
|
63
|
+
], { termWidth: 14 }));
|
|
64
|
+
}
|
|
65
|
+
renderRichText(blocks);
|
|
66
|
+
}
|
|
67
|
+
function formatText(value) {
|
|
68
|
+
return value ? ui.code(value) : ui.dim("(None)");
|
|
69
|
+
}
|