@dishantlangayan/solace-cloud-cli 0.0.1 → 0.0.3

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.
@@ -1,5 +1,6 @@
1
- import { Command } from '@oclif/core';
2
- export default class MissionctrlBrokerList extends Command {
1
+ import { ScCommand } from '../../../sc-command.js';
2
+ import { EventBrokerServiceDetail } from '../../../types/broker.js';
3
+ export default class MissionctrlBrokerList extends ScCommand<typeof MissionctrlBrokerList> {
3
4
  static args: {};
4
5
  static description: string;
5
6
  static examples: string[];
@@ -9,5 +10,5 @@ export default class MissionctrlBrokerList extends Command {
9
10
  pageSize: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
11
  sort: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
12
  };
12
- run(): Promise<void>;
13
+ run(): Promise<EventBrokerServiceDetail[]>;
13
14
  }
@@ -1,7 +1,8 @@
1
- import { Command, Flags } from '@oclif/core';
2
- import { table } from 'table';
1
+ import { Flags } from '@oclif/core';
2
+ import { ScCommand } from '../../../sc-command.js';
3
+ import { renderTable } from '../../../util/internal.js';
3
4
  import { ScConnection } from '../../../util/sc-connection.js';
4
- export default class MissionctrlBrokerList extends Command {
5
+ export default class MissionctrlBrokerList extends ScCommand {
5
6
  static args = {};
6
7
  static description = `Get a listing of event broker services.
7
8
 
@@ -10,17 +11,18 @@ Your token must have one of the permissions listed in the Token Permissions.
10
11
  Token Permissions: [ \`mission_control:access\` **or** \`services:get\` **or** \`services:get:self\` **or** \`services:view\` **or** \`services:view:self\` ]`;
11
12
  static examples = ['<%= config.bin %> <%= command.id %> --name=MyBrokerName --pageNumber=1 --pageSize=10 --sort=name:asc'];
12
13
  static flags = {
13
- // flag with a value (-n, --name=VALUE)
14
- name: Flags.string({ char: 'n', description: 'Name of the event broker service to match on.' }),
15
- // pageNumber (--pageNumber=VALUE)
16
- pageNumber: Flags.integer({ description: 'The page number to get. Defaults to 1' }),
17
- // pageSize (--pageSize=VALUE)
14
+ name: Flags.string({
15
+ char: 'n',
16
+ description: 'Name of the event broker service to match on.'
17
+ }),
18
+ pageNumber: Flags.integer({
19
+ description: 'The page number to get. Defaults to 1'
20
+ }),
18
21
  pageSize: Flags.integer({
19
22
  description: 'The number of event broker services to return per page. Defaults to 100',
20
23
  max: 100,
21
24
  min: 1,
22
25
  }),
23
- // sort (--sort=VALUE)
24
26
  sort: Flags.string({
25
27
  description: `Sort the returned event broker services by attribute.
26
28
 
@@ -60,6 +62,8 @@ Token Permissions: [ \`mission_control:access\` **or** \`services:get\` **or** \
60
62
  ];
61
63
  // Display results as a table
62
64
  this.log();
63
- this.log(table(brokerArray));
65
+ this.log(renderTable(brokerArray));
66
+ // Return raw json if --json flag is set
67
+ return resp.data;
64
68
  }
65
69
  }
@@ -0,0 +1,15 @@
1
+ import { ScCommand } from '../../../sc-command.js';
2
+ import { OperationData } from '../../../types/broker.js';
3
+ export default class MissionctrlBrokerOpstatus extends ScCommand<typeof MissionctrlBrokerOpstatus> {
4
+ static args: {};
5
+ static description: string;
6
+ static examples: string[];
7
+ static flags: {
8
+ 'broker-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'operation-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'show-progress': import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ };
13
+ run(): Promise<OperationData>;
14
+ private print;
15
+ }
@@ -0,0 +1,109 @@
1
+ import { Flags } from '@oclif/core';
2
+ import cliProgress from 'cli-progress';
3
+ import { ScCommand } from '../../../sc-command.js';
4
+ import { ScConnection } from '../../../util/sc-connection.js';
5
+ import { camelCaseToTitleCase, renderKeyValueTable, sleep } from '../../../util/internal.js';
6
+ export default class MissionctrlBrokerOpstatus extends ScCommand {
7
+ static args = {};
8
+ static description = `Get the status of an operation that being performed on an event broker service.
9
+ To get the operation, you provide identifier of the operation and the identifier of the event broker service.
10
+
11
+ Token Permissions: [ mission_control:access or services:get or services:get:self or services:view or services:view:self ]`;
12
+ static examples = [
13
+ '<%= config.bin %> <%= command.id %>',
14
+ ];
15
+ static flags = {
16
+ 'broker-id': Flags.string({
17
+ char: 'b',
18
+ description: 'Id of the event broker service.',
19
+ exactlyOne: ['broker-id', 'name'],
20
+ }),
21
+ name: Flags.string({
22
+ char: 'n',
23
+ description: 'Name of the event broker service.',
24
+ exactlyOne: ['broker-id', 'name'],
25
+ }),
26
+ 'operation-id': Flags.string({
27
+ char: 'o',
28
+ description: 'The identifier of the operation being performed on the event broker service.'
29
+ }),
30
+ 'show-progress': Flags.boolean({
31
+ char: 'p',
32
+ description: 'Displays a status bar of the in-progress operation. The command will wait for completion of each step of the operation.'
33
+ }),
34
+ };
35
+ async run() {
36
+ const { flags } = await this.parse(MissionctrlBrokerOpstatus);
37
+ const name = flags.name ?? '';
38
+ let brokerId = flags['broker-id'] ?? '';
39
+ const operationId = flags['operation-id'] ?? '';
40
+ const showProgress = flags['show-progress'] ?? false;
41
+ const conn = new ScConnection();
42
+ // API url
43
+ let apiUrl = `/missionControl/eventBrokerServices`;
44
+ // If broker name provided, retrieve the broker service id first
45
+ // then retrieve the operation status
46
+ let rawResp;
47
+ if (name) {
48
+ // API call to get broker by name
49
+ apiUrl += `?customAttributes=name=="${name}"`;
50
+ const resp = await conn.get(apiUrl);
51
+ // TODO FUTURE: show status of multiple brokers operations that match the name
52
+ if (resp.data.length > 1) {
53
+ this.error(`Multiple broker services found with: ${name}. Exactly one broker service must match the provided name.`);
54
+ }
55
+ else {
56
+ brokerId = resp.data[0]?.id;
57
+ }
58
+ }
59
+ // API call to retrieve status of the broker operation
60
+ apiUrl = `/missionControl/eventBrokerServices/${brokerId}/operations/${operationId}`;
61
+ if (showProgress) {
62
+ apiUrl += '?expand=progressLogs';
63
+ }
64
+ let resp = await conn.get(apiUrl);
65
+ this.print(resp.data);
66
+ // Display progress bar for each step included in the progress logs
67
+ // Enable progress bar if set
68
+ if (resp.data.progressLogs && resp.data.progressLogs.length > 0) {
69
+ let progressLogs = resp.data.progressLogs;
70
+ let numSteps = progressLogs.length;
71
+ // Create a new progress bar instance and use shades_classic theme
72
+ const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
73
+ // start the progress bar with a total value of size of the steps and start value of 0
74
+ progressBar.start(numSteps, 0);
75
+ // Update the progress with the steps completed
76
+ let completedNumSteps = 0;
77
+ while (completedNumSteps < numSteps) {
78
+ // Sleep for 5 seconds before making the next API call
79
+ await sleep(5000);
80
+ // Make another API call to get the lastest progress
81
+ resp = await conn.get(apiUrl);
82
+ if (resp.data.progressLogs) {
83
+ progressLogs = resp.data.progressLogs;
84
+ for (const progressLog of progressLogs) {
85
+ if (progressLog.step === 'success') {
86
+ completedNumSteps++;
87
+ }
88
+ }
89
+ // Update progress bar
90
+ progressBar.update(completedNumSteps);
91
+ }
92
+ else {
93
+ break;
94
+ }
95
+ }
96
+ // stop the progress bar
97
+ progressBar.stop();
98
+ }
99
+ return resp.data;
100
+ }
101
+ print(environment) {
102
+ const tableRows = [
103
+ ['Key', 'Value'],
104
+ ...Object.entries(environment).map(([key, value]) => [camelCaseToTitleCase(key), value]),
105
+ ];
106
+ this.log();
107
+ this.log(renderKeyValueTable(tableRows));
108
+ }
109
+ }
@@ -1,5 +1,6 @@
1
- import { Command } from '@oclif/core';
2
- export default class PlatformEnvCreate extends Command {
1
+ import { ScCommand } from '../../../sc-command.js';
2
+ import { Environment } from '../../../types/environment.js';
3
+ export default class PlatformEnvCreate extends ScCommand<typeof PlatformEnvCreate> {
3
4
  static args: {};
4
5
  static description: string;
5
6
  static examples: string[];
@@ -9,6 +10,6 @@ export default class PlatformEnvCreate extends Command {
9
10
  isProduction: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
11
  name: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
12
  };
12
- run(): Promise<void>;
13
+ run(): Promise<Environment>;
13
14
  private print;
14
15
  }
@@ -1,25 +1,32 @@
1
- import { Command, Flags } from '@oclif/core';
2
- import { table } from 'table';
3
- import { camelCaseToTitleCase } from '../../../util/internal.js';
1
+ import { Flags } from '@oclif/core';
2
+ import { ScCommand } from '../../../sc-command.js';
3
+ import { camelCaseToTitleCase, renderKeyValueTable } from '../../../util/internal.js';
4
4
  import { ScConnection } from '../../../util/sc-connection.js';
5
- export default class PlatformEnvCreate extends Command {
5
+ export default class PlatformEnvCreate extends ScCommand {
6
6
  static args = {};
7
7
  static description = `Create a new environment.
8
8
 
9
9
  Token Permissions: [ environments:edit ]`;
10
10
  static examples = ['<%= config.bin %> <%= command.id %> --name=MyEnvironment --desc="My environment description" --isDefault --isProduction'];
11
11
  static flags = {
12
- desc: Flags.string({ char: 'd', description: 'Description of the environment to create.' }),
13
- // flag with no value (--isDefault)
14
- isDefault: Flags.boolean({ description: 'Indicates this is the organization’s default environment.' }),
12
+ desc: Flags.string({
13
+ char: 'd',
14
+ description: 'Description of the environment to create.'
15
+ }),
16
+ isDefault: Flags.boolean({
17
+ description: 'Indicates this is the organization’s default environment.'
18
+ }),
15
19
  isProduction: Flags.boolean({
16
20
  description: `Indicates this is an organization’s production environment.
17
21
  This is an immutable field. If an environment needs to be migrated,
18
22
  architecture can be migrated to a new environment with the desired
19
23
  environment type instead.`,
20
24
  }),
21
- // flag with a value (-n, --name=VALUE)
22
- name: Flags.string({ char: 'n', description: 'Name of the environment to create.', required: true }),
25
+ name: Flags.string({
26
+ char: 'n',
27
+ description: 'Name of the environment to create.',
28
+ required: true
29
+ }),
23
30
  };
24
31
  async run() {
25
32
  const { flags } = await this.parse(PlatformEnvCreate);
@@ -42,22 +49,15 @@ export default class PlatformEnvCreate extends Command {
42
49
  // Display results
43
50
  this.log('Environment created successfully.');
44
51
  this.print(resp.data);
52
+ // Return raw json if --json flag is set
53
+ return resp.data;
45
54
  }
46
55
  print(environment) {
47
- this.log();
48
56
  const tableRows = [
49
57
  ['Key', 'Value'],
50
58
  ...Object.entries(environment).map(([key, value]) => [camelCaseToTitleCase(key), value]),
51
59
  ];
52
- // Table config
53
- const config = {
54
- columns: {
55
- 1: { width: 50, wrapWord: true },
56
- },
57
- drawHorizontalLine(lineIndex, rowCount) {
58
- return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
59
- },
60
- };
61
- this.log(table(tableRows, config));
60
+ this.log();
61
+ this.log(renderKeyValueTable(tableRows));
62
62
  }
63
63
  }
@@ -1,5 +1,5 @@
1
- import { Command } from '@oclif/core';
2
- export default class PlatformEnvDelete extends Command {
1
+ import { ScCommand } from '../../../sc-command.js';
2
+ export default class PlatformEnvDelete extends ScCommand<typeof PlatformEnvDelete> {
3
3
  static args: {};
4
4
  static description: string;
5
5
  static examples: string[];
@@ -7,5 +7,7 @@ export default class PlatformEnvDelete extends Command {
7
7
  'env-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
8
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
9
  };
10
- run(): Promise<void>;
10
+ run(): Promise<{
11
+ message: string;
12
+ }>;
11
13
  }
@@ -1,16 +1,23 @@
1
- import { Command, Flags } from '@oclif/core';
1
+ import { Flags } from '@oclif/core';
2
+ import { ScCommand } from '../../../sc-command.js';
2
3
  import { ScConnection } from '../../../util/sc-connection.js';
3
- export default class PlatformEnvDelete extends Command {
4
+ export default class PlatformEnvDelete extends ScCommand {
4
5
  static args = {};
5
6
  static description = `Delete an environment using either its name or unique identifier. The default environment cannot be deleted.
6
7
 
7
8
  Token Permissions: [ environments:edit ]`;
8
9
  static examples = ['<%= config.bin %> <%= command.id %> --name=MyEnvName', '<%= config.bin %> <%= command.id %> --env-id=MyEnvId'];
9
10
  static flags = {
10
- // flag for getting environment by id (-e, --env-id)
11
- 'env-id': Flags.string({ char: 'e', description: 'Id of the environment.', exactlyOne: ['env-id', 'name'] }),
12
- // flag for getting environment by name (-n, --name=VALUE)
13
- name: Flags.string({ char: 'n', description: 'Name of the environment.', exactlyOne: ['env-id', 'name'] }),
11
+ 'env-id': Flags.string({
12
+ char: 'e',
13
+ description: 'Id of the environment.',
14
+ exactlyOne: ['env-id', 'name']
15
+ }),
16
+ name: Flags.string({
17
+ char: 'n',
18
+ description: 'Name of the environment.',
19
+ exactlyOne: ['env-id', 'name']
20
+ }),
14
21
  };
15
22
  async run() {
16
23
  const { flags } = await this.parse(PlatformEnvDelete);
@@ -22,20 +29,31 @@ export default class PlatformEnvDelete extends Command {
22
29
  let envIdToDelete = envId;
23
30
  // If env name provided, get the environment matching provided name and delete. If more than one environment matches, an error will be thrown.
24
31
  // If env id provided, delete environment with that id
32
+ let foundMultiple = false;
25
33
  if (name) {
26
34
  // API call to get environment by name
27
35
  const getEnvApiUrl = `${apiUrl}?name=${name}`;
28
36
  const resp = await conn.get(getEnvApiUrl);
29
37
  if (resp.data.length > 1) {
30
- this.error(`Multiple environments found with: ${name}. Exactly one environment must match the provided name.`);
38
+ foundMultiple = true;
31
39
  }
32
40
  else {
33
41
  envIdToDelete = resp.data[0]?.id;
34
42
  }
35
43
  }
36
- // API call to delete environment by id
37
- apiUrl += `/${envIdToDelete}`;
38
- await conn.delete(apiUrl);
39
- this.log(`Environment with id '${envIdToDelete}' has been deleted successfully.`);
44
+ let message = '';
45
+ if (foundMultiple) {
46
+ message = `Multiple environments found with: ${name}. Exactly one environment must match the provided name.`;
47
+ this.warn(message);
48
+ }
49
+ else {
50
+ // API call to delete environment by id
51
+ apiUrl += `/${envIdToDelete}`;
52
+ await conn.delete(apiUrl);
53
+ message = `Environment with id '${envIdToDelete}' has been deleted successfully.`;
54
+ this.log(message);
55
+ }
56
+ // Return raw json if --json flag is set
57
+ return { message };
40
58
  }
41
59
  }
@@ -1,5 +1,6 @@
1
- import { Command } from '@oclif/core';
2
- export default class PlatformEnvDisplay extends Command {
1
+ import { ScCommand } from '../../../sc-command.js';
2
+ import { Environment } from '../../../types/environment.js';
3
+ export default class PlatformEnvDisplay extends ScCommand<typeof PlatformEnvDisplay> {
3
4
  static args: {};
4
5
  static description: string;
5
6
  static examples: string[];
@@ -7,6 +8,6 @@ export default class PlatformEnvDisplay extends Command {
7
8
  'env-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
9
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
10
  };
10
- run(): Promise<void>;
11
+ run(): Promise<Environment[]>;
11
12
  private print;
12
13
  }
@@ -1,21 +1,26 @@
1
- import { Command, Flags } from '@oclif/core';
2
- import { table } from 'table';
3
- import { camelCaseToTitleCase } from '../../../util/internal.js';
1
+ import { Flags } from '@oclif/core';
2
+ import { ScCommand } from '../../../sc-command.js';
3
+ import { camelCaseToTitleCase, renderKeyValueTable } from '../../../util/internal.js';
4
4
  import { ScConnection } from '../../../util/sc-connection.js';
5
- export default class PlatformEnvDisplay extends Command {
5
+ export default class PlatformEnvDisplay extends ScCommand {
6
6
  static args = {};
7
7
  static description = `Display information about an Environment.
8
8
 
9
9
  Use either the Environment's ID (--env-id) or name of the Environment (--name).
10
10
 
11
- Required token permissions: [ environments:view ]
12
- `;
11
+ Required token permissions: [ environments:view ]`;
13
12
  static examples = ['<%= config.bin %> <%= command.id %> --name=MyEnvName', '<%= config.bin %> <%= command.id %> --env-id=MyEnvId'];
14
13
  static flags = {
15
- // flag for getting environment by id (-e, --env-id)
16
- 'env-id': Flags.string({ char: 'e', description: 'Id of the environment.', exactlyOne: ['env-id', 'name'] }),
17
- // flag for getting environment by name (-n, --name=VALUE)
18
- name: Flags.string({ char: 'n', description: 'Name of the environment.', exactlyOne: ['env-id', 'name'] }),
14
+ 'env-id': Flags.string({
15
+ char: 'e',
16
+ description: 'Id of the environment.',
17
+ exactlyOne: ['env-id', 'name']
18
+ }),
19
+ name: Flags.string({
20
+ char: 'n',
21
+ description: 'Name of the environment.',
22
+ exactlyOne: ['env-id', 'name']
23
+ }),
19
24
  };
20
25
  async run() {
21
26
  const { flags } = await this.parse(PlatformEnvDisplay);
@@ -26,11 +31,13 @@ export default class PlatformEnvDisplay extends Command {
26
31
  // If env name provided, get all environments matching provided name
27
32
  // If env id provided, get environment with that id
28
33
  let apiUrl = `/platform/environments`;
34
+ let rawResp;
29
35
  if (envId) {
30
36
  // API call to get environment by id
31
37
  apiUrl += `/${envId}`;
32
38
  const resp = await conn.get(apiUrl);
33
39
  this.print(resp.data);
40
+ rawResp = [resp.data];
34
41
  }
35
42
  else if (name) {
36
43
  // API call to get environment by name
@@ -39,26 +46,20 @@ export default class PlatformEnvDisplay extends Command {
39
46
  for (const env of resp.data) {
40
47
  this.print(env);
41
48
  }
49
+ rawResp = resp.data;
42
50
  }
43
51
  else {
44
52
  this.error('Either --env-id or --name must be provided.');
45
53
  }
54
+ // Return raw json if --json flag is set
55
+ return rawResp;
46
56
  }
47
57
  print(environment) {
48
- this.log();
49
58
  const tableRows = [
50
59
  ['Key', 'Value'],
51
60
  ...Object.entries(environment).map(([key, value]) => [camelCaseToTitleCase(key), value]),
52
61
  ];
53
- // Table config
54
- const config = {
55
- columns: {
56
- 1: { width: 50, wrapWord: true },
57
- },
58
- drawHorizontalLine(lineIndex, rowCount) {
59
- return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
60
- },
61
- };
62
- this.log(table(tableRows, config));
62
+ this.log();
63
+ this.log(renderKeyValueTable(tableRows));
63
64
  }
64
65
  }
@@ -1,4 +1,5 @@
1
1
  import { ScCommand } from '../../../sc-command.js';
2
+ import { Environment } from '../../../types/environment.js';
2
3
  export default class PlatformEnvList extends ScCommand<typeof PlatformEnvList> {
3
4
  static args: {};
4
5
  static description: string;
@@ -9,5 +10,5 @@ export default class PlatformEnvList extends ScCommand<typeof PlatformEnvList> {
9
10
  pageSize: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
11
  sort: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
12
  };
12
- run(): Promise<void>;
13
+ run(): Promise<Environment[]>;
13
14
  }
@@ -1,6 +1,6 @@
1
1
  import { Flags } from '@oclif/core';
2
- import { table } from 'table';
3
2
  import { ScCommand } from '../../../sc-command.js';
3
+ import { renderTable } from '../../../util/internal.js';
4
4
  import { ScConnection } from '../../../util/sc-connection.js';
5
5
  export default class PlatformEnvList extends ScCommand {
6
6
  static args = {};
@@ -9,17 +9,20 @@ export default class PlatformEnvList extends ScCommand {
9
9
  Required token permissions: [ environments:view ]`;
10
10
  static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --name=Default --pageNumber=1 --pageSize=10 --sort=name:ASC'];
11
11
  static flags = {
12
- // flag with a value (-n, --name=VALUE)
13
- name: Flags.string({ char: 'n', description: 'Name of the environment to match on.' }),
14
- // pageNumber (--pageNumber=VALUE)
15
- pageNumber: Flags.integer({ description: 'The page number to get. Defaults to 10' }),
16
- // pageSize (--pageSize=VALUE)
12
+ name: Flags.string({
13
+ char: 'n',
14
+ description: 'Name of the environment to match on.'
15
+ }),
16
+ pageNumber: Flags.integer({
17
+ char: 'p',
18
+ description: 'The page number to get. Defaults to 10'
19
+ }),
17
20
  pageSize: Flags.integer({
21
+ char: 's',
18
22
  description: 'The number of environments to get per page. Defaults to 1',
19
23
  max: 100,
20
24
  min: 1,
21
25
  }),
22
- // sort (--sort=VALUE)
23
26
  sort: Flags.string({
24
27
  description: 'The query (fieldName:<ASC/DESC>) used to sort the environment list in the response.',
25
28
  }),
@@ -37,20 +40,20 @@ export default class PlatformEnvList extends ScCommand {
37
40
  // API call
38
41
  const resp = await conn.get(apiUrl);
39
42
  // Array to output as table
40
- const envArray = [['Name', 'Id', 'Is Default', 'Is Production', 'Description'], ...resp.data.map((item) => [
43
+ const envArray = [
44
+ ['Name', 'Id', 'Is Default', 'Is Production', 'Description'],
45
+ ...resp.data.map((item) => [
41
46
  item.name,
42
47
  item.id,
43
48
  item.isDefault,
44
49
  item.isProduction,
45
50
  item.description,
46
- ])];
51
+ ])
52
+ ];
47
53
  // Display results as a table
48
- const config = {
49
- columns: {
50
- 4: { width: 50, wrapWord: true },
51
- },
52
- };
53
54
  this.log();
54
- this.log(table(envArray, config));
55
+ this.log(renderTable(envArray, { 4: { width: 50, wrapWord: true } }));
56
+ // Return raw json if --json flag is set
57
+ return resp.data;
55
58
  }
56
59
  }
@@ -1,5 +1,6 @@
1
- import { Command } from '@oclif/core';
2
- export default class PlatformEnvUpdate extends Command {
1
+ import { ScCommand } from '../../../sc-command.js';
2
+ import { Environment } from '../../../types/environment.js';
3
+ export default class PlatformEnvUpdate extends ScCommand<typeof PlatformEnvUpdate> {
3
4
  static args: {};
4
5
  static description: string;
5
6
  static examples: string[];
@@ -10,6 +11,6 @@ export default class PlatformEnvUpdate extends Command {
10
11
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
12
  'new-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
13
  };
13
- run(): Promise<void>;
14
+ run(): Promise<Environment>;
14
15
  private print;
15
16
  }
@@ -1,8 +1,8 @@
1
- import { Command, Flags } from '@oclif/core';
2
- import { table } from 'table';
3
- import { camelCaseToTitleCase } from '../../../util/internal.js';
1
+ import { Flags } from '@oclif/core';
2
+ import { ScCommand } from '../../../sc-command.js';
3
+ import { camelCaseToTitleCase, renderKeyValueTable } from '../../../util/internal.js';
4
4
  import { ScConnection } from '../../../util/sc-connection.js';
5
- export default class PlatformEnvUpdate extends Command {
5
+ export default class PlatformEnvUpdate extends ScCommand {
6
6
  static args = {};
7
7
  static description = `Modify an environment's attributes
8
8
 
@@ -15,11 +15,25 @@ export default class PlatformEnvUpdate extends Command {
15
15
  '<%= config.bin %> <%= command.id %> --env-id=MyEnvId --new-name=MyNewEnvName --desc="My description to update" --isDefault'
16
16
  ];
17
17
  static flags = {
18
- desc: Flags.string({ char: 'd', description: 'Description of the environment to update.' }),
19
- 'env-id': Flags.string({ char: 'e', description: 'Id of the environment.', exactlyOne: ['env-id', 'name'] }),
20
- isDefault: Flags.boolean({ description: `Indicates this is the organization's default environment. The default value is false.` }),
21
- name: Flags.string({ char: 'n', description: 'Current name of the environment.', exactlyOne: ['env-id', 'name'] }),
22
- 'new-name': Flags.string({ description: 'New name of the environment.' }),
18
+ desc: Flags.string({
19
+ char: 'd',
20
+ description: 'Description of the environment to update.'
21
+ }),
22
+ 'env-id': Flags.string({
23
+ char: 'e',
24
+ description: 'Id of the environment.',
25
+ exactlyOne: ['env-id', 'name']
26
+ }),
27
+ isDefault: Flags.boolean({
28
+ description: `Indicates this is the organization's default environment. The default value is false.`
29
+ }),
30
+ name: Flags.string({
31
+ char: 'n', description: 'Current name of the environment.',
32
+ exactlyOne: ['env-id', 'name']
33
+ }),
34
+ 'new-name': Flags.string({
35
+ description: 'New name of the environment.'
36
+ }),
23
37
  };
24
38
  async run() {
25
39
  const { flags } = await this.parse(PlatformEnvUpdate);
@@ -55,22 +69,14 @@ export default class PlatformEnvUpdate extends Command {
55
69
  const resp = await conn.put(apiUrl, body);
56
70
  this.log(`Environment with id '${envIdToUdpate}' has been updated successfully.`);
57
71
  this.print(resp.data);
72
+ return resp.data;
58
73
  }
59
74
  print(environment) {
60
- this.log();
61
75
  const tableRows = [
62
76
  ['Key', 'Value'],
63
77
  ...Object.entries(environment).map(([key, value]) => [camelCaseToTitleCase(key), value]),
64
78
  ];
65
- // Table config
66
- const config = {
67
- columns: {
68
- 1: { width: 50, wrapWord: true },
69
- },
70
- drawHorizontalLine(lineIndex, rowCount) {
71
- return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
72
- },
73
- };
74
- this.log(table(tableRows, config));
79
+ this.log();
80
+ this.log(renderKeyValueTable(tableRows));
75
81
  }
76
82
  }