-
Notifications
You must be signed in to change notification settings - Fork 107
/
current.ts
31 lines (24 loc) · 996 Bytes
/
current.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
import { APIOrganizationCommand, formatAndWriteItem, outputItem } from '@smartthings/cli-lib'
import { tableFieldDefinitions } from '../organizations'
export default class OrganizationCurrentCommand extends APIOrganizationCommand<typeof OrganizationCurrentCommand.flags> {
static description = 'return the currently active organization'
static flags = {
...APIOrganizationCommand.flags,
...outputItem.flags,
}
static args = []
async run(): Promise<void> {
let currentOrganization
const currentOrganizationId = this.stringConfigValue('organization')
if (currentOrganizationId) {
currentOrganization = await this.client.organizations.get(currentOrganizationId)
} else {
currentOrganization = (await this.client.organizations.list()).find(org => org.isDefaultUserOrg)
}
if (currentOrganization) {
await formatAndWriteItem(this, { tableFieldDefinitions }, currentOrganization)
} else {
this.warn(`Organization '${currentOrganizationId}' not found`)
}
}
}