-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathexecute.ts
48 lines (37 loc) · 1.44 KB
/
execute.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
import { Flags } from '@oclif/core'
import { RuleExecutionResponse } from '@smartthings/core-sdk'
import { APICommand, formatAndWriteItem } from '@smartthings/cli-lib'
import { buildExecuteResponseTableOutput, chooseRule, getRuleWithLocation } from '../../lib/commands/rules-util'
export default class RulesExecuteCommand extends APICommand<typeof RulesExecuteCommand.flags> {
static description = 'execute a rule' +
this.apiDocsURL('executeRule')
static flags = {
...APICommand.flags,
...formatAndWriteItem.flags,
location: Flags.string({
char: 'l',
description: 'a specific location to query',
helpValue: '<UUID>',
}),
}
static args = [{
name: 'id',
description: 'rule UUID',
}]
static examples = [
'# prompt for a rule to execute and then execute it',
'$ smartthings rules:execute',
'',
'# execute the rule with the specified id',
'$ smartthings rules:execute 699c7308-8c72-4363-9571-880d0f5cc725',
]
async run(): Promise<void> {
const ruleId = await chooseRule(this, 'Select a rule to execute.', this.flags.location, this.args.id)
const locationId = this.flags.location
?? (await getRuleWithLocation(this.client, ruleId, this.flags.location)).locationId
const result = await this.client.rules.execute(ruleId, locationId)
await formatAndWriteItem<RuleExecutionResponse>(this,
{ buildTableOutput: (data: RuleExecutionResponse) => buildExecuteResponseTableOutput(this.tableGenerator, data) },
result)
}
}