-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathdevice-config.ts
33 lines (25 loc) · 1.21 KB
/
device-config.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
import { Errors } from '@oclif/core'
import { APIOrganizationCommand, formatAndWriteItem } from '@smartthings/cli-lib'
import { buildTableOutput } from '../presentation/device-config'
import { chooseDeviceProfile } from '../../lib/commands/deviceprofiles-util'
export default class DeviceProfileDeviceConfigCommand extends APIOrganizationCommand<typeof DeviceProfileDeviceConfigCommand.flags> {
static description = 'get the device configuration associated with a device profile' +
this.apiDocsURL('getDeviceProfile', 'getDeviceConfiguration')
static flags = {
...APIOrganizationCommand.flags,
...formatAndWriteItem.flags,
}
static args = [{
name: 'id',
description: 'device profile id or the number in list',
}]
async run(): Promise<void> {
const id = await chooseDeviceProfile(this, this.args.id, { allowIndex: true })
const profile = await this.client.deviceProfiles.get(id)
if (!profile.metadata) {
throw new Errors.CLIError('No presentation defined for device profile')
}
const deviceConfig = await this.client.presentation.get(profile.metadata.vid, profile.metadata.mnmn)
await formatAndWriteItem(this, { buildTableOutput: data => buildTableOutput(this.tableGenerator, data) }, deviceConfig)
}
}