-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.ts
77 lines (63 loc) · 1.86 KB
/
config.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
69
70
71
72
73
74
75
76
77
import config from '../services/config'
import BaseCommand from '../base/base-command'
import ui from '../services/ui'
import state, { Mode } from '../services/state'
import renderers from '../renderers'
export default class Config extends BaseCommand {
skipConfigValidation = true
static description = 'codex configuration management'
static examples = [
'$ codex config',
'$ codex config foo.bar',
'$ codex config foo.bar value'
]
static flags = {
...BaseCommand.flags
}
static args = [{
name: 'path',
required: false,
description: 'configuration setting path e.g. \'auth.username\'',
type: 'string'
}, {
name: 'value',
required: false,
description: 'configuration value'
}]
async run() {
if (this.args.path === undefined) {
/* display the whole config */
this.log(renderers.json.marshal(config.data))
} else if (this.args.value === undefined) {
/* display the value */
this.log(config.get(this.args.path))
} else {
/* set the value */
let resetState = false
if (this.args.path === 's3.bucket') {
/* state will be reset, warn */
resetState = true
if (state.mode !== Mode.IDLE) {
ui.warning('You\'re currently editing a patch; changing the bucket will result in the state being reset')
const { Toggle } = require('enquirer')
const prompt = new Toggle({
message: 'Are you sure you want to reset the state?',
enabled: 'Yes',
disabled: 'No'
});
const answer = await prompt.run()
if (!answer) {
ui.info('bailing out')
return
}
}
}
config.set(this.args.path, this.args.value)
config.save()
if (resetState) {
ui.info('resetting state')
await state.reset()
}
}
}
}