mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-05-02 17:13:05 +00:00
Merge pull request #2056 from balena-io/scan-json
scan: Add '--json' option to help with scripting
This commit is contained in:
commit
63d3402924
@ -1493,6 +1493,10 @@ display full info
|
|||||||
|
|
||||||
scan timeout in seconds
|
scan timeout in seconds
|
||||||
|
|
||||||
|
#### -j, --json
|
||||||
|
|
||||||
|
produce JSON output instead of tabular output
|
||||||
|
|
||||||
## ssh <applicationOrDevice> [service]
|
## ssh <applicationOrDevice> [service]
|
||||||
|
|
||||||
Start a shell on a local or remote device. If a service name is not provided,
|
Start a shell on a local or remote device. If a service name is not provided,
|
||||||
|
@ -22,6 +22,7 @@ import * as cf from '../utils/common-flags';
|
|||||||
import { getVisuals, stripIndent } from '../utils/lazy';
|
import { getVisuals, stripIndent } from '../utils/lazy';
|
||||||
|
|
||||||
interface FlagsDef {
|
interface FlagsDef {
|
||||||
|
json?: boolean;
|
||||||
verbose: boolean;
|
verbose: boolean;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
help: void;
|
help: void;
|
||||||
@ -53,6 +54,10 @@ export default class ScanCmd extends Command {
|
|||||||
description: 'scan timeout in seconds',
|
description: 'scan timeout in seconds',
|
||||||
}),
|
}),
|
||||||
help: cf.help,
|
help: cf.help,
|
||||||
|
json: flags.boolean({
|
||||||
|
char: 'j',
|
||||||
|
description: 'produce JSON output instead of tabular output',
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
public static primary = true;
|
public static primary = true;
|
||||||
@ -78,7 +83,7 @@ export default class ScanCmd extends Command {
|
|||||||
const activeLocalDevices: LocalBalenaOsDevice[] = await new SpinnerPromise({
|
const activeLocalDevices: LocalBalenaOsDevice[] = await new SpinnerPromise({
|
||||||
promise: discover.discoverLocalBalenaOsDevices(discoverTimeout),
|
promise: discover.discoverLocalBalenaOsDevices(discoverTimeout),
|
||||||
startMessage: 'Scanning for local balenaOS devices..',
|
startMessage: 'Scanning for local balenaOS devices..',
|
||||||
stopMessage: 'Reporting scan results',
|
stopMessage: options.json ? '' : 'Reporting scan results',
|
||||||
}).filter(async ({ address }: { address: string }) => {
|
}).filter(async ({ address }: { address: string }) => {
|
||||||
const docker = dockerUtils.createClient({
|
const docker = dockerUtils.createClient({
|
||||||
host: address,
|
host: address,
|
||||||
@ -137,7 +142,11 @@ export default class ScanCmd extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Output results
|
// Output results
|
||||||
console.log(prettyjson.render(devicesInfo, { noColor: true }));
|
console.log(
|
||||||
|
options.json
|
||||||
|
? JSON.stringify(devicesInfo, null, 4)
|
||||||
|
: prettyjson.render(devicesInfo, { noColor: true }),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static dockerInfoProperties = [
|
protected static dockerInfoProperties = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user