From 4cbc23ac6b2271a6be015cb50c7eeee4b005c121 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Tue, 28 Nov 2023 17:48:12 +0000 Subject: [PATCH] Create subreddit option --- src/cli.ts | 34 ++++++++++++++++++++++++++++++++-- src/contracts/ICliOptions.ts | 3 +++ yarn.lock | 24 ++++++------------------ 3 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 src/contracts/ICliOptions.ts diff --git a/src/cli.ts b/src/cli.ts index b1311f5..caa74b4 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,9 +1,39 @@ import { Command } from "commander"; +import randomBunny from "./index"; +import ICliOptions from "./contracts/ICliOptions"; + 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 ', 'The subreddit to search', 'rabbits'); -program.parse(); \ No newline at end of file +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") + "\n"); + } else { + const error = response.Error!; + + console.error(error.Message, error.Code); + } + }); \ No newline at end of file diff --git a/src/contracts/ICliOptions.ts b/src/contracts/ICliOptions.ts new file mode 100644 index 0000000..c85971d --- /dev/null +++ b/src/contracts/ICliOptions.ts @@ -0,0 +1,3 @@ +export default interface ICliOptions { + subreddit: string, +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 8621b13..9f9318e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -488,7 +488,7 @@ "@types/node" "*" jest-mock "^29.7.0" -"@jest/expect-utils@^29.5.0", "@jest/expect-utils@^29.7.0": +"@jest/expect-utils@^29.7.0": version "29.7.0" resolved "https://registry.yarnpkg.com/@jest/expect-utils/-/expect-utils-29.7.0.tgz#023efe5d26a8a70f21677d0a1afc0f0a44e3a1c6" integrity sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA== @@ -904,14 +904,7 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA== -"@types/node@*": - version "20.10.0" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.10.0.tgz#16ddf9c0a72b832ec4fcce35b8249cf149214617" - integrity sha512-D0WfRmU9TQ8I9PFx9Yc+EBHw+vSpIub4IDvQivcp26PtPrdMGAq5SDcpXEo/epqa/DXotVpekHiLNTg3iaKXBQ== - dependencies: - undici-types "~5.26.4" - -"@types/node@^20.0.0": +"@types/node@*", "@types/node@^20.0.0": version "20.10.0" resolved "https://registry.yarnpkg.com/@types/node/-/node-20.10.0.tgz#16ddf9c0a72b832ec4fcce35b8249cf149214617" integrity sha512-D0WfRmU9TQ8I9PFx9Yc+EBHw+vSpIub4IDvQivcp26PtPrdMGAq5SDcpXEo/epqa/DXotVpekHiLNTg3iaKXBQ== @@ -3011,7 +3004,7 @@ jest-environment-node@^29.7.0: jest-mock "^29.7.0" jest-util "^29.7.0" -jest-get-type@^29.4.3, jest-get-type@^29.6.3: +jest-get-type@^29.6.3: version "29.6.3" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-29.6.3.tgz#36f499fdcea197c1045a127319c0481723908fd1" integrity sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw== @@ -3043,7 +3036,7 @@ jest-leak-detector@^29.7.0: jest-get-type "^29.6.3" pretty-format "^29.7.0" -jest-matcher-utils@^29.5.0, jest-matcher-utils@^29.7.0: +jest-matcher-utils@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz#ae8fec79ff249fd592ce80e3ee474e83a6c44f12" integrity sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g== @@ -3053,7 +3046,7 @@ jest-matcher-utils@^29.5.0, jest-matcher-utils@^29.7.0: jest-get-type "^29.6.3" pretty-format "^29.7.0" -jest-message-util@^29.5.0, jest-message-util@^29.7.0: +jest-message-util@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-29.7.0.tgz#8bc392e204e95dfe7564abbe72a404e28e51f7f3" integrity sha512-GBEV4GRADeP+qtB2+6u61stea8mGcOT4mCtrYISZwfu9/ISHFJ/5zOMXYbpBE9RsS5+Gb63DW4FgmnKJ79Kf6w== @@ -3198,7 +3191,7 @@ jest-snapshot@^29.7.0: pretty-format "^29.7.0" semver "^7.5.3" -jest-util@^29.0.0, jest-util@^29.5.0, jest-util@^29.7.0: +jest-util@^29.0.0, jest-util@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.7.0.tgz#23c2b62bfb22be82b44de98055802ff3710fc0bc" integrity sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA== @@ -4777,11 +4770,6 @@ undici-types@~5.26.4: resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== -undici-types@~5.26.4: - version "5.26.5" - resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" - integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== - unique-string@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/unique-string/-/unique-string-3.0.0.tgz#84a1c377aff5fd7a8bc6b55d8244b2bd90d75b9a"