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
40 changes: 0 additions & 40 deletions packages/cli/src/commands/devices/rename.ts

This file was deleted.

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

import { stringInput } from '../../lib/user-query.js'
import { apiCommand, apiCommandBuilder, type APICommandFlags, apiDocsURL } from '../../lib/command/api-command.js'
import { outputItem, outputItemBuilder, type OutputItemFlags } from '../../lib/command/output-item.js'
import { chooseDevice } from '../../lib/command/util/devices-choose.js'
import { buildTableOutput } from '../../lib/command/util/devices-table.js'


export type CommandArgs =
& APICommandFlags
& OutputItemFlags
& {
id?: string
newLabel?: string
}

const command = 'devices:rename [id] [new-label]'

const describe = 'rename a device'

const builder = (yargs: Argv): Argv<CommandArgs> =>
outputItemBuilder(apiCommandBuilder(yargs))
.positional('id', { describe: 'device id', type: 'string' })
.positional('new-label', { describe: 'new device label', type: 'string' })
.example([
['$0 devices:rename', 'prompt for a device and a new label and rename the chosen device'],
[
'$0 devices:rename f22bb71f-b6a0-43de-9131-20e7dfc0f973 "New Name"',
'rename the specified device with the specified name',
],
])
.epilog(apiDocsURL('updateDevice'))

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

const id = await chooseDevice(command, argv.id)

const label = argv.newLabel ?? await stringInput('Enter new device label:')

await outputItem(
command,
{ buildTableOutput: data => buildTableOutput(command.tableGenerator, data) },
() => command.client.devices.update(id, { label }),
)
}

const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
export default cmd
6 changes: 4 additions & 2 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ import devicesCommand from './devices.js'
import devicesCapabilityStatusCommand from './devices/capability-status.js'
import devicesComponentStatusCommand from './devices/component-status.js'
import devicesCommandsCommand from './devices/commands.js'
import devicesStatusCommand from './devices/status.js'
import devicesDeleteCommand from './devices/delete.js'
import devicesHealthCommand from './devices/health.js'
import devicesHistoryCommand from './devices/history.js'
import devicesPreferencesCommand from './devices/preferences.js'
import devicesPresentationCommand from './devices/presentation.js'
import devicesRenameCommand from './devices/rename.js'
import devicesStatusCommand from './devices/status.js'
import devicesUpdateCommand from './devices/update.js'
import edgeChannelsCommand from './edge/channels.js'
import edgeChannelsCreateCommand from './edge/channels/create.js'
Expand Down Expand Up @@ -167,12 +168,13 @@ export const commands: CommandModule<object, any>[] = [
devicesCapabilityStatusCommand,
devicesComponentStatusCommand,
devicesCommandsCommand,
devicesStatusCommand,
devicesDeleteCommand,
devicesHealthCommand,
devicesHistoryCommand,
devicesPreferencesCommand,
devicesPresentationCommand,
devicesRenameCommand,
devicesStatusCommand,
devicesUpdateCommand,
edgeChannelsCommand,
edgeChannelsCreateCommand,
Expand Down