-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. - Add `-s` and `--subreddit` CLI options to change the subreddit - Defaults to "rabbits" #75 ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) - [x] This change requires a documentation update # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. # Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that provde my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/random-bunny/pulls/118 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
- Loading branch information
Showing
4 changed files
with
101 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
import { Command } from "commander"; | ||
import randomBunny from "./index"; | ||
import ICliOptions from "./contracts/ICliOptions"; | ||
import { exit } from "process"; | ||
|
||
const program = new Command(); | ||
|
||
program | ||
.name('random-bunny') | ||
.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'); | ||
|
||
program.parse(); | ||
|
||
const options: ICliOptions = program.opts(); | ||
|
||
randomBunny(options.subreddit) | ||
.then((response) => { | ||
if (response.IsSuccess) { | ||
const result = response.Result!; | ||
|
||
const outputLines: string[] = []; | ||
outputLines.push(`Archived = ${result.Archived}`); | ||
outputLines.push(`Downvotes = ${result.Downs}`); | ||
outputLines.push(`Hidden = ${result.Hidden}`); | ||
outputLines.push(`Permalink = ${result.Permalink}`); | ||
outputLines.push(`Subreddit = ${result.Subreddit}`); | ||
outputLines.push(`Subreddit Subscribers = ${result.SubredditSubscribers}`); | ||
outputLines.push(`Title = ${result.Title}`); | ||
outputLines.push(`Upvotes = ${result.Ups}`); | ||
outputLines.push(`Url = ${result.Url}`); | ||
|
||
console.log(outputLines.join("\n")); | ||
exit(0); | ||
} else { | ||
const error = response.Error!; | ||
|
||
program.parse(); | ||
console.error(error.Message, error.Code); | ||
exit(1); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default interface ICliOptions { | ||
subreddit: string, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters