bdy 1.23.13 → 1.23.14-dev

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.
Files changed (38) hide show
  1. package/distTs/package.json +3 -1
  2. package/distTs/src/api/client.js +259 -24
  3. package/distTs/src/cliIndex.js +4 -0
  4. package/distTs/src/command/api/request.js +5 -4
  5. package/distTs/src/command/artifact/list.js +2 -6
  6. package/distTs/src/command/distro/list.js +1 -0
  7. package/distTs/src/command/distro/route/update.js +1 -1
  8. package/distTs/src/command/distro/update.js +9 -9
  9. package/distTs/src/command/environment/create.js +70 -0
  10. package/distTs/src/command/environment/delete.js +30 -0
  11. package/distTs/src/command/environment/get.js +48 -0
  12. package/distTs/src/command/environment/list.js +45 -0
  13. package/distTs/src/command/environment/resolve.js +39 -0
  14. package/distTs/src/command/environment/update.js +60 -0
  15. package/distTs/src/command/environment.js +20 -0
  16. package/distTs/src/command/project/git/credential.js +6 -4
  17. package/distTs/src/command/sandbox/exec/command.js +1 -1
  18. package/distTs/src/command/sandbox/exec/logs.js +1 -1
  19. package/distTs/src/command/target/create.js +33 -0
  20. package/distTs/src/command/target/delete.js +31 -0
  21. package/distTs/src/command/target/exec/command.js +101 -0
  22. package/distTs/src/command/target/exec/kill.js +31 -0
  23. package/distTs/src/command/target/exec/list.js +53 -0
  24. package/distTs/src/command/target/exec/logs.js +27 -0
  25. package/distTs/src/command/target/exec/status.js +44 -0
  26. package/distTs/src/command/target/exec.js +24 -0
  27. package/distTs/src/command/target/get.js +63 -0
  28. package/distTs/src/command/target/list.js +49 -0
  29. package/distTs/src/command/target/scope.js +138 -0
  30. package/distTs/src/command/target/update.js +32 -0
  31. package/distTs/src/command/target.js +22 -0
  32. package/distTs/src/index.js +14 -0
  33. package/distTs/src/input.js +65 -0
  34. package/distTs/src/output/pipeline.js +5 -3
  35. package/distTs/src/output.js +30 -2
  36. package/distTs/src/texts.js +251 -27
  37. package/distTs/src/utils.js +18 -2
  38. package/package.json +3 -1
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const input_1 = __importDefault(require("../../input"));
10
+ const distro_1 = require("../../types/distro");
11
+ const commandEnvironmentList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_ENVIRONMENT_LIST);
12
+ commandEnvironmentList.alias('ls');
13
+ commandEnvironmentList.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
14
+ commandEnvironmentList.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
15
+ commandEnvironmentList.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
16
+ commandEnvironmentList.option('--format <text|json>', texts_1.OPTION_FORMAT);
17
+ commandEnvironmentList.addHelpText('after', `\nEXAMPLES:${texts_1.EXAMPLE_ENVIRONMENT_LIST}`);
18
+ commandEnvironmentList.action(async (options) => {
19
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
20
+ const project = input_1.default.restApiProject(options.project, true);
21
+ const scope = input_1.default.scope(project, options.scope);
22
+ input_1.default.projectScopeNote(options, project, scope, 'environments');
23
+ const client = input_1.default.restApiTokenClient();
24
+ const result = await client.getEnvironments(workspace, scope === distro_1.SCOPE.PROJECT ? project : null);
25
+ const environments = result.environments || [];
26
+ if (options.format === 'json') {
27
+ output_1.default.json(environments);
28
+ }
29
+ else {
30
+ if (environments.length === 0) {
31
+ output_1.default.exitNormal(texts_1.TXT_ENVIRONMENT_NOT_FOUND);
32
+ }
33
+ const data = [['NAME', 'IDENTIFIER', 'SCOPE']];
34
+ for (const environment of environments) {
35
+ data.push([
36
+ environment.name || '-',
37
+ environment.identifier || '-',
38
+ environment.scope || '-',
39
+ ]);
40
+ }
41
+ output_1.default.table(data);
42
+ }
43
+ output_1.default.exitNormal();
44
+ });
45
+ exports.default = commandEnvironmentList;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveEnvironmentId = void 0;
7
+ const texts_1 = require("../../texts");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const input_1 = __importDefault(require("../../input"));
10
+ // Shared resolve preamble for commands taking an environment identifier:
11
+ // project context from flags/env -> /identifiers -> hash id, exiting on a
12
+ // miss. Without a project the identifier resolves as a workspace
13
+ // environment; with one, along the project line.
14
+ //
15
+ // strictProject is for mutating commands (update/delete): an explicit -p is
16
+ // a statement "the environment of this project", so the resolved environment
17
+ // must actually live there. Without it /identifiers silently falls back to
18
+ // the workspace environment of the same identifier and the write lands on a
19
+ // workspace-wide resource. Reads keep the fallback - that is how workspace
20
+ // environments stay addressable from inside a project context.
21
+ const resolveEnvironmentId = async (client, workspace, identifier, options, strictProject = false) => {
22
+ const project = input_1.default.restApiProject(options.project, true);
23
+ const resolved = await client.getEnvironmentByIdentifier(workspace, identifier, project);
24
+ // A nonexistent project is rejected by the API client
25
+ // (getResourceByIdentifier); here only the environment itself can miss.
26
+ if (!resolved.environment_id) {
27
+ output_1.default.exitError(texts_1.ERR_ENVIRONMENT_NOT_FOUND);
28
+ }
29
+ if (strictProject && options.project) {
30
+ const environment = await client.getEnvironment(workspace, resolved.environment_id);
31
+ // a workspace environment carries no project, so this also fails the
32
+ // workspace-fallback case
33
+ if (environment.project?.name !== resolved.project_identifier) {
34
+ output_1.default.exitError(texts_1.ERR_ENVIRONMENT_NOT_FOUND);
35
+ }
36
+ }
37
+ return resolved.environment_id;
38
+ };
39
+ exports.resolveEnvironmentId = resolveEnvironmentId;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const input_1 = __importDefault(require("../../input"));
9
+ const output_1 = __importDefault(require("../../output"));
10
+ const resolve_1 = require("./resolve");
11
+ const commandEnvironmentUpdate = (0, utils_1.newCommand)('update', texts_1.DESC_COMMAND_ENVIRONMENT_UPDATE);
12
+ commandEnvironmentUpdate.alias('edit');
13
+ commandEnvironmentUpdate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
14
+ commandEnvironmentUpdate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
15
+ commandEnvironmentUpdate.option('-n, --name <name>', texts_1.OPTION_ENVIRONMENT_NAME);
16
+ commandEnvironmentUpdate.option('--tags <tags>', texts_1.OPTION_ENVIRONMENT_TAGS);
17
+ commandEnvironmentUpdate.option('--public-url <url>', texts_1.OPTION_ENVIRONMENT_PUBLIC_URL);
18
+ commandEnvironmentUpdate.option('--icon <icon>', texts_1.OPTION_ENVIRONMENT_ICON);
19
+ commandEnvironmentUpdate.option('--note <note>', texts_1.OPT_COMMAND_NOTE);
20
+ commandEnvironmentUpdate.option('--agent-note <note>', texts_1.OPT_COMMAND_AGENT_NOTE);
21
+ commandEnvironmentUpdate.argument('<identifier>', texts_1.OPTION_ENVIRONMENT_IDENTIFIER);
22
+ commandEnvironmentUpdate.addHelpText('after', `\nEXAMPLES:${texts_1.EXAMPLE_ENVIRONMENT_UPDATE}`);
23
+ commandEnvironmentUpdate.action(async (identifier, options) => {
24
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
25
+ const body = {};
26
+ let changed = false;
27
+ if (options.name) {
28
+ body.name = options.name;
29
+ changed = true;
30
+ }
31
+ if (options.tags !== undefined) {
32
+ body.tags = input_1.default.tags(options.tags);
33
+ changed = true;
34
+ }
35
+ if (options.publicUrl !== undefined) {
36
+ body.public_url = options.publicUrl;
37
+ changed = true;
38
+ }
39
+ if (options.icon) {
40
+ body.icon = options.icon;
41
+ changed = true;
42
+ }
43
+ if (options.note !== undefined) {
44
+ body.note = options.note;
45
+ changed = true;
46
+ }
47
+ if (options.agentNote !== undefined) {
48
+ body.agent_note = options.agentNote;
49
+ changed = true;
50
+ }
51
+ if (!changed) {
52
+ output_1.default.exitError(texts_1.ERR_COMMAND_NO_UPDATE);
53
+ }
54
+ const client = input_1.default.restApiTokenClient();
55
+ const environment_id = await (0, resolve_1.resolveEnvironmentId)(client, workspace, identifier, options,
56
+ /* strictProject */ true);
57
+ const result = await client.updateEnvironment(workspace, environment_id, body);
58
+ output_1.default.exitSuccess((0, texts_1.TXT_ENVIRONMENT_UPDATED)(result.identifier, result.html_url));
59
+ });
60
+ exports.default = commandEnvironmentUpdate;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../utils");
7
+ const texts_1 = require("../texts");
8
+ const list_1 = __importDefault(require("./environment/list"));
9
+ const get_1 = __importDefault(require("./environment/get"));
10
+ const create_1 = __importDefault(require("./environment/create"));
11
+ const update_1 = __importDefault(require("./environment/update"));
12
+ const delete_1 = __importDefault(require("./environment/delete"));
13
+ const commandEnvironment = (0, utils_1.newCommand)('environment', texts_1.DESC_COMMAND_ENVIRONMENT);
14
+ commandEnvironment.alias('env');
15
+ commandEnvironment.addCommand(list_1.default);
16
+ commandEnvironment.addCommand(get_1.default);
17
+ commandEnvironment.addCommand(create_1.default);
18
+ commandEnvironment.addCommand(update_1.default);
19
+ commandEnvironment.addCommand(delete_1.default);
20
+ exports.default = commandEnvironment;
@@ -60,10 +60,12 @@ commandProjectGitCredential.action(async (action) => {
60
60
  projects.projects[0].html_url.includes(input.host);
61
61
  }
62
62
  if (myHost) {
63
- output_1.default.normal(`protocol=${input.protocol || 'https'}`);
64
- output_1.default.normal(`host=${input.host}`);
65
- output_1.default.normal(`username=${client.token}`);
66
- output_1.default.normal(`password=`);
63
+ // git credential protocol output - a machine-read payload, so it
64
+ // bypasses terminal-kit formatting
65
+ output_1.default.data(`protocol=${input.protocol || 'https'}`);
66
+ output_1.default.data(`host=${input.host}`);
67
+ output_1.default.data(`username=${client.token}`);
68
+ output_1.default.data(`password=`);
67
69
  }
68
70
  }
