-
Notifications
You must be signed in to change notification settings - Fork 103
/
delete.ts
59 lines (50 loc) · 1.67 KB
/
delete.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
import { Flags } from '@oclif/core'
import { InstalledApp, InstalledAppListOptions } from '@smartthings/core-sdk'
import { selectFromList, APICommand, withLocations, SelectFromListConfig, WithNamedLocation } from '@smartthings/cli-lib'
export default class InstalledAppDeleteCommand extends APICommand<typeof InstalledAppDeleteCommand.flags> {
static description = 'delete an installed app instance' +
this.apiDocsURL('deleteInstallation')
static flags = {
...APICommand.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: 'installed app UUID',
}]
async run(): Promise<void> {
const config: SelectFromListConfig<InstalledApp & WithNamedLocation> = {
primaryKeyName: 'installedAppId',
sortKeyName: 'displayName',
listTableFieldDefinitions: ['displayName', 'installedAppType', 'installedAppStatus', 'installedAppId'],
}
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 installed app to delete.',
})
await this.client.installedApps.delete(id),
this.log(`Installed app ${id} deleted.`)
}
}