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

This file was deleted.

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

import { type DeviceProfile } from '@smartthings/core-sdk'

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 {
inputAndOutputItem,
inputAndOutputItemBuilder,
type InputAndOutputItemFlags,
} from '../../lib/command/input-and-output-item.js'
import { type ActionFunction } from '../../lib/command/io-defs.js'
import {
buildTableOutput,
cleanupForUpdate,
type DeviceDefinitionRequest,
} from '../../lib/command/util/deviceprofiles-util.js'
import { chooseDeviceProfile } from '../../lib/command/util/deviceprofiles-choose.js'


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

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

const describe = 'update a device profile'

const builder = (yargs: Argv): Argv<CommandArgs> =>
inputAndOutputItemBuilder(apiOrganizationCommandBuilder(yargs))
.positional('id-or-index', { describe: 'device profile id or number from list', type: 'string' })
.example([
[
'$0 deviceprofiles:update --input my-profile.yaml',
'prompt for a device profile and update it using the data in my-profile.yaml',
],
[
'$0 deviceprofiles:update --input my-profile.json 204cf401-bb4b-4dfc-91ec-729f5d8075ef',
'update the specified device profile using the data in my-profile.json',
],
])
.epilog(apiDocsURL('updateDeviceProfile'))

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

const id = await chooseDeviceProfile(command, argv.idOrIndex)
const executeUpdate: ActionFunction<void, DeviceDefinitionRequest, DeviceProfile> = async (_, data) => {
if (data.view) {
return fatalError('Input contains "view" property. Use deviceprofiles:view:update instead.')
}

return command.client.deviceProfiles.update(id, cleanupForUpdate(data))
}
await inputAndOutputItem(
command,
{ buildTableOutput: data => buildTableOutput(command.tableGenerator, data, { includePreferences: true }) },
executeUpdate,
)
}

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 @@ -38,6 +38,7 @@ import deviceprofilesViewCommand from './deviceprofiles/view.js'
import deviceprofilesTranslations from './deviceprofiles/translations.js'
import deviceprofilesTranslationsDelete from './deviceprofiles/translations/delete.js'
import deviceprofilesTranslationsUpsertCommand from './deviceprofiles/translations/upsert.js'
import deviceprofilesUpdateCommand from './deviceprofiles/update.js'
import deviceprofilesViewCreateCommand from './deviceprofiles/view/create.js'
import deviceprofilesViewUpdateCommand from './deviceprofiles/view/update.js'
import devicesCommand from './devices.js'
Expand Down Expand Up @@ -153,6 +154,7 @@ export const commands: CommandModule<object, any>[] = [
deviceprofilesTranslations,
deviceprofilesTranslationsDelete,
deviceprofilesTranslationsUpsertCommand,
deviceprofilesUpdateCommand,
deviceprofilesViewCreateCommand,
deviceprofilesViewUpdateCommand,
devicesCommand,
Expand Down