/
install.ts
62 lines (52 loc) · 2.13 KB
/
install.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
import { Flags } from '@oclif/core'
import { EnrolledChannel } from '@smartthings/core-sdk'
import { selectFromList, SelectFromListConfig } from '@smartthings/cli-lib'
import { chooseDriverFromChannel, chooseHub } from '../../../lib/commands/drivers-util'
import { EdgeCommand } from '../../../lib/edge-command'
export default class DriversInstallCommand extends EdgeCommand<typeof DriversInstallCommand.flags> {
static description = 'install an edge driver onto a hub' +
this.apiDocsURL('installDrivers')
static examples = [
'smartthings edge:drivers:install # use Q&A format to enter required values',
'smartthings edge:drivers:install -H <hub-id> # specify the hub on the command line, other fields will be asked for',
'smartthings edge:drivers:install -H <hub-id> -C <channel-id> <driver-id> # install a driver from a channel on an enrolled hub',
]
static flags = {
...EdgeCommand.flags,
hub: Flags.string({
char: 'H',
description: 'hub id',
helpValue: '<UUID>',
}),
channel: Flags.string({
char: 'C',
description: 'channel id',
helpValue: '<UUID>',
}),
}
static args = [{
name: 'driverId',
description: 'id of driver to install',
}]
async chooseChannelFromEnrollments(hubId: string): Promise<string> {
const config: SelectFromListConfig<EnrolledChannel> = {
itemName: 'hub-enrolled channel',
primaryKeyName: 'channelId',
sortKeyName: 'name',
}
const listItems = (): Promise<EnrolledChannel[]> =>
this.client.hubdevices.enrolledChannels(hubId)
return selectFromList(this, config, {
listItems,
promptMessage: 'Select a channel to install the driver from.',
})
}
async run(): Promise<void> {
const hubId = await chooseHub(this, 'Select a hub to install to.', this.flags.hub,
{ useConfigDefault: true })
const channelId = this.flags.channel ?? await this.chooseChannelFromEnrollments(hubId)
const driverId = await chooseDriverFromChannel(this, channelId, this.args.driverId)
await this.client.hubdevices.installDriver(driverId, hubId, channelId)
this.log(`driver ${driverId} installed to hub ${hubId}`)
}
}