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
45 changes: 0 additions & 45 deletions packages/cli/src/commands/deviceprofiles/presentation.ts

This file was deleted.

77 changes: 77 additions & 0 deletions src/commands/deviceprofiles/presentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs'

import { apiDocsURL } from '../../lib/command/api-command.js'
import { fatalError } from '../../lib/util.js'
import {
apiOrganizationCommand,
apiOrganizationCommandBuilder,
type APIOrganizationCommandFlags,
} from '../../lib/command/api-organization-command.js'
import {
formatAndWriteItem,
formatAndWriteItemBuilder,
type FormatAndWriteItemFlags,
} from '../../lib/command/format.js'
import { chooseDeviceProfile } from '../../lib/command/util/deviceprofiles-choose.js'
import { buildTableOutput } from '../../lib/command/util/presentation-table.js'


export type CommandArgs =
& APIOrganizationCommandFlags
& FormatAndWriteItemFlags
& {
idOrIndex?: string
}

const command = 'deviceprofiles:presentation [id-or-index]'

const describe = 'get the presentation associated with a device profile'

export const builder = (yargs: Argv): Argv<CommandArgs> =>
formatAndWriteItemBuilder(apiOrganizationCommandBuilder(yargs))
.positional('id-or-index', { describe: 'device profile id or number from list', type: 'string' })
.example([
[
'$0 deviceprofiles:presentation',
'prompt for a device profile and display its presentation information',
],
[
'$0 deviceprofiles:presentation 2',
'display presentation information for the second device profile listed when running' +
' "smartthings deviceprofiles"',
],
[
'$0 deviceprofiles:presentation fd4adb7f-4a23-4134-9b39-05ed889a03cf',
'display presentation information for the specified device profile',
],
[
'$0 deviceprofiles:presentation fd4adb7f-4a23-4134-9b39-05ed889a03cf --language ko',
'display presentation information for the specified device profile and language',
],
])
.epilog('Specifying only the presentationId defaults to the language set for the' +
' computer\'s operating system. The language can be overridden by specifying an ISO' +
' language code. If "NONE" is specified for the language' +
'flag then no language header is specified in the API request\n\n' +
apiDocsURL('getDeviceProfile', 'getDevicePresentation'))

const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
const command = await apiOrganizationCommand(argv)

const id = await chooseDeviceProfile(command, argv.idOrIndex, { allowIndex: true })

const profile = await command.client.deviceProfiles.get(id)
if (!profile.metadata) {
return fatalError('No presentation defined for device profile')
}

const presentation = await command.client.presentation.getPresentation(profile.metadata.vid, profile.metadata.mnmn)
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 @@ -33,6 +33,7 @@ import devicepreferencesTranslationsCreateCommand from './devicepreferences/tran
import devicepreferencesTranslationsUpdateCommand from './devicepreferences/translations/update.js'
import deviceprofilesCommand from './deviceprofiles.js'
import deviceprofilesCreateCommand from './deviceprofiles/create.js'
import deviceprofilesPresentationCommand from './deviceprofiles/presentation.js'
import deviceprofilesPublishCommand from './deviceprofiles/publish.js'
import deviceprofilesViewCommand from './deviceprofiles/view.js'
import deviceprofilesTranslations from './deviceprofiles/translations.js'
Expand Down Expand Up @@ -148,6 +149,7 @@ export const commands: CommandModule<object, any>[] = [
devicepreferencesTranslationsUpdateCommand,
deviceprofilesCommand,
deviceprofilesCreateCommand,
deviceprofilesPresentationCommand,
deviceprofilesPublishCommand,
deviceprofilesViewCommand,
deviceprofilesTranslations,
Expand Down
3 changes: 3 additions & 0 deletions src/lib/validate-util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { type ValidateFunction } from './user-query.js'


// TODO: it would be simpler and more flexible if we allowed min/max alongside regex here.
// Even though min/max can be specified in the regex, we can give the user better error messages
// if we include them specifically.
export type RegExStringValidationOptions = {
regex: string | RegExp

Expand Down