MCPcopy Index your code
hub / github.com/SmartThingsCommunity/smartthings-cli / handler

Function handler

src/commands/locations/modes.ts:54–85  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

52 .epilog(buildEpilog({ command, apiDocs: ['getModes', 'getMode'] }))
53
54const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
55 const command = await apiCommand(argv)
56
57 const config: OutputItemOrListConfig<Mode & WithNamedLocation> = {
58 primaryKeyName: 'id',
59 sortKeyName: 'label',
60 listTableFieldDefinitions: tableFieldDefinitions,
61 tableFieldDefinitions: tableFieldDefinitions,
62 }
63 if (argv.verbose) {
64 config.listTableFieldDefinitions = tableFieldDefinitionsWithLocationName
65 config.tableFieldDefinitions = tableFieldDefinitionsWithLocationName
66 }
67 const modes = await getModesWithLocation(command.client, argv.location)
68 await outputItemOrList<Mode & WithNamedLocation>(
69 command,
70 config,
71 argv.idOrIndex,
72 async () => modes,
73 async id => {
74 const mode = modes.find(mode => mode.id === id)
75 if (!mode) {
76 return fatalError(`could not find mode with id ${id}`)
77 }
78 if (argv.verbose) {
79 return mode
80 }
81 // If we aren't using `verbose` flag, get the raw mode again
82 // so there aren't extra fields in JSON/YAML output
83 return command.client.modes.get(id, mode.locationId)
84 })
85}
86
87const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
88export default cmd

Callers

nothing calls this directly

Calls 3

apiCommandFunction · 0.85
getModesWithLocationFunction · 0.85
fatalErrorFunction · 0.85

Tested by

no test coverage detected