Skip to content

Commit

Permalink
Add JSON output for pctl devices
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelthomas2774 committed Mar 17, 2022
1 parent 006910d commit 4de8373
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/cli/pctl/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export function builder(yargs: Argv<ParentArguments>) {
}).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',
});
}

Expand All @@ -33,6 +39,15 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {

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',
Expand Down

0 comments on commit 4de8373

Please sign in to comment.