-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathinstalledapps.ts
72 lines (60 loc) · 2.03 KB
/
installedapps.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
import { Flags } from '@oclif/core'
import { InstalledApp, InstalledAppListOptions } from '@smartthings/core-sdk'
import { APICommand, outputListing, TableFieldDefinition, withLocations } from '@smartthings/cli-lib'
export type InstalledAppWithLocation = InstalledApp & { location?: string }
export const listTableFieldDefinitions = ['displayName', 'installedAppType', 'installedAppStatus', 'installedAppId']
export const tableFieldDefinitions: TableFieldDefinition<InstalledApp>[] = [
'displayName', 'installedAppId', 'installedAppType', 'installedAppStatus',
'singleInstance', 'appId', 'locationId', 'singleInstance',
{
label: 'Classifications',
value: installedApp => installedApp.classifications?.join('\n') ?? '',
include: installedApp => !!installedApp.classifications,
},
]
export default class InstalledAppsCommand extends APICommand {
static description = 'get a specific app or a list of apps'
static flags = {
...APICommand.flags,
...outputListing.flags,
'location-id': Flags.string({
char: 'l',
description: 'filter results by location',
multiple: true,
}),
verbose: Flags.boolean({
description: 'include location name in output',
char: 'v',
}),
}
static args = [{
name: 'id',
description: 'the app id',
}]
async run(): Promise<void> {
const { args, argv, flags } = await this.parse(InstalledAppsCommand)
await super.setup(args, argv, flags)
const config = {
primaryKeyName: 'installedAppId',
sortKeyName: 'displayName',
listTableFieldDefinitions,
tableFieldDefinitions,
}
if (this.flags.verbose) {
config.listTableFieldDefinitions.splice(3, 0, 'location')
}
const listOptions: InstalledAppListOptions = {
locationId: flags['location-id'],
}
await outputListing<InstalledApp, InstalledAppWithLocation>(this, config, args.id,
async () => {
const apps = await this.client.installedApps.list(listOptions)
if (this.flags.verbose) {
return await withLocations(this.client, apps)
}
return apps
},
id => this.client.installedApps.get(id),
)
}
}