From a2c0c01b058a588882d9608414230a5842bf177c Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Tue, 20 Feb 2024 18:01:24 +0000 Subject: [PATCH] Add documentation on the cli --- docs/cli.md | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 6 ++++ 2 files changed, 90 insertions(+) create mode 100644 docs/cli.md diff --git a/docs/cli.md b/docs/cli.md new file mode 100644 index 0000000..893fcd5 --- /dev/null +++ b/docs/cli.md @@ -0,0 +1,84 @@ +# CLI + +Since Version 2.2, Random Bunny contains a command line interface (CLI). + +## Default Output + +By default, the command will fetch a random image from `r/rabbits` and return it in a human-readable output. + +``` +$ randombunny + +Archived = false +Downvotes = 0 +Hidden = false +Permalink = /r/Rabbits/comments/1av1rg9/cute_baby_bun/ +Subreddit = Rabbits +Subreddit Subscribers = 486084 +Title = Cute baby bun +Upvotes = 211 +Url = https://i.redd.it/sfz0srdrimjc1.png +``` + +## Help + +The command also includes a help option in case you are stuck. + +``` +$ randombunny --help + +# or + +$ randombunny -h + +Usage: random-bunny [options] + +Get a random image url from a subreddit of your choosing + +Options: + -V, --version output the version number + -s, --subreddit The subreddit to search (default: "rabbits") + -j, --json Output as JSON + -q, --query-metadata Include query metadata in result + --sort Sort by (choices: "hot", "new", "top", default: "hot") + -h, --help display help for command +✨ Done in 0.32s. +``` + +## JSON output + +You can also convert the output into JSON, if you need to input it to another program. + +```bash +$ randombunny --json + +# or + +$ randonbunny -j + +{"Archived":false,"Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1av1rg9/cute_baby_bun/","Subreddit":"Rabbits","SubredditSubscribers":486085,"Title":"Cute baby bun","Ups":210,"Url":"https://i.redd.it/sfz0srdrimjc1.png"} +``` + +## Sort + +You can also choose the sorting option which reddit will use to return the available posts to randomise from. + +This defaults to "hot". The valid options are "hot", "new", and "top". + +``` +$ randombunny --sort hot +$ randombunny --sort new +$ randomBunny --sort top +``` + + +## Subreddit + +You can change the subreddit which the command fetches from. + +This defaults to "rabbits" + +``` +$ randombunny --subreddit rabbits +$ randombunny -s horses +``` diff --git a/readme.md b/readme.md index 4403cd6..33d47ad 100644 --- a/readme.md +++ b/readme.md @@ -44,6 +44,12 @@ The json string which gets returned consists of: `sortBy` will default to 'hot' if not given or invalid +## CLI + +Random bunny can also be used as a CLI. This is accessible via the executable (see git releases) or via `src/cli.ts` + +For more details, see the documentation. + ## Notes * Node 4 or newer. -- 2.43.4