Skip to content

Commit

Permalink
Merge pull request balena-io#2496 from balena-io/add-fleet-view-command
Browse files Browse the repository at this point in the history
Add `--view` flag to `fleet` command for opening a fleet's dashboard page
  • Loading branch information
bulldozer-balena[bot] committed Jul 7, 2022
2 parents f55dd81 + 566b7f9 commit be7c0dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/balena-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ Examples:

$ balena fleet MyFleet
$ balena fleet myorg/myfleet
$ balena fleet myorg/myfleet --view

### Arguments

Expand All @@ -362,6 +363,10 @@ fleet name, slug (preferred), or numeric ID (deprecated)

### Options

#### --view

open fleet dashboard page

## fleet create <name>

Create a new balena fleet.
Expand Down
24 changes: 21 additions & 3 deletions lib/commands/fleet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* limitations under the License.
*/

import type { flags } from '@oclif/command';
import type { flags as flagsType } from '@oclif/command';
import { flags } from '@oclif/command';
import type { Release } from 'balena-sdk';

import Command from '../../command';
Expand All @@ -28,6 +29,7 @@ import type { DataOutputOptions } from '../../framework';

interface FlagsDef extends DataOutputOptions {
help: void;
view: boolean;
}

interface ArgsDef {
Expand All @@ -45,14 +47,19 @@ export default class FleetCmd extends Command {
public static examples = [
'$ balena fleet MyFleet',
'$ balena fleet myorg/myfleet',
'$ balena fleet myorg/myfleet --view',
];

public static args = [ca.fleetRequired];

public static usage = 'fleet <fleet>';

public static flags: flags.Input<FlagsDef> = {
public static flags: flagsType.Input<FlagsDef> = {
help: cf.help,
view: flags.boolean({
default: false,
description: 'open fleet dashboard page',
}),
...(isV14() ? cf.dataOutputFlags : {}),
};

Expand All @@ -66,7 +73,9 @@ export default class FleetCmd extends Command {

const { getApplication } = await import('../../utils/sdk');

const application = (await getApplication(getBalenaSdk(), params.fleet, {
const balena = getBalenaSdk();

const application = (await getApplication(balena, params.fleet, {
$expand: {
is_for__device_type: { $select: 'slug' },
should_be_running__release: { $select: 'commit' },
Expand All @@ -78,6 +87,15 @@ export default class FleetCmd extends Command {
commit?: string;
};

if (options.view) {
const open = await import('open');
const dashboardUrl = balena.models.application.getDashboardUrl(
application.id,
);
await open(dashboardUrl, { wait: false });
return;
}

application.device_type = application.is_for__device_type[0].slug;
application.commit = application.should_be_running__release[0]?.commit;

Expand Down

0 comments on commit be7c0dc

Please sign in to comment.