/
apps.ts
72 lines (61 loc) · 2.68 KB
/
apps.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 { AppType, AppClassification, AppListOptions, PagedApp, AppResponse } from '@smartthings/core-sdk'
import { APICommand, outputItemOrList, OutputItemOrListConfig } from '@smartthings/cli-lib'
import { shortARNorURL, tableFieldDefinitions, verboseApps } from '../lib/commands/apps-util'
export default class AppsCommand extends APICommand<typeof AppsCommand.flags> {
static description = 'get a specific app or a list of apps' +
this.apiDocsURL('listApps', 'getApp')
static flags = {
...APICommand.flags,
...outputItemOrList.flags,
type: Flags.string({
description: 'filter results by appType, WEBHOOK_SMART_APP, LAMBDA_SMART_APP, API_ONLY',
multiple: false,
}),
classification: Flags.string({
description: 'filter results by one or more classifications, AUTOMATION, SERVICE, DEVICE, CONNECTED_SERVICE',
multiple: true,
}),
verbose: Flags.boolean({
description: 'include URLs and ARNs in table output',
char: 'v',
}),
}
static args = [{
name: 'id',
description: 'the app id or number from list',
}]
static examples = [
{ description: 'list all apps', command: 'smartthings apps' },
{ description: 'list the first app in the list retrieved by running "smartthings apps"', command: 'smartthings apps 1' },
{ description: 'list an app by id', command: 'smartthings apps 5dfd6626-ab1d-42da-bb76-90def3153998' },
{ description: 'include URLs and ARNs in the output', command: 'smartthings apps --verbose' },
{ description: 'list SERVICE classification apps', command: 'smartthings apps --classification SERVICE' },
{ description: 'list API-only apps', command: 'smartthings apps --type API_ONLY' },
]
async run(): Promise<void> {
const config: OutputItemOrListConfig<AppResponse, PagedApp | AppResponse> = {
primaryKeyName: 'appId',
sortKeyName: 'displayName',
tableFieldDefinitions,
listTableFieldDefinitions: ['displayName', 'appType', 'appId'],
}
if (this.flags.verbose) {
config.listTableFieldDefinitions.push({ label: 'ARN/URL', value: shortARNorURL })
}
const listApps = async (): Promise<PagedApp[] | AppResponse[]> => {
const appListOptions: AppListOptions = {}
if (this.flags.type) {
appListOptions.appType = AppType[this.flags.type as keyof typeof AppType]
}
if (this.flags.classification) {
appListOptions.classification = this.flags.classification.map(classification => AppClassification[classification as keyof typeof AppClassification])
}
if (this.flags.verbose) {
return verboseApps(this.client, appListOptions)
}
return this.client.apps.list(appListOptions)
}
await outputItemOrList(this, config, this.args.id, listApps, id => this.client.apps.get(id))
}
}