Add sort option #123

Merged
VylpesTester merged 2 commits from feature/74-cli-sort into develop 2023-12-08 17:10:01 +00:00
2 changed files with 5 additions and 3 deletions
Showing only changes of commit c26d56c149 - Show all commits

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,
}