/
update.ts
68 lines (63 loc) · 2.18 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import inquirer from '../../ui/autocomplete'
import { updateEnvironment } from '../../api/environments'
import {
descriptionPrompt,
namePrompt,
environmentPrompt,
EnvironmentPromptResult,
} from '../../ui/prompts'
import { Flags } from '@oclif/core'
import { CreateEnvironmentDto, UpdateEnvironmentDto } from '../../api/schemas'
import UpdateCommandWithCommonProperties from '../updateCommandWithCommonProperties'
export default class UpdateEnvironment extends UpdateCommandWithCommonProperties {
static hidden = false
static description = 'Update a Environment.'
prompts = [namePrompt, descriptionPrompt]
static flags = {
...UpdateCommandWithCommonProperties.flags,
key: Flags.string({
description: 'Unique ID',
}),
type: Flags.string({
description: 'The type of environment',
options: CreateEnvironmentDto.shape.type.options,
}),
description: Flags.string({
description: 'Description for the environment',
}),
}
public async run(): Promise<void> {
const { args, flags } = await this.parse(UpdateEnvironment)
const { key } = args
const { headless, project } = flags
await this.requireProject(project, headless)
let envKey = key
if (headless && !envKey) {
this.writer.showError('The key argument is required')
return
} else if (!envKey) {
const { environment } =
await inquirer.prompt<EnvironmentPromptResult>(
[environmentPrompt],
{
token: this.authToken,
projectKey: this.projectKey,
},
)
envKey = environment._id
this.writer.printCurrentValues(environment)
}
const params = await this.populateParametersWithZod(
UpdateEnvironmentDto,
this.prompts,
flags,
)
const result = await updateEnvironment(
this.authToken,
this.projectKey,
envKey,
params,
)
this.writer.showResults(result)
}
}