-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathchannels.ts
73 lines (61 loc) · 2.42 KB
/
channels.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
70
71
72
73
import { Flags } from '@oclif/core'
import { Channel, SubscriberType } from '@smartthings/core-sdk'
import { allOrganizationsFlags, outputItemOrList, OutputItemOrListConfig, WithOrganization } from '@smartthings/cli-lib'
import { EdgeCommand } from '../../lib/edge-command'
import { listChannels, listTableFieldDefinitions, tableFieldDefinitions } from '../../lib/commands/channels-util'
export default class ChannelsCommand extends EdgeCommand<typeof ChannelsCommand.flags> {
static description = 'list all channels owned by you or retrieve a single channel' +
this.apiDocsURL('listChannels', 'channelById')
/* eslint-disable @typescript-eslint/naming-convention */
static flags = {
...EdgeCommand.flags,
...outputItemOrList.flags,
...allOrganizationsFlags,
'include-read-only': Flags.boolean({
char: 'I',
description: 'include subscribed-to channels as well as owned channels',
exclusive: ['all-organizations'],
}),
'subscriber-type': Flags.string({
description: 'filter results based on subscriber type',
options: ['HUB'],
}),
'subscriber-id': Flags.string({
description: 'filter results based on subscriber id (e.g. hub id)',
dependsOn: ['subscriber-type'],
helpValue: '<UUID>',
}),
}
/* eslint-enable @typescript-eslint/naming-convention */
static args = [{
name: 'idOrIndex',
description: 'the channel id or number in list',
}]
static examples = [`# list all user-owned channels
$ smartthings edge:channels
# list user-owned and subscribed channels
$ smartthings edge:channels --include-read-only`,
`
# display details about the second channel listed when running "smartthings edge:channels"
$ smartthings edge:channels 2
# display channels subscribed to by the specified hub
$ smartthings edge:channels --subscriber-type HUB --subscriber-id <hub-id>`]
async run(): Promise<void> {
const config: OutputItemOrListConfig<Channel & WithOrganization> = {
primaryKeyName: 'channelId',
sortKeyName: 'name',
listTableFieldDefinitions,
tableFieldDefinitions,
}
if (this.flags['all-organizations']) {
config.listTableFieldDefinitions.push('organization')
}
await outputItemOrList(this, config, this.args.idOrIndex,
async () => listChannels(this.client, {
subscriberType: this.flags['subscriber-type'] as SubscriberType | undefined,
subscriberId: this.flags['subscriber-id'],
includeReadOnly: this.flags['include-read-only'],
}),
id => this.client.channels.get(id))
}
}