/
assign.ts
44 lines (35 loc) · 1.29 KB
/
assign.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
import { Flags } from '@oclif/core'
import { chooseChannel } from '../../../lib/commands/channels-util'
import { chooseDriver } from '../../../lib/commands/drivers-util'
import { EdgeCommand } from '../../../lib/edge-command'
export class ChannelsAssignCommand extends EdgeCommand<typeof ChannelsAssignCommand.flags> {
static description = 'assign a driver to a channel' +
this.apiDocsURL('createDriverChannel')
static flags = {
...EdgeCommand.flags,
channel: Flags.string({
char: 'C',
description: 'channel id',
helpValue: '<UUID>',
}),
}
static args = [
{
name: 'driverId',
description: 'driver id',
},
{
name: 'version',
description: 'driver version',
},
]
async run(): Promise<void> {
const channelId = await chooseChannel(this, 'Select a channel for the driver.',
this.flags.channel, { useConfigDefault: true })
const driverId = await chooseDriver(this, 'Select a driver to assign.', this.args.driverId)
// If the version wasn't specified, grab it from the driver.
const version = this.args.version ?? (await this.client.drivers.get(driverId)).version
await this.client.channels.assignDriver(channelId, driverId, version)
this.log(`${driverId} ${this.args.version ? `(version ${this.args.version})` : ''} assigned to channel ${channelId}`)
}
}