mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-06 19:19:56 +00:00
device rm: Add ability to remove multiple devices in one command
Change-type: minor
This commit is contained in:
parent
0eb4e6d770
commit
47e9d39c6f
@ -174,7 +174,7 @@ Users are encouraged to regularly update the balena CLI to the latest version.
|
|||||||
- [device reboot <uuid>](#device-reboot-uuid)
|
- [device reboot <uuid>](#device-reboot-uuid)
|
||||||
- [device register <application>](#device-register-application)
|
- [device register <application>](#device-register-application)
|
||||||
- [device rename <uuid> [newname]](#device-rename-uuid-newname)
|
- [device rename <uuid> [newname]](#device-rename-uuid-newname)
|
||||||
- [device rm <uuid>](#device-rm-uuid)
|
- [device rm <uuid(s)>](#device-rm-uuid-s)
|
||||||
- [device shutdown <uuid>](#device-shutdown-uuid)
|
- [device shutdown <uuid>](#device-shutdown-uuid)
|
||||||
- [devices](#devices)
|
- [devices](#devices)
|
||||||
- [devices supported](#devices-supported)
|
- [devices supported](#devices-supported)
|
||||||
@ -638,9 +638,9 @@ the new name for the device
|
|||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
## device rm <uuid>
|
## device rm <uuid(s)>
|
||||||
|
|
||||||
Remove a device from balena.
|
Remove one or more devices from balena.
|
||||||
|
|
||||||
Note this command asks for confirmation interactively.
|
Note this command asks for confirmation interactively.
|
||||||
You can avoid this by passing the `--yes` option.
|
You can avoid this by passing the `--yes` option.
|
||||||
@ -648,13 +648,14 @@ You can avoid this by passing the `--yes` option.
|
|||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
$ balena device rm 7cf02a6
|
$ balena device rm 7cf02a6
|
||||||
|
$ balena device rm 7cf02a6,dc39e52
|
||||||
$ balena device rm 7cf02a6 --yes
|
$ balena device rm 7cf02a6 --yes
|
||||||
|
|
||||||
### Arguments
|
### Arguments
|
||||||
|
|
||||||
#### UUID
|
#### UUID
|
||||||
|
|
||||||
the uuid of the device to remove
|
comma-separated list (no blank spaces) of device UUIDs to be removed
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
|
@ -33,28 +33,30 @@ interface ArgsDef {
|
|||||||
|
|
||||||
export default class DeviceRmCmd extends Command {
|
export default class DeviceRmCmd extends Command {
|
||||||
public static description = stripIndent`
|
public static description = stripIndent`
|
||||||
Remove a device.
|
Remove one or more devices.
|
||||||
|
|
||||||
Remove a device from balena.
|
Remove one or more devices from balena.
|
||||||
|
|
||||||
Note this command asks for confirmation interactively.
|
Note this command asks for confirmation interactively.
|
||||||
You can avoid this by passing the \`--yes\` option.
|
You can avoid this by passing the \`--yes\` option.
|
||||||
`;
|
`;
|
||||||
public static examples = [
|
public static examples = [
|
||||||
'$ balena device rm 7cf02a6',
|
'$ balena device rm 7cf02a6',
|
||||||
|
'$ balena device rm 7cf02a6,dc39e52',
|
||||||
'$ balena device rm 7cf02a6 --yes',
|
'$ balena device rm 7cf02a6 --yes',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static args: Array<IArg<any>> = [
|
public static args: Array<IArg<any>> = [
|
||||||
{
|
{
|
||||||
name: 'uuid',
|
name: 'uuid',
|
||||||
description: 'the uuid of the device to remove',
|
description:
|
||||||
|
'comma-separated list (no blank spaces) of device UUIDs to be removed',
|
||||||
parse: (dev) => tryAsInteger(dev),
|
parse: (dev) => tryAsInteger(dev),
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
public static usage = 'device rm <uuid>';
|
public static usage = 'device rm <uuid(s)>';
|
||||||
|
|
||||||
public static flags: flags.Input<FlagsDef> = {
|
public static flags: flags.Input<FlagsDef> = {
|
||||||
yes: cf.yes,
|
yes: cf.yes,
|
||||||
@ -72,12 +74,23 @@ export default class DeviceRmCmd extends Command {
|
|||||||
const patterns = await import('../../utils/patterns');
|
const patterns = await import('../../utils/patterns');
|
||||||
|
|
||||||
// Confirm
|
// Confirm
|
||||||
|
const uuids = params.uuid.split(',');
|
||||||
await patterns.confirm(
|
await patterns.confirm(
|
||||||
options.yes,
|
options.yes,
|
||||||
'Are you sure you want to delete the device?',
|
uuids.length > 1
|
||||||
|
? `Are you sure you want to delete ${uuids.length} devices?`
|
||||||
|
: `Are you sure you want to delete device ${uuids[0]} ?`,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove
|
// Remove
|
||||||
await balena.models.device.remove(params.uuid);
|
for (const uuid of params.uuid.split(',')) {
|
||||||
|
try {
|
||||||
|
await balena.models.device.remove(uuid);
|
||||||
|
} catch (err) {
|
||||||
|
console.info(`${err.message}, uuid: ${uuid}`);
|
||||||
|
process.exitCode = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ Additional commands:
|
|||||||
device reboot <uuid> restart a device
|
device reboot <uuid> restart a device
|
||||||
device register <application> register a device
|
device register <application> register a device
|
||||||
device rename <uuid> [newname] rename a device
|
device rename <uuid> [newname] rename a device
|
||||||
device rm <uuid> remove a device
|
device rm <uuid(s)> remove one or more devices
|
||||||
device shutdown <uuid> shutdown a device
|
device shutdown <uuid> shutdown a device
|
||||||
devices supported list the supported device types (like 'raspberrypi3' or 'intel-nuc')
|
devices supported list the supported device types (like 'raspberrypi3' or 'intel-nuc')
|
||||||
env add <name> [value] add an environment or config variable to an application, device or service
|
env add <name> [value] add an environment or config variable to an application, device or service
|
||||||
|
Loading…
x
Reference in New Issue
Block a user