diff --git a/packages/cli/src/commands/devices/presentation.ts b/packages/cli/src/commands/devices/presentation.ts deleted file mode 100644 index 0acae946..00000000 --- a/packages/cli/src/commands/devices/presentation.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { APICommand, chooseDevice, formatAndWriteItem } from '@smartthings/cli-lib' - -import { buildTableOutput } from '../presentation.js' - - -export const tableFieldDefinitions = ['clientName', 'scope', 'redirectUris'] - -export default class DevicePresentationCommand extends APICommand { - static description = 'get a device presentation' - - static flags = { - ...APICommand.flags, - ...formatAndWriteItem.flags, - } - - static args = [{ - name: 'id', - description: 'the device id or number in the list', - }] - - async run(): Promise { - const deviceId = await chooseDevice(this, this.args.id, { allowIndex: true }) - const presentation = await this.client.devices.getPresentation(deviceId) - await formatAndWriteItem(this, { buildTableOutput: data => buildTableOutput(this.tableGenerator, data) }, presentation) - } -} diff --git a/src/commands/devices/presentation.ts b/src/commands/devices/presentation.ts new file mode 100644 index 00000000..ba42580c --- /dev/null +++ b/src/commands/devices/presentation.ts @@ -0,0 +1,59 @@ +import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs' + +import { + apiCommand, + apiCommandBuilder, + apiDocsURL, + type APICommandFlags, +} from '../../lib/command/api-command.js' +import { + formatAndWriteItem, + formatAndWriteItemBuilder, + type FormatAndWriteItemFlags, +} from '../../lib/command/format.js' +import { chooseDevice } from '../../lib/command/util/devices-choose.js' +import { buildTableOutput } from '../../lib/command/util/presentation-table.js' + + +export type CommandArgs = + & APICommandFlags + & FormatAndWriteItemFlags + & { + idOrIndex?: string + } + +const command = 'devices:presentation [id-or-index]' + +const describe = 'get a device presentation' + +const builder = (yargs: Argv): Argv => + formatAndWriteItemBuilder(apiCommandBuilder(yargs)) + .positional('id-or-index', { describe: 'device id or number from list', type: 'string' }) + .example([ + ['$0 devices:presentation', 'choose a device from a list and display its presentation'], + [ + '$0 devices:presentation 3', + 'display the presentation for the third device listed when running "smartthings devices"', + ], + [ + '$0 devices:presentation a13a3fbb-2b97-4c73-978d-ae7c2fca3ea8', + 'display the presentation for the specified device', + ], + ]) + .epilog(apiDocsURL('getDevicePresentation')) + + +const handler = async (argv: ArgumentsCamelCase): Promise => { + const command = await apiCommand(argv) + + const deviceId = await chooseDevice(command, argv.idOrIndex, { allowIndex: true }) + const presentation = await command.client.devices.getPresentation(deviceId) + await formatAndWriteItem( + command, + { buildTableOutput: data => buildTableOutput(command.tableGenerator, data) }, + presentation, + ) +} + +const cmd: CommandModule = { command, describe, builder, handler } +export default cmd diff --git a/src/commands/index.ts b/src/commands/index.ts index 45737617..6f8eb5c1 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -48,6 +48,7 @@ import devicesStatusCommand from './devices/status.js' import devicesDeleteCommand from './devices/delete.js' import devicesHistoryCommand from './devices/history.js' import devicesPreferencesCommand from './devices/preferences.js' +import devicesPresentationCommand from './devices/presentation.js' import devicesUpdateCommand from './devices/update.js' import edgeChannelsCommand from './edge/channels.js' import edgeChannelsCreateCommand from './edge/channels/create.js' @@ -163,6 +164,7 @@ export const commands: CommandModule[] = [ devicesDeleteCommand, devicesHistoryCommand, devicesPreferencesCommand, + devicesPresentationCommand, devicesUpdateCommand, edgeChannelsCommand, edgeChannelsCreateCommand,