Add sort option

This commit is contained in:
Ethan Lane 2023-12-05 17:22:30 +00:00
parent 91f974be9d
commit c26d56c149
2 changed files with 5 additions and 3 deletions

View file

@ -1,4 +1,4 @@
import { Command } from "commander";
import { Command, Option } from "commander";
import randomBunny from "./index";
import ICliOptions from "./contracts/ICliOptions";
import { exit } from "process";
@ -9,13 +9,14 @@ 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')
.addOption(new Option('--sort <sort>', 'Sort by').default('hot').choices(['hot', 'new', 'top']));
program.parse();
const options: ICliOptions = program.opts();
randomBunny(options.subreddit)
randomBunny(options.subreddit, options.sort)
.then((response) => {
if (response.IsSuccess) {
const result = response.Result!;

View file

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