-
Notifications
You must be signed in to change notification settings - Fork 3
/
get.ts
49 lines (44 loc) · 1.47 KB
/
get.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
import inquirer from 'inquirer'
import { fetchVariations } from '../../api/variations'
import { featurePrompt, FeaturePromptResult } from '../../ui/prompts'
import Base from '../base'
import { Args } from '@oclif/core'
export default class GetVariations extends Base {
static hidden = false
authRequired = true
static description =
'Retrieve variations for a feature from the management API'
static args = {
feature: Args.string({
name: 'feature',
description: 'Feature key or id',
}),
}
public async run(): Promise<void> {
const { args, flags } = await this.parse(GetVariations)
const { headless, project } = flags
await this.requireProject(project, headless)
let featureKey
if (headless && !args.feature) {
this.writer.showError('In headless mode, feature is required')
return
} else if (!args.feature) {
const { feature } = await inquirer.prompt<FeaturePromptResult>(
[featurePrompt],
{
token: this.authToken,
projectKey: this.projectKey,
},
)
featureKey = feature.key
} else {
featureKey = args.feature
}
const variations = await fetchVariations(
this.authToken,
this.projectKey,
featureKey,
)
this.writer.showResults(variations)
}
}