69
71
  catch {
@@ -43,7 +43,7 @@ commandSandboxExecCommand.action(async (identifier, command, options) => {
43
43
  str.forEach((s) => {
44
44
  const json = JSON.parse(s);
45
45
  if (json.data)
46
- output_1.default.normal(json.data);
46
+ output_1.default.data(json.data);
47
47
  });
48
48
  }
49
49
  catch {
@@ -31,7 +31,7 @@ commandSandboxExecLogs.action(async (identifier, commandId, options) => {
31
31
  str.forEach((s) => {
32
32
  const json = JSON.parse(s);
33
33
  if (json.data)
34
- output_1.default.normal(json.data);
34
+ output_1.default.data(json.data);
35
35
  });
36
36
  }
37
37
  catch {
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const input_1 = __importDefault(require("../../input"));
10
+ const scope_1 = require("./scope");
11
+ const commandTargetCreate = (0, utils_1.newCommand)('create', texts_1.DESC_COMMAND_TARGET_CREATE);
12
+ commandTargetCreate.alias('add');
13
+ commandTargetCreate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
14
+ commandTargetCreate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
15
+ commandTargetCreate.option('--pipeline <identifier>', texts_1.OPTION_TARGET_PIPELINE);
16
+ commandTargetCreate.option('--environment <identifier>', texts_1.OPTION_TARGET_ENVIRONMENT);
17
+ commandTargetCreate.option('--scope <scope>', texts_1.OPT_COMMAND_TARGET_SCOPE);
18
+ commandTargetCreate.option('--yaml <content|@path>', texts_1.OPTION_TARGET_YAML);
19
+ commandTargetCreate.addHelpText('after', `\nEXAMPLES:${texts_1.EXAMPLE_TARGET_CREATE}`);
20
+ commandTargetCreate.action(async (options) => {
21
+ const yaml = input_1.default.restApiYaml(options.yaml);
22
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
23
+ const project = input_1.default.restApiProject(options.project, true);
24
+ const scope = input_1.default.targetScope(project, options.pipeline, options.environment, options.scope);
25
+ const client = input_1.default.restApiTokenClient();
26
+ const scopeParams = await (0, scope_1.resolveTargetScope)(client, workspace, project, scope, options);
27
+ const body = {
28
+ yaml: Buffer.from(yaml, 'utf8').toString('base64'),
29
+ };
30
+ const result = await client.createTargetByYaml(workspace, scopeParams, body);
31
+ output_1.default.exitSuccess((0, texts_1.TXT_TARGET_CREATED)(result.identifier, result.html_url));
32
+ });
33
+ exports.default = commandTargetCreate;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const input_1 = __importDefault(require("../../input"));
10
+ const scope_1 = require("./scope");
11
+ const commandTargetDelete = (0, utils_1.newCommand)('delete', texts_1.DESC_COMMAND_TARGET_DELETE);
12
+ commandTargetDelete.alias('rm');
13
+ commandTargetDelete.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
14
+ commandTargetDelete.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
15
+ commandTargetDelete.option('--pipeline <identifier>', texts_1.OPTION_TARGET_PIPELINE);
16
+ commandTargetDelete.option('--environment <identifier>', texts_1.OPTION_TARGET_ENVIRONMENT);
17
+ commandTargetDelete.option('-f, --force', texts_1.OPTION_CONFIRM_FORCE);
18
+ commandTargetDelete.argument('<identifier>', texts_1.OPTION_TARGET_IDENTIFIER);
19
+ commandTargetDelete.addHelpText('after', `\nEXAMPLES:${texts_1.EXAMPLE_TARGET_DELETE}`);
20
+ commandTargetDelete.action(async (identifier, options) => {
21
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
22
+ const client = input_1.default.restApiTokenClient();
23
+ const target_id = await (0, scope_1.resolveTargetId)(client, workspace, identifier, options,
24
+ /* strictLine */ true);
25
+ const confirmed = options.force || (await output_1.default.confirm((0, texts_1.TXT_TARGET_DELETE_CONFIRM)(identifier)));
26
+ if (!confirmed)
27
+ output_1.default.exitNormal();
28
+ await client.deleteTarget(workspace, target_id);
29
+ output_1.default.exitSuccess((0, texts_1.TXT_TARGET_DELETED)(identifier));
30
+ });
31
+ exports.default = commandTargetDelete;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_fs_1 = __importDefault(require("node:fs"));
7
+ const utils_1 = require("../../../utils");
8
+ const texts_1 = require("../../../texts");
9
+ const output_1 = __importDefault(require("../../../output"));
10
+ const input_1 = __importDefault(require("../../../input"));
11
+ const scope_1 = require("../scope");
12
+ const EXEC_WAIT_MS = 10000;
13
+ const commandTargetExecCommand = (0, utils_1.newCommand)('command', texts_1.DESC_COMMAND_TARGET_EXEC);
14
+ commandTargetExecCommand.alias('cmd');
15
+ commandTargetExecCommand.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
16
+ commandTargetExecCommand.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
17
+ commandTargetExecCommand.option('--pipeline <identifier>', texts_1.OPTION_TARGET_PIPELINE);
18
+ commandTargetExecCommand.option('--environment <identifier>', texts_1.OPTION_TARGET_ENVIRONMENT);
19
+ commandTargetExecCommand.option('--async', texts_1.OPTION_TARGET_EXEC_ASYNC);
20
+ commandTargetExecCommand.option('--file <path>', texts_1.OPTION_TARGET_EXEC_FILE);
21
+ commandTargetExecCommand.option('--format <text|json>', texts_1.OPTION_FORMAT);
22
+ commandTargetExecCommand.argument('<identifier>', texts_1.OPTION_TARGET_IDENTIFIER);
23
+ commandTargetExecCommand.argument('[command]', texts_1.OPTION_TARGET_EXEC_COMMAND);
24
+ commandTargetExecCommand.addHelpText('after', `\nEXAMPLES:${texts_1.EXAMPLE_TARGET_EXEC_COMMAND}`);
25
+ commandTargetExecCommand.action(async (identifier, command, options) => {
26
+ output_1.default.handleSignals();
27
+ if (options.file && command !== undefined) {
28
+ output_1.default.exitError(texts_1.ERR_TARGET_EXEC_COMMAND_CONFLICT);
29
+ }
30
+ let cmd = command;
31
+ if (options.file) {
32
+ try {
33
+ cmd = node_fs_1.default.readFileSync(options.file, 'utf8');
34
+ }
35
+ catch {
36
+ output_1.default.exitError((0, texts_1.ERR_TARGET_EXEC_FILE_NOT_FOUND)(options.file));
37
+ }
38
+ }
39
+ if (!cmd?.trim()) {
40
+ output_1.default.exitError(texts_1.ERR_TARGET_EXEC_NO_COMMAND);
41
+ }
42
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
43
+ const client = input_1.default.restApiTokenClient();
44
+ const target_id = await (0, scope_1.resolveTargetId)(client, workspace, identifier, options,
45
+ /* strictLine */ true);
46
+ let exec = await client.executeTargetCommand(workspace, target_id, {
47
+ command: cmd,
48
+ });
49
+ const execId = exec.execution_id;
50
+ const json = options.format === 'json';
51
+ if (options.async) {
52
+ if (json) {
53
+ output_1.default.json(exec);
54
+ }
55
+ else {
56
+ output_1.default.note((0, texts_1.TXT_TARGET_EXEC_BACKGROUND)(execId));
57
+ output_1.default.data(execId);
58
+ }
59
+ output_1.default.exitNormal();
60
+ }
61
+ if (json) {
62
+ while (exec.status === utils_1.TARGET_EXEC_STATUS.INPROGRESS) {
63
+ exec = await client.getTargetExec(workspace, execId, EXEC_WAIT_MS);
64
+ }
65
+ const log = [];
66
+ await (0, scope_1.forwardExecLog)(client, workspace, execId, 0, (lines) => log.push(...lines));
67
+ output_1.default.json({ ...exec, log });
68
+ output_1.default.exitCode(exec.status === utils_1.TARGET_EXEC_STATUS.SUCCESSFUL ? 0 : 1);
69
+ }
70
+ output_1.default.note((0, texts_1.TXT_TARGET_EXEC_ID)(execId));
71
+ let offset = 0;
72
+ let truncated = false;
73
+ // bytes_out from the status long-poll tells whether there is anything
74
+ // new to fetch, saving a log request per quiet poll cycle.
75
+ let loggedBytes;
76
+ const drainLog = async () => {
77
+ loggedBytes = exec.bytes_out;
78
+ const log = await (0, scope_1.forwardExecLog)(client, workspace, execId, offset);
79
+ offset = log.offset;
80
+ truncated = truncated || log.truncated;
81
+ };
82
+ while (exec.status === utils_1.TARGET_EXEC_STATUS.INPROGRESS) {
83
+ exec = await client.getTargetExec(workspace, execId, EXEC_WAIT_MS);
84
+ if (exec.bytes_out !== loggedBytes)
85
+ await drainLog();
86
+ }
87
+ if (loggedBytes === undefined || exec.bytes_out !== loggedBytes) {
88
+ await drainLog();
89
+ }
90
+ if (exec.truncated || truncated) {
91
+ output_1.default.noteWarning(texts_1.WARN_TARGET_EXEC_TRUNCATED);
92
+ }
93
+ if (exec.status === utils_1.TARGET_EXEC_STATUS.SUCCESSFUL) {
94
+ output_1.default.note((0, texts_1.TXT_TARGET_EXEC_SUCCESS)(execId));
95
+ output_1.default.exitNormal();
96
+ }
97
+ output_1.default.exitError(exec.status === utils_1.TARGET_EXEC_STATUS.CANCELLED
98
+ ? (0, texts_1.TXT_TARGET_EXEC_CANCELLED)(execId)
99
+ : (0, texts_1.TXT_TARGET_EXEC_FAILED)(execId, exec.failure_reason));
100
+ });
101
+ exports.default = commandTargetExecCommand;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const texts_1 = require("../../../texts");
8
+ const input_1 = __importDefault(require("../../../input"));
9
+ const output_1 = __importDefault(require("../../../output"));
10
+ const commandTargetExecKill = (0, utils_1.newCommand)('kill', texts_1.DESC_COMMAND_TARGET_EXEC_KILL);
11
+ commandTargetExecKill.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
12
+ commandTargetExecKill.option('-f, --force', texts_1.OPTION_CONFIRM_FORCE);
13
+ commandTargetExecKill.argument('<exec-id>', texts_1.OPTION_TARGET_EXEC_ID);
14
+ commandTargetExecKill.addHelpText('after', `\nEXAMPLES:${texts_1.EXAMPLE_TARGET_EXEC_KILL}`);
15
+ commandTargetExecKill.action(async (execId, options) => {
16
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
17
+ const client = input_1.default.restApiTokenClient();
18
+ // Resolve the exec before the prompt so a bad id fails the same way
19
+ // (Resource not found, exit 1) with and without --force - otherwise the
20
+ // auto-declined prompt exits 0 without ever checking the id. With --force
21
+ // the DELETE itself surfaces the 404, so the extra request is skipped.
22
+ if (!options.force)
23
+ await client.getTargetExec(workspace, execId);
24
+ const confirmed = options.force ||
25
+ (await output_1.default.confirm((0, texts_1.TXT_TARGET_EXEC_KILL_CONFIRM)(execId)));
26
+ if (!confirmed)
27
+ output_1.default.exitNormal();
28
+ await client.cancelTargetExec(workspace, execId);
29
+ output_1.default.exitSuccess((0, texts_1.TXT_TARGET_EXEC_KILLED)(execId));
30
+ });
31
+ exports.default = commandTargetExecKill;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const texts_1 = require("../../../texts");
8
+ const input_1 = __importDefault(require("../../../input"));
9
+ const output_1 = __importDefault(require("../../../output"));
10
+ const scope_1 = require("../scope");
11
+ const commandTargetExecList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_TARGET_EXEC_LIST);
12
+ commandTargetExecList.alias('ls');
13
+ commandTargetExecList.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
14
+ commandTargetExecList.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
15
+ commandTargetExecList.option('--pipeline <identifier>', texts_1.OPTION_TARGET_PIPELINE);
16
+ commandTargetExecList.option('--environment <identifier>', texts_1.OPTION_TARGET_ENVIRONMENT);
17
+ commandTargetExecList.option('--limit <n>', texts_1.OPTION_TARGET_EXEC_LIMIT);
18
+ commandTargetExecList.option('--format <text|json>', texts_1.OPTION_FORMAT);
19
+ commandTargetExecList.argument('<identifier>', texts_1.OPTION_TARGET_IDENTIFIER);
20
+ commandTargetExecList.addHelpText('after', `\nEXAMPLES:${texts_1.EXAMPLE_TARGET_EXEC_LIST}`);
21
+ commandTargetExecList.action(async (identifier, options) => {
22
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
23
+ const client = input_1.default.restApiTokenClient();
24
+ const target_id = await (0, scope_1.resolveTargetId)(client, workspace, identifier, options);
25
+ const limit = options.limit ? parseInt(options.limit, 10) : undefined;
26
+ const execs = await client.getTargetExecs(workspace, target_id, limit);
27
+ if (options.format === 'json') {
28
+ output_1.default.json(execs);
29
+ }
30
+ else {
31
+ if (execs.length === 0) {
32
+ output_1.default.exitError(texts_1.ERR_TARGET_NO_EXECS);
33
+ }
34
+ const data = [
35
+ ['EXEC ID', 'STATUS', 'COMMAND', 'STARTED', 'FINISHED', 'EXIT CODE'],
36
+ ];
37
+ for (const exec of execs) {
38
+ data.push([
39
+ exec.execution_id || '-',
40
+ exec.failure_reason
41
+ ? `${exec.status} (${exec.failure_reason})`
42
+ : exec.status || '-',
43
+ (0, utils_1.truncate)(exec.command || '-', 40),
44
+ exec.started_at || '-',
45
+ exec.finished_at || '-',
46
+ exec.exit_code !== undefined ? String(exec.exit_code) : '-',
47
+ ]);
48
+ }
49
+ output_1.default.table(data);
50
+ }
51
+ output_1.default.exitNormal();
52
+ });
53
+ exports.default = commandTargetExecList;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const texts_1 = require("../../../texts");
8
+ const input_1 = __importDefault(require("../../../input"));
9
+ const output_1 = __importDefault(require("../../../output"));
10
+ const scope_1 = require("../scope");
11
+ const commandTargetExecLogs = (0, utils_1.newCommand)('logs', texts_1.DESC_COMMAND_TARGET_EXEC_LOGS);
12
+ commandTargetExecLogs.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
13
+ commandTargetExecLogs.option('--offset <n>', texts_1.OPTION_TARGET_EXEC_LOG_OFFSET);
14
+ commandTargetExecLogs.option('--limit <n>', texts_1.OPTION_TARGET_EXEC_LOG_LIMIT);
15
+ commandTargetExecLogs.argument('<exec-id>', texts_1.OPTION_TARGET_EXEC_ID);
16
+ commandTargetExecLogs.addHelpText('after', `\nEXAMPLES:${texts_1.EXAMPLE_TARGET_EXEC_LOGS}`);
17
+ commandTargetExecLogs.action(async (execId, options) => {
18
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
19
+ const client = input_1.default.restApiTokenClient();
20
+ const offset = options.offset ? parseInt(options.offset, 10) : 0;
21
+ const limit = options.limit ? parseInt(options.limit, 10) : undefined;
22
+ const { truncated } = await (0, scope_1.forwardExecLog)(client, workspace, execId, offset, undefined, limit);
23
+ if (truncated)
24
+ output_1.default.noteWarning(texts_1.WARN_TARGET_EXEC_TRUNCATED);
25
+ output_1.default.exitNormal();
26
+ });
27
+ exports.default = commandTargetExecLogs;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const texts_1 = require("../../../texts");
8
+ const input_1 = __importDefault(require("../../../input"));
9
+ const output_1 = __importDefault(require("../../../output"));
10
+ const commandTargetExecStatus = (0, utils_1.newCommand)('status', texts_1.DESC_COMMAND_TARGET_EXEC_STATUS);
11
+ commandTargetExecStatus.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
12
+ commandTargetExecStatus.option('--format <text|json>', texts_1.OPTION_FORMAT);
13
+ commandTargetExecStatus.argument('<exec-id>', texts_1.OPTION_TARGET_EXEC_ID);
14
+ commandTargetExecStatus.addHelpText('after', `\nEXAMPLES:${texts_1.EXAMPLE_TARGET_EXEC_STATUS}`);
15
+ commandTargetExecStatus.action(async (execId, options) => {
16
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
17
+ const client = input_1.default.restApiTokenClient();
18
+ const exec = await client.getTargetExec(workspace, execId);
19
+ if (options.format === 'json') {
20
+ output_1.default.json(exec);
21
+ }
22
+ else {
23
+ // The table renderer pads every Value cell to the widest one, so a long
24
+ // SQL command would blow the whole table up; the full text is available
25
+ // via --format json.
26
+ const data = [
27
+ ['Property', 'Value'],
28
+ ['Execution ID', exec.execution_id || '-'],
29
+ ['Command', (0, utils_1.truncate)(exec.command || '-', 100)],
30
+ ['Status', exec.status || '-'],
31
+ [
32
+ 'Exit Code',
33
+ exec.exit_code !== undefined ? String(exec.exit_code) : '-',
34
+ ],
35
+ ['Failure Reason', exec.failure_reason || '-'],
36
+ ['Error', exec.error_message || '-'],
37
+ ['Started', exec.started_at || '-'],
38
+ ['Finished', exec.finished_at || '-'],
39
+ ];
40
+ output_1.default.table(data);
41
+ }
42
+ output_1.default.exitNormal();
43
+ });
44
+ exports.default = commandTargetExecStatus;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const command_1 = __importDefault(require("./exec/command"));
9
+ const status_1 = __importDefault(require("./exec/status"));
10
+ const kill_1 = __importDefault(require("./exec/kill"));
11
+ const list_1 = __importDefault(require("./exec/list"));
12
+ const logs_1 = __importDefault(require("./exec/logs"));
13
+ const commandTargetExec = (0, utils_1.newCommand)('exec', texts_1.DESC_COMMAND_TARGET_EXEC);
14
+ commandTargetExec.addCommand(command_1.default);
15
+ commandTargetExec.addCommand(status_1.default);
16
+ commandTargetExec.addCommand(kill_1.default);
17
+ commandTargetExec.addCommand(list_1.default);
18
+ commandTargetExec.addCommand(logs_1.default);
19
+ commandTargetExec.addHelpText('after', `\nEXAMPLES:${texts_1.EXAMPLE_TARGET_EXEC_COMMAND}
20
+ ${texts_1.EXAMPLE_TARGET_EXEC_KILL}
21
+ ${texts_1.EXAMPLE_TARGET_EXEC_LIST}
22
+ ${texts_1.EXAMPLE_TARGET_EXEC_LOGS}
23
+ ${texts_1.EXAMPLE_TARGET_EXEC_STATUS}`);
24
+ exports.default = commandTargetExec;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const input_1 = __importDefault(require("../../input"));
10
+ const scope_1 = require("./scope");
11
+ const commandTargetGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_TARGET_GET);
12
+ commandTargetGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
13
+ commandTargetGet.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
14
+ commandTargetGet.option('--pipeline <identifier>', texts_1.OPTION_TARGET_PIPELINE);
15
+ commandTargetGet.option('--environment <identifier>', texts_1.OPTION_TARGET_ENVIRONMENT);
16
+ commandTargetGet.option('--format <text|json>', texts_1.OPTION_FORMAT);
17
+ commandTargetGet.argument('<identifier>', texts_1.OPTION_TARGET_IDENTIFIER);
18
+ commandTargetGet.addHelpText('after', `\nEXAMPLES:${texts_1.EXAMPLE_TARGET_GET}`);
19
+ commandTargetGet.action(async (identifier, options) => {
20
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
21
+ const client = input_1.default.restApiTokenClient();
22
+ const target_id = await (0, scope_1.resolveTargetId)(client, workspace, identifier, options);
23
+ const target = await client.getTarget(workspace, target_id);
24
+ if (options.format === 'json') {
25
+ output_1.default.json(target);
26
+ }
27
+ else {
28
+ const data = [
29
+ ['Field', 'Value'],
30
+ ['ID', target.id || '-'],
31
+ ['Identifier', target.identifier || '-'],
32
+ ['Name', target.name || '-'],
33
+ ['Type', target.type || '-'],
34
+ ['Scope', (0, scope_1.targetScopeOf)(target)],
35
+ ['Address', (0, scope_1.targetAddressOf)(target)],
36
+ ['Tags', (target.tags || []).join(', ') || '-'],
37
+ ['Note', target.note || '-'],
38
+ ['Agent note', target.agent_note || '-'],
39
+ ['Disabled', target.disabled ? 'true' : 'false'],
40
+ ];
41
+ if (target.project) {
42
+ data.push(['Project', target.project.name || '-']);
43
+ }
44
+ if (target.pipeline) {
45
+ data.push([
46
+ 'Pipeline',
47
+ target.pipeline.identifier || String(target.pipeline.id) || '-',
48
+ ]);
49
+ }
50
+ if (target.environment) {
51
+ data.push([
52
+ 'Environment',
53
+ target.environment.identifier || target.environment.id || '-',
54
+ ]);
55
+ }
56
+ if (target.html_url) {
57
+ data.push(['URL', target.html_url]);
58
+ }
59
+ output_1.default.table(data);
60
+ }
61
+ output_1.default.exitNormal();
62
+ });
63
+ exports.default = commandTargetGet;