diff --git a/doc/cli.markdown b/doc/cli.markdown index d6404dd6..f572925a 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -1493,6 +1493,10 @@ display full info scan timeout in seconds +#### -j, --json + +produce JSON output instead of tabular output + ## ssh <applicationOrDevice> [service] Start a shell on a local or remote device. If a service name is not provided, diff --git a/lib/commands/scan.ts b/lib/commands/scan.ts index 03be5c6b..f4cdf94a 100644 --- a/lib/commands/scan.ts +++ b/lib/commands/scan.ts @@ -22,6 +22,7 @@ import * as cf from '../utils/common-flags'; import { getVisuals, stripIndent } from '../utils/lazy'; interface FlagsDef { + json?: boolean; verbose: boolean; timeout?: number; help: void; @@ -53,6 +54,10 @@ export default class ScanCmd extends Command { description: 'scan timeout in seconds', }), help: cf.help, + json: flags.boolean({ + char: 'j', + description: 'produce JSON output instead of tabular output', + }), }; public static primary = true; @@ -78,7 +83,7 @@ export default class ScanCmd extends Command { const activeLocalDevices: LocalBalenaOsDevice[] = await new SpinnerPromise({ promise: discover.discoverLocalBalenaOsDevices(discoverTimeout), startMessage: 'Scanning for local balenaOS devices..', - stopMessage: 'Reporting scan results', + stopMessage: options.json ? '' : 'Reporting scan results', }).filter(async ({ address }: { address: string }) => { const docker = dockerUtils.createClient({ host: address, @@ -137,7 +142,11 @@ export default class ScanCmd extends Command { } // 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 = [