Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions packages/cli/src/commands/devices/presentation.ts

This file was deleted.

59 changes: 59 additions & 0 deletions src/commands/devices/presentation.ts
Original file line number Diff line number Diff line change
@@ -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<CommandArgs> =>
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<CommandArgs>): Promise<void> => {
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<object, CommandArgs> = { command, describe, builder, handler }
export default cmd
2 changes: 2 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -163,6 +164,7 @@ export const commands: CommandModule<object, any>[] = [
devicesDeleteCommand,
devicesHistoryCommand,
devicesPreferencesCommand,
devicesPresentationCommand,
devicesUpdateCommand,
edgeChannelsCommand,
edgeChannelsCreateCommand,
Expand Down