-
Notifications
You must be signed in to change notification settings - Fork 103
/
create.ts
52 lines (40 loc) · 1.63 KB
/
create.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
import inquirer from 'inquirer'
import { Channel, ChannelCreate } from '@smartthings/core-sdk'
import { inputAndOutputItem, TableFieldDefinition, userInputProcessor } from '@smartthings/cli-lib'
import { EdgeCommand } from '../../../lib/edge-command'
const tableFieldDefinitions: TableFieldDefinition<Channel>[] = ['channelId', 'name', 'description',
'type', 'termsOfServiceUrl', 'createdDate', 'lastModifiedDate']
export default class ChannelsCreateCommand extends EdgeCommand<typeof ChannelsCreateCommand.flags> {
static description = 'create a channel' +
this.apiDocsURL('createChannel')
static flags = {
...EdgeCommand.flags,
...inputAndOutputItem.flags,
}
async getInputFromUser(): Promise<ChannelCreate> {
const name = (await inquirer.prompt({
type: 'input',
name: 'name',
message: 'Channel name:',
validate: input => input ? true : 'name is required',
})).name as string
const description = (await inquirer.prompt({
type: 'input',
name: 'description',
message: 'Channel description:',
validate: input => input ? true : 'description is required',
})).description as string
const termsOfServiceUrl = (await inquirer.prompt({
type: 'input',
name: 'termsOfServiceUrl',
message: 'Channel terms of service URL:',
validate: input => input ? true : 'termsOfServiceUrl is required',
})).termsOfServiceUrl as string
return { name, description, termsOfServiceUrl, type: 'DRIVER' }
}
async run(): Promise<void> {
await inputAndOutputItem<ChannelCreate, Channel>(this, { tableFieldDefinitions },
(_, input: ChannelCreate) => this.client.channels.create(input),
userInputProcessor(this))
}
}