MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / handler

Function handler

src/commands/organizations/current.ts:41–68  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

39 .epilog(buildEpilog({ command }))
40
41const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
42 const command = await apiOrganizationCommand(argv)
43
44 const currentOrganizationId = command.cliConfig.stringConfigValue('organization')
45 const getOrganization = async (id: string): Promise<OrganizationResponse | undefined> => {
46 try {
47 return await command.client.organizations.get(id)
48 } catch (error) {
49 if (error.response?.status === 403) {
50 return undefined
51 }
52 throw error
53 }
54 }
55 const currentOrganization = currentOrganizationId
56 ? await getOrganization(currentOrganizationId)
57 : (await command.client.organizations.list()).find(org => org.isDefaultUserOrg)
58
59 if (currentOrganization) {
60 await formatAndWriteItem(command, { tableFieldDefinitions }, currentOrganization)
61 } else {
62 if (currentOrganizationId) {
63 console.error(`Organization '${currentOrganizationId}' not found`)
64 } else {
65 console.error('Could not find an active organization.')
66 }
67 }
68}
69
70const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
71export default cmd

Callers

nothing calls this directly

Calls 3

apiOrganizationCommandFunction · 0.85
getOrganizationFunction · 0.85
formatAndWriteItemFunction · 0.85

Tested by

no test coverage detected