Add sort option
This commit is contained in:
parent
91f974be9d
commit
c26d56c149
2 changed files with 5 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { Command } from "commander";
|
import { Command, Option } from "commander";
|
||||||
import randomBunny from "./index";
|
import randomBunny from "./index";
|
||||||
import ICliOptions from "./contracts/ICliOptions";
|
import ICliOptions from "./contracts/ICliOptions";
|
||||||
import { exit } from "process";
|
import { exit } from "process";
|
||||||
|
@ -9,13 +9,14 @@ 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')
|
||||||
|
.addOption(new Option('--sort <sort>', 'Sort by').default('hot').choices(['hot', 'new', 'top']));
|
||||||
|
|
||||||
program.parse();
|
program.parse();
|
||||||
|
|
||||||
const options: ICliOptions = program.opts();
|
const options: ICliOptions = program.opts();
|
||||||
|
|
||||||
randomBunny(options.subreddit)
|
randomBunny(options.subreddit, options.sort)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.IsSuccess) {
|
if (response.IsSuccess) {
|
||||||
const result = response.Result!;
|
const result = response.Result!;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
export default interface ICliOptions {
|
export default interface ICliOptions {
|
||||||
subreddit: string,
|
subreddit: string,
|
||||||
|
sort: string,
|
||||||
}
|
}
|
Loading…
Reference in a new issue