/
update.ts
41 lines (33 loc) · 1.39 KB
/
update.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { flags } from '@oclif/command';
import chalk from 'chalk';
import { cli } from 'cli-ux';
import Command from '../../base-command';
export default class EnvironmentUpdate extends Command {
static aliases = ['environment:update', 'envs:update', 'env:update'];
static description = 'Update an environments configuration';
static flags = {
...Command.flags,
description: flags.string({ char: 'd' }),
};
static args = [{
name: 'namespaced_environment',
description: 'Name of the environment to update',
required: true,
parse: (value: string) => value.toLowerCase(),
}];
async run() {
const { args, flags } = this.parse(EnvironmentUpdate);
const [account_name, env_name] = args.namespaced_environment.split('/');
if (!account_name || !env_name) {
throw new Error(`Please specify a namespaced environment in the form <account_name>/<environment_name>`);
}
const account = (await this.app.api.get(`/accounts/${account_name}`)).data;
cli.action.start(chalk.blue('Updating environment'));
const { data: account_environment } = await this.app.api.get(`/accounts/${account.id}/environments/${env_name}`);
const answers = { ...args, ...flags };
await this.app.api.put(`/environments/${account_environment.id}`, {
description: answers.description,
});
cli.action.stop(chalk.green('Environment updated successfully'));
}
}