-
Notifications
You must be signed in to change notification settings - Fork 101
/
organizations.ts
47 lines (40 loc) · 1.41 KB
/
organizations.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
import { APICommand, outputItemOrList, OutputItemOrListConfig, TableFieldDefinition } from '@smartthings/cli-lib'
import { OrganizationResponse } from '@smartthings/core-sdk'
export const tableFieldDefinitions: TableFieldDefinition<OrganizationResponse>[] = [
'name', 'label', 'organizationId', 'developerGroupId', 'adminGroupId', 'warehouseGroupId',
{
prop: 'isDefaultUserOrg',
value: (i: OrganizationResponse): string | undefined => i.isDefaultUserOrg?.toString(),
},
{
prop: 'manufacturerName',
include: (i: OrganizationResponse): boolean => i.manufacturerName !== undefined,
},
{
prop: 'mnid',
include: (i: OrganizationResponse): boolean => i.mnid !== undefined,
},
]
export default class OrganizationsCommand extends APICommand<typeof OrganizationsCommand.flags> {
static description = 'list all organizations the user belongs to'
static flags = {
...APICommand.flags,
...outputItemOrList.flags,
}
static args = [{
name: 'id',
description: 'the organization name, id or index',
}]
async run(): Promise<void> {
const config: OutputItemOrListConfig<OrganizationResponse> = {
tableFieldDefinitions,
primaryKeyName: 'organizationId',
sortKeyName: 'name',
listTableFieldDefinitions: ['name', 'label', 'organizationId', 'isDefaultUserOrg'],
}
await outputItemOrList(this, config, this.args.id,
() => this.client.organizations.list(),
id => this.client.organizations.get(id),
)
}
}