-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
57 lines (37 loc) · 1.19 KB
/
index.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
import Command from '../../base'
import exec from '../../exec'
import inquirer from 'inquirer'
import { type ActionType, triggers } from '../../triggers'
import { clColor } from '@commercelayer/cli-core'
export default class OrdersIndex extends Command {
static description = 'execute an action on an order'
static flags = {
}
static args = {
...Command.args,
}
async run(): Promise<any> {
const { args, flags } = await this.parse(OrdersIndex)
const id = args.id
const action = await promptAction(id)
const fields = [] as string[] // ['id', 'status', 'payment_status', 'fulfillment_status', 'customer_email']
const res = await exec(id, action, flags, fields)
this.log()
this.printOutput(res, flags)
this.successMessage(action, res.id)
return res
}
}
const promptAction = async (id: string): Promise<ActionType> => {
const answers = await inquirer.prompt([{
type: 'list',
name: 'trigger',
message: `Select an action to execute on order ${clColor.yellowBright(id)}:`,
choices: Object.keys(triggers).sort().map(a => {
return { name: a, value: a }
}),
loop: false,
pageSize: 10,
}])
return answers.trigger
}