-
Notifications
You must be signed in to change notification settings - Fork 102
/
rules.ts
41 lines (33 loc) · 1.17 KB
/
rules.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
import { Flags } from '@oclif/core'
import { Rule } from '@smartthings/core-sdk'
import { APICommand, outputItemOrList, OutputItemOrListConfig, WithNamedLocation } from '@smartthings/cli-lib'
import { getRulesByLocation, getRuleWithLocation, tableFieldDefinitions } from '../lib/commands/rules-util'
export default class RulesCommand extends APICommand<typeof RulesCommand.flags> {
static description = 'get a specific rule' +
this.apiDocsURL('listRules', 'getRule')
static flags = {
...APICommand.flags,
...outputItemOrList.flags,
location: Flags.string({
char: 'l',
description: 'a specific location to query',
helpValue: '<UUID>',
}),
}
static args = [{
name: 'idOrIndex',
description: 'rule UUID or index',
}]
async run(): Promise<void> {
const config: OutputItemOrListConfig<Rule & WithNamedLocation> = {
primaryKeyName: 'id',
sortKeyName: 'name',
listTableFieldDefinitions: ['name', 'id', 'locationId', 'location'],
tableFieldDefinitions,
}
await outputItemOrList(this, config, this.args.idOrIndex,
() => getRulesByLocation(this.client, this.flags.location),
id => getRuleWithLocation(this.client, id, this.flags.location),
)
}
}