From e4870916e233e1540bc4b25d5bde13b8e4e3bed7 Mon Sep 17 00:00:00 2001 From: Paulo Castro Date: Wed, 24 Nov 2021 22:59:31 +0000 Subject: [PATCH] config read: Add '--json' option for JSON output Change-type: minor --- doc/cli.markdown | 4 ++++ lib/commands/config/read.ts | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/cli.markdown b/doc/cli.markdown index 8ace6915..395c324a 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -2655,6 +2655,10 @@ device type (Check available types with `balena devices supported`) path to OS image file (e.g. balena.img) or block device (e.g. /dev/disk2) +#### -j, --json + +produce JSON output instead of tabular output + ## config reconfigure Interactively reconfigure a provisioned device or OS image. diff --git a/lib/commands/config/read.ts b/lib/commands/config/read.ts index 79cf0670..99d3b3f6 100644 --- a/lib/commands/config/read.ts +++ b/lib/commands/config/read.ts @@ -24,6 +24,7 @@ interface FlagsDef { type: string; drive?: string; help: void; + json: boolean; } export default class ConfigReadCmd extends Command { @@ -45,6 +46,7 @@ export default class ConfigReadCmd extends Command { type: cf.deviceType, drive: cf.driveOrImg, help: cf.help, + json: cf.json, }; public static authenticated = true; @@ -63,7 +65,11 @@ export default class ConfigReadCmd extends Command { const config = await import('balena-config-json'); const configJSON = await config.read(drive, options.type); - const prettyjson = await import('prettyjson'); - console.info(prettyjson.render(configJSON)); + if (options.json) { + console.log(JSON.stringify(configJSON, null, 4)); + } else { + const prettyjson = await import('prettyjson'); + console.log(prettyjson.render(configJSON)); + } } }