/
rename.ts
40 lines (31 loc) · 953 Bytes
/
rename.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
import inquirer from 'inquirer'
import { APICommand, chooseDevice, outputItem } from '@smartthings/cli-lib'
import { buildTableOutput } from '../../lib/commands/devices-util'
export default class DeviceRenameCommand extends APICommand<typeof DeviceRenameCommand.flags> {
static description = 'rename a device' +
this.apiDocsURL('updateDevice')
static flags = {
...APICommand.flags,
...outputItem.flags,
}
static args = [
{
name: 'id',
description: 'the device id',
},
{
name: 'label',
description: 'the new device label',
},
]
async run(): Promise<void> {
const id = await chooseDevice(this, this.args.id)
const label = this.args.label ?? (await inquirer.prompt({
type: 'input',
name: 'label',
message: 'Enter new device label:',
})).label
await outputItem(this, { buildTableOutput: data => buildTableOutput(this.tableGenerator, data) },
() => this.client.devices.update(id, { label }))
}
}