diff --git a/packages/cli/src/commands/deviceprofiles/delete.ts b/packages/cli/src/commands/deviceprofiles/delete.ts deleted file mode 100644 index fd4eb701..00000000 --- a/packages/cli/src/commands/deviceprofiles/delete.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { APIOrganizationCommand } from '@smartthings/cli-lib' - -import { chooseDeviceProfile } from '../../lib/commands/deviceprofiles-util.js' - - -export default class DeviceProfileDeleteCommand extends APIOrganizationCommand { - static description = 'delete a device profile' + - this.apiDocsURL('deleteDeviceProfile') - - static flags = APIOrganizationCommand.flags - - static args = [{ - name: 'id', - description: 'Device profile UUID or number in the list', - }] - - static examples = [ - '$ smartthings deviceprofiles:delete 63b8c91e-9686-4c43-9afb-fbd9f77e3bb0 # delete profile with this UUID', - '$ smartthings deviceprofiles:delete 5 # delete the 5th profile in the list', - ] - - async run(): Promise { - const id = await chooseDeviceProfile(this, this.args.id) - await this.client.deviceProfiles.delete(id) - this.log(`Device profile ${id} deleted.`) - } -} diff --git a/src/commands/deviceprofiles/delete.ts b/src/commands/deviceprofiles/delete.ts new file mode 100644 index 00000000..bc4930b4 --- /dev/null +++ b/src/commands/deviceprofiles/delete.ts @@ -0,0 +1,43 @@ +import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs' + +import { apiDocsURL } from '../../lib/command/api-command.js' +import { + apiOrganizationCommand, + apiOrganizationCommandBuilder, + type APIOrganizationCommandFlags, +} from '../../lib/command/api-organization-command.js' +import { chooseDeviceProfile } from '../../lib/command/util/deviceprofiles-choose.js' + + +export type CommandArgs = + & APIOrganizationCommandFlags + & { + id?: string + } + +const command = 'deviceprofiles:delete [id]' + +const describe = 'delete a device profile' + +const builder = (yargs: Argv): Argv => + apiOrganizationCommandBuilder(yargs) + .positional('id', { describe: 'device profile id', type: 'string' }) + .example([ + ['$0 deviceprofiles:delete', 'prompt for a device profile and delete it'], + [ + '$0 deviceprofiles:delete 63b8c91e-9686-4c43-9afb-fbd9f77e3bb0', + 'delete the device profile with the specified id', + ], + ]) + .epilog(apiDocsURL('deleteDeviceProfile')) + +const handler = async (argv: ArgumentsCamelCase): Promise => { + const command = await apiOrganizationCommand(argv) + + const id = await chooseDeviceProfile(command, argv.id) + await command.client.deviceProfiles.delete(id) + console.log(`Device profile ${id} deleted.`) +} + +const cmd: CommandModule = { command, describe, builder, handler } +export default cmd diff --git a/src/commands/index.ts b/src/commands/index.ts index 92791499..501b2683 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -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 deviceprofilesDeleteCommand from './deviceprofiles/delete.js' import deviceprofilesDeviceConfigCommand from './deviceprofiles/device-config.js' import deviceprofilesPresentationCommand from './deviceprofiles/presentation.js' import deviceprofilesPublishCommand from './deviceprofiles/publish.js' @@ -152,6 +153,7 @@ export const commands: CommandModule[] = [ devicepreferencesTranslationsUpdateCommand, deviceprofilesCommand, deviceprofilesCreateCommand, + deviceprofilesDeleteCommand, deviceprofilesDeviceConfigCommand, deviceprofilesPresentationCommand, deviceprofilesPublishCommand,