From 4de8373e0b3c1b95032368a2896d1f4da9155ba1 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Thu, 17 Mar 2022 14:59:16 +0000 Subject: [PATCH] Add JSON output for pctl devices --- README.md | 4 ++++ src/cli/pctl/devices.ts | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index ce32a93..8bb957a 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,10 @@ nxapi pctl user ```sh # Show Nintendo Switch consoles in a table nxapi pctl devices + +# JSON +nxapi pctl devices --json +nxapi pctl devices --json-pretty-print ``` #### Daily summaries diff --git a/src/cli/pctl/devices.ts b/src/cli/pctl/devices.ts index 4602835..5619d32 100644 --- a/src/cli/pctl/devices.ts +++ b/src/cli/pctl/devices.ts @@ -16,6 +16,12 @@ export function builder(yargs: Argv) { }).option('token', { describe: 'Nintendo Account session token', type: 'string', + }).option('json', { + describe: 'Output raw JSON', + type: 'boolean', + }).option('json-pretty-print', { + describe: 'Output pretty-printed JSON', + type: 'boolean', }); } @@ -33,6 +39,15 @@ export async function handler(argv: ArgumentsCamelCase) { const devices = await moon.getDevices(); + if (argv.jsonPrettyPrint) { + console.log(JSON.stringify(devices, null, 4)); + return; + } + if (argv.json) { + console.log(JSON.stringify(devices)); + return; + } + const table = new Table({ head: [ 'ID',