-
Notifications
You must be signed in to change notification settings - Fork 104
/
deviceprofiles.ts
69 lines (57 loc) · 2.48 KB
/
deviceprofiles.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Flags } from '@oclif/core'
import { DeviceProfile } from '@smartthings/core-sdk'
import {
APIOrganizationCommand,
WithOrganization,
allOrganizationsFlags,
outputItemOrList,
forAllOrganizations,
OutputItemOrListConfig,
} from '@smartthings/cli-lib'
import { buildTableOutput } from '../lib/commands/deviceprofiles-util'
export default class DeviceProfilesCommand extends APIOrganizationCommand<typeof DeviceProfilesCommand.flags> {
static description = 'list all device profiles available in a user account or retrieve a single profile' +
this.apiDocsURL('listDeviceProfiles', 'getDeviceProfile')
static flags = {
...APIOrganizationCommand.flags,
...outputItemOrList.flags,
...allOrganizationsFlags,
verbose: Flags.boolean({
description: 'include presentationId and manufacturerName in list output',
char: 'v',
}),
}
static args = [{
name: 'id',
description: 'device profile to retrieve; UUID or the number of the profile from list',
}]
static examples = [
'$ smartthings deviceprofiles # list all device profiles',
'$ smartthings deviceprofiles bb0fdc5-...-a8bd2ea # show device profile with the specified UUID',
'$ smartthings deviceprofiles 2 # show the second device profile in the list',
'$ smartthings deviceprofiles 3 -j # show the profile in JSON format',
'$ smartthings deviceprofiles 5 -y # show the profile in YAML format',
'$ smartthings deviceprofiles 4 -j -o profile.json # write the profile to the file "profile.json"',
]
async run(): Promise<void> {
const config: OutputItemOrListConfig<DeviceProfile & WithOrganization> = {
primaryKeyName: 'id',
sortKeyName: 'name',
listTableFieldDefinitions: ['name', 'status', 'id'],
buildTableOutput: (data: DeviceProfile) => buildTableOutput(this.tableGenerator, data),
}
if (this.flags['all-organizations']) {
config.listTableFieldDefinitions = ['name', 'status', 'id', 'organization']
}
if (this.flags.verbose) {
config.listTableFieldDefinitions.push({ label: 'Presentation ID', value: item => item.metadata?.vid ?? '' })
config.listTableFieldDefinitions.push({ label: 'Manufacturer Name', value: item => item.metadata?.mnmn ?? '' })
}
await outputItemOrList(this, config, this.args.id,
() => this.flags['all-organizations']
? forAllOrganizations(this.client, (orgClient) => orgClient.deviceProfiles.list())
: this.client.deviceProfiles.list(),
id => this.client.deviceProfiles.get(id),
)
}
}