-
Notifications
You must be signed in to change notification settings - Fork 102
/
rename.ts
74 lines (66 loc) · 2.13 KB
/
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
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
74
import { Flags } from '@oclif/core'
import inquirer from 'inquirer'
import { InstalledApp, InstalledAppListOptions } from '@smartthings/core-sdk'
import { APICommand, formatAndWriteItem, FormatAndWriteItemConfig, selectFromList, SelectFromListConfig, withLocations, WithNamedLocation } from '@smartthings/cli-lib'
import { listTableFieldDefinitions, tableFieldDefinitions } from '../../lib/commands/installedapps-util'
export default class InstalledAppRenameCommand extends APICommand<typeof InstalledAppRenameCommand.flags> {
static description = 'renamed an installed app instance'
static flags = {
...APICommand.flags,
...formatAndWriteItem.flags,
location: Flags.string({
char: 'l',
description: 'filter results by location',
multiple: true,
helpValue: '<UUID>',
}),
verbose: Flags.boolean({
description: 'include location name in output',
char: 'v',
}),
}
static args = [
{
name: 'id',
description: 'the installed app id',
},
{
name: 'name',
description: 'the new installed app name',
},
]
async run(): Promise<void> {
const config: SelectFromListConfig<InstalledApp & WithNamedLocation> & FormatAndWriteItemConfig<InstalledApp> = {
itemName: 'installed app',
primaryKeyName: 'installedAppId',
sortKeyName: 'displayName',
tableFieldDefinitions,
listTableFieldDefinitions,
}
if (this.flags.verbose) {
config.listTableFieldDefinitions.splice(3, 0, 'location')
}
const listOptions: InstalledAppListOptions = {
locationId: this.flags.location,
}
const id = await selectFromList(this, config, {
preselectedId: this.args.id,
listItems: async () => {
const apps = await this.client.installedApps.list(listOptions)
if (this.flags.verbose) {
return await withLocations(this.client, apps)
}
return apps
},
promptMessage: 'Select an app to rename.',
})
const displayName = this.args.name ??
(await inquirer.prompt({
type: 'input',
name: 'label',
message: 'Enter new installed app name:',
})).label
const updatedApp = await this.client.installedApps.update(id, { displayName })
await formatAndWriteItem(this, config, updatedApp)
}
}