From 1fe0480a8a95d9d62492a0552cea7131fa520da1 Mon Sep 17 00:00:00 2001 From: Matthew Yarmolinsky Date: Thu, 14 Jul 2022 18:56:51 +0000 Subject: [PATCH] Add `--view` flag to `device` command for opening a device's dashboard page Change-type: minor Signed-off-by: Matthew Yarmolinsky --- docs/balena-cli.md | 5 +++++ lib/commands/device/index.ts | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/balena-cli.md b/docs/balena-cli.md index ebc6e880..a796377a 100644 --- a/docs/balena-cli.md +++ b/docs/balena-cli.md @@ -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. diff --git a/lib/commands/device/index.ts b/lib/commands/device/index.ts index b83abbfa..0dcb2f34 100644 --- a/lib/commands/device/index.ts +++ b/lib/commands/device/index.ts @@ -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> = [ { @@ -71,13 +75,19 @@ export default class DeviceCmd extends Command { public static flags: flags.Input = { 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(DeviceCmd); + const { args: params, flags: options } = this.parse( + 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);