-
Notifications
You must be signed in to change notification settings - Fork 104
/
update.ts
38 lines (29 loc) · 1.06 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
import { Flags } from '@oclif/core'
import { Rule, RuleRequest } from '@smartthings/core-sdk'
import { APICommand, inputAndOutputItem } from '@smartthings/cli-lib'
import { chooseRule, getRuleWithLocation, tableFieldDefinitions } from '../../lib/commands/rules-util'
export default class RulesUpdateCommand extends APICommand<typeof RulesUpdateCommand.flags> {
static description = 'update a rule' +
this.apiDocsURL('updateRule')
static flags = {
...APICommand.flags,
...inputAndOutputItem.flags,
location: Flags.string({
char: 'l',
description: 'a specific location to query',
helpValue: '<UUID>',
}),
}
static args = [{
name: 'id',
description: 'rule UUID',
}]
async run(): Promise<void> {
const id = await chooseRule(this, 'Select a rule to update.', this.flags.location, this.args.id)
await inputAndOutputItem<RuleRequest, Rule>(this, { tableFieldDefinitions },
async (_, data) => {
const rule = await getRuleWithLocation(this.client, id, this.flags.location)
return this.client.rules.update(id, data, rule.locationId)
})
}
}