-
Notifications
You must be signed in to change notification settings - Fork 104
/
update.ts
42 lines (33 loc) · 1.27 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
39
40
41
42
import { Errors } from '@oclif/core'
import { DeviceProfile } from '@smartthings/core-sdk'
import { ActionFunction, APIOrganizationCommand, inputAndOutputItem } from '@smartthings/cli-lib'
import {
buildTableOutput,
chooseDeviceProfile,
cleanupForUpdate,
DeviceDefinitionRequest,
} from '../../lib/commands/deviceprofiles-util'
export default class DeviceProfileUpdateCommand extends APIOrganizationCommand<typeof DeviceProfileUpdateCommand.flags> {
static description = 'update a device profile' +
this.apiDocsURL('updateDeviceProfile')
static flags = {
...APIOrganizationCommand.flags,
...inputAndOutputItem.flags,
}
static args = [{
name: 'id',
description: 'device profile UUID or number in the list',
}]
async run(): Promise<void> {
const id = await chooseDeviceProfile(this, this.args.id)
const executeUpdate: ActionFunction<void, DeviceDefinitionRequest, DeviceProfile> = async (_, data) => {
if (data.view) {
throw new Errors.CLIError('Input contains "view" property. Use deviceprofiles:view:update instead.')
}
return this.client.deviceProfiles.update(id, cleanupForUpdate(data))
}
await inputAndOutputItem(this, {
buildTableOutput: data => buildTableOutput(this.tableGenerator, data, { includePreferences: true }),
}, executeUpdate)
}
}