-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathcreate.ts
32 lines (23 loc) · 921 Bytes
/
create.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
import { Flags } from '@oclif/core'
import { Rule, RuleRequest } from '@smartthings/core-sdk'
import { APICommand, inputAndOutputItem } from '@smartthings/cli-lib'
import { chooseLocation } from '../locations'
import { tableFieldDefinitions } from '../../lib/commands/rules/rules-util'
export default class RulesCreateCommand extends APICommand {
static description = 'create a rule'
static flags = {
...APICommand.flags,
...inputAndOutputItem.flags,
'location-id': Flags.string({
char: 'l',
description: 'a specific location to query',
}),
}
async run(): Promise<void> {
const { args, argv, flags } = await this.parse(RulesCreateCommand)
await super.setup(args, argv, flags)
const locationId = await chooseLocation(this, flags['location-id'])
await inputAndOutputItem<RuleRequest, Rule>(this, { tableFieldDefinitions },
(_, rule) => this.client.rules.create(rule, locationId))
}
}