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

This file was deleted.

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

import { fatalError } from '../../lib/util.js'
import { apiDocsURL } from '../../lib/command/api-command.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-device-config-table.js'


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

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

const describe = 'get the device configuration 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:device-config',
'prompt for a device profile and display its device config',
],
[
'$0 deviceprofiles:device-config 2',
'display device config for the second device profile listed when running' +
' "smartthings deviceprofiles"',
],
[
'$0 deviceprofiles:device-config c4cb671a-c538-45fa-b076-24b2616181de',
'display device config for the specified device profile',
],
])
.epilog(apiDocsURL('getDeviceProfile', 'getDeviceConfiguration'))

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 deviceConfig = await command.client.presentation.get(profile.metadata.vid, profile.metadata.mnmn)
await formatAndWriteItem(
command,
{ buildTableOutput: data => buildTableOutput(command.tableGenerator, data) },
deviceConfig,
)
}

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 deviceprofilesDeviceConfigCommand from './deviceprofiles/device-config.js'
import deviceprofilesPresentationCommand from './deviceprofiles/presentation.js'
import deviceprofilesPublishCommand from './deviceprofiles/publish.js'
import deviceprofilesViewCommand from './deviceprofiles/view.js'
Expand Down Expand Up @@ -150,6 +151,7 @@ export const commands: CommandModule<object, any>[] = [
devicepreferencesTranslationsUpdateCommand,
deviceprofilesCommand,
deviceprofilesCreateCommand,
deviceprofilesDeviceConfigCommand,
deviceprofilesPresentationCommand,
deviceprofilesPublishCommand,
deviceprofilesViewCommand,
Expand Down