Add ability to output the CLI in JSON format #124

Merged
Vylpes merged 4 commits from feature/73-cli-json into develop 2024-01-19 18:02:16 +00:00
2 changed files with 9 additions and 1 deletions
Showing only changes of commit 38054d3812 - Show all commits

View file

@ -9,7 +9,8 @@ program
.name('random-bunny')
.description('Get a random image url from a subreddit of your choosing')
.version('2.2')
.option('-s, --subreddit <subreddit>', 'The subreddit to search', 'rabbits');
.option('-s, --subreddit <subreddit>', 'The subreddit to search', 'rabbits')
.option('-j, --json', 'Output as JSON');
program.parse();
@ -21,6 +22,12 @@ randomBunny(options.subreddit)
const result = response.Result!;
const outputLines: string[] = [];
if (options.json) {
console.log(JSON.stringify(result));
return;
}
outputLines.push(`Archived = ${result.Archived}`);
outputLines.push(`Downvotes = ${result.Downs}`);
outputLines.push(`Hidden = ${result.Hidden}`);

View file

@ -1,3 +1,4 @@
export default interface ICliOptions {
subreddit: string,
json?: boolean,
}