Merge pull request #2504 from balena-io/add-device-view-option

Add `--view` flag to `device` command for opening a device's dashboard page
This commit is contained in:
bulldozer-balena[bot] 2022-07-20 12:23:37 +00:00 committed by GitHub
commit 2664f4e7fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -685,6 +685,7 @@ Show information about a single device.
Examples:
$ balena device 7cf02a6
$ balena device 7cf02a6 --view
### Arguments
@ -694,6 +695,10 @@ the device uuid
### Options
#### --view
open device dashboard page
## device deactivate <uuid>
Deactivate a device.

View File

@ -44,6 +44,7 @@ interface ExtendedDevice extends DeviceWithDeviceType {
interface FlagsDef {
help: void;
view: boolean;
}
interface ArgsDef {
@ -56,7 +57,10 @@ export default class DeviceCmd extends Command {
Show information about a single device.
`;
public static examples = ['$ balena device 7cf02a6'];
public static examples = [
'$ balena device 7cf02a6',
'$ balena device 7cf02a6 --view',
];
public static args: Array<IArg<any>> = [
{
@ -71,13 +75,19 @@ export default class DeviceCmd extends Command {
public static flags: flags.Input<FlagsDef> = {
help: cf.help,
view: flags.boolean({
default: false,
description: 'open device dashboard page',
}),
};
public static authenticated = true;
public static primary = true;
public async run() {
const { args: params } = this.parse<FlagsDef, ArgsDef>(DeviceCmd);
const { args: params, flags: options } = this.parse<FlagsDef, ArgsDef>(
DeviceCmd,
);
const balena = getBalenaSdk();
@ -108,6 +118,14 @@ export default class DeviceCmd extends Command {
],
...expandForAppName,
})) as ExtendedDevice;
if (options.view) {
const open = await import('open');
const dashboardUrl = balena.models.device.getDashboardUrl(device.uuid);
await open(dashboardUrl, { wait: false });
return;
}
device.status = device.overall_status;
device.dashboard_url = balena.models.device.getDashboardUrl(device.uuid);