Compare commits
2 commits
91f974be9d
...
b2722b487e
Author | SHA1 | Date | |
---|---|---|---|
b2722b487e | |||
38054d3812 |
3 changed files with 28 additions and 2 deletions
|
@ -9,7 +9,8 @@ program
|
||||||
.name('random-bunny')
|
.name('random-bunny')
|
||||||
.description('Get a random image url from a subreddit of your choosing')
|
.description('Get a random image url from a subreddit of your choosing')
|
||||||
.version('2.2')
|
.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();
|
program.parse();
|
||||||
|
|
||||||
|
@ -21,6 +22,12 @@ randomBunny(options.subreddit)
|
||||||
const result = response.Result!;
|
const result = response.Result!;
|
||||||
|
|
||||||
const outputLines: string[] = [];
|
const outputLines: string[] = [];
|
||||||
|
|
||||||
|
if (options.json) {
|
||||||
|
console.log(JSON.stringify(result));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
outputLines.push(`Archived = ${result.Archived}`);
|
outputLines.push(`Archived = ${result.Archived}`);
|
||||||
outputLines.push(`Downvotes = ${result.Downs}`);
|
outputLines.push(`Downvotes = ${result.Downs}`);
|
||||||
outputLines.push(`Hidden = ${result.Hidden}`);
|
outputLines.push(`Hidden = ${result.Hidden}`);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
export default interface ICliOptions {
|
export default interface ICliOptions {
|
||||||
subreddit: string,
|
subreddit: string,
|
||||||
|
json?: boolean,
|
||||||
}
|
}
|
|
@ -88,7 +88,25 @@ describe('subreddit', () => {
|
||||||
|
|
||||||
expect(subreddit).toBe('Horses');
|
expect(subreddit).toBe('Horses');
|
||||||
}, 5000);
|
}, 5000);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
describe('json', () => {
|
||||||
|
test('GIVEN -j is supplied, EXPECT output to be valid JSON', async () => {
|
||||||
|
const result = await cli(['-j'], '.');
|
||||||
|
|
||||||
|
const json = JSON.parse(result.stdout);
|
||||||
|
|
||||||
|
expect(json).toBeDefined();
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
test('GIVEN --json is supplied, EXPECT output to be valid JSON', async () => {
|
||||||
|
const result = await cli(['--json'], '.');
|
||||||
|
|
||||||
|
const json = JSON.parse(result.stdout);
|
||||||
|
|
||||||
|
expect(json).toBeDefined();
|
||||||
|
}, 5000);
|
||||||
|
});
|
||||||
|
|
||||||
function cli(args: string[], cwd: string): Promise<cliResult> {
|
function cli(args: string[], cwd: string): Promise<cliResult> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
|
Loading…
Reference in a new issue