From 7f49183c5e8e1f853fd99dfbab73df5fa31c2e1f Mon Sep 17 00:00:00 2001 From: Ross Stenersen Date: Wed, 25 Jun 2025 14:32:55 -0500 Subject: [PATCH] refactor: convert edge:channels:update command to yargs --- .../edge/src/commands/edge/channels/update.ts | 29 ---------- src/commands/edge/channels/update.ts | 57 +++++++++++++++++++ src/commands/index.ts | 2 + 3 files changed, 59 insertions(+), 29 deletions(-) delete mode 100644 packages/edge/src/commands/edge/channels/update.ts create mode 100644 src/commands/edge/channels/update.ts diff --git a/packages/edge/src/commands/edge/channels/update.ts b/packages/edge/src/commands/edge/channels/update.ts deleted file mode 100644 index db33b2ec..00000000 --- a/packages/edge/src/commands/edge/channels/update.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { inputAndOutputItem } from '@smartthings/cli-lib' - -import { Channel, ChannelUpdate } from '@smartthings/core-sdk' - -import { chooseChannel, tableFieldDefinitions } from '../../../lib/commands/channels-util.js' -import { EdgeCommand } from '../../../lib/edge-command.js' - - -export default class ChannelsUpdateCommand extends EdgeCommand { - static description = 'update a channel' + - this.apiDocsURL('updateChannel') - - static flags = { - ...EdgeCommand.flags, - ...inputAndOutputItem.flags, - } - - static args = [{ - name: 'id', - description: 'the channel id', - }] - - async run(): Promise { - const id = await chooseChannel(this, 'Choose a channel to patch.', this.args.id, - { useConfigDefault: true }) - await inputAndOutputItem(this, { tableFieldDefinitions }, - (_, channelMods) => this.client.channels.update(id, channelMods)) - } -} diff --git a/src/commands/edge/channels/update.ts b/src/commands/edge/channels/update.ts new file mode 100644 index 00000000..03509e87 --- /dev/null +++ b/src/commands/edge/channels/update.ts @@ -0,0 +1,57 @@ +import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs' + +import { type Channel, type ChannelUpdate } from '@smartthings/core-sdk' + +import { apiCommand, apiCommandBuilder, type APICommandFlags, apiDocsURL } from '../../../lib/command/api-command.js' +import { + inputAndOutputItem, + inputAndOutputItemBuilder, + type InputAndOutputItemFlags, +} from '../../../lib/command/input-and-output-item.js' +import { chooseChannel } from '../../../lib/command/util/edge/channels-choose.js' +import { tableFieldDefinitions } from '../../../lib/command/util/edge/channels-table.js' + + +export type CommandArgs = + & APICommandFlags + & InputAndOutputItemFlags + & { + id?: string + } + +const command = 'edge:channels:update [id]' + +const describe = 'update a channel' + +const builder = (yargs: Argv): Argv => + inputAndOutputItemBuilder(apiCommandBuilder(yargs)) + .positional('id', { describe: 'id of channel to update', type: 'string' }) + .example([ + [ + '$0 edge:channels:update --input channel.yaml', + 'prompt for a channel and update it using the data in channel.yaml', + ], + [ + '$0 edge:channels:update 0068b912-50fb-439d-a14a-27cc90ca81dc --input channel.json', + 'update the specified channel using the data in channel.json', + ], + ]) + .epilog(apiDocsURL('updateChannel')) + +const handler = async (argv: ArgumentsCamelCase): Promise => { + const command = await apiCommand(argv) + + const id = await chooseChannel( + command, + argv.id, + { promptMessage: 'Choose a channel to update.', useConfigDefault: true }, + ) + await inputAndOutputItem( + command, + { tableFieldDefinitions }, + (_, channelMods) => command.client.channels.update(id, channelMods), + ) +} + +const cmd: CommandModule = { command, describe, builder, handler } +export default cmd diff --git a/src/commands/index.ts b/src/commands/index.ts index b50623b6..f0f33fb2 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -70,6 +70,7 @@ import edgeChannelsInvitesDeleteCommand from './edge/channels/invites/delete.js' import edgeChannelsMetaInfoCommand from './edge/channels/metainfo.js' import edgeChannelsUnassignCommand from './edge/channels/unassign.js' import edgeChannelsUnenrollCommand from './edge/channels/unenroll.js' +import edgeChannelsUpdateCommand from './edge/channels/update.js' import edgeDriversCommand from './edge/drivers.js' import edgeDriversDefaultCommand from './edge/drivers/default.js' import edgeDriversDeleteCommand from './edge/drivers/delete.js' @@ -203,6 +204,7 @@ export const commands: CommandModule[] = [ edgeChannelsMetaInfoCommand, edgeChannelsUnassignCommand, edgeChannelsUnenrollCommand, + edgeChannelsUpdateCommand, edgeDriversCommand, edgeDriversDefaultCommand, edgeDriversDeleteCommand,