From cd6ff1ebf5ac419b5217feeddac7503247ff3e36 Mon Sep 17 00:00:00 2001 From: Bauke Date: Wed, 29 Mar 2023 13:41:43 +0200 Subject: [PATCH] Add Cliffy documentation to Deno. --- .bauke/Deno.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.bauke/Deno.md b/.bauke/Deno.md index 2cf40a5..e55ade7 100644 --- a/.bauke/Deno.md +++ b/.bauke/Deno.md @@ -22,6 +22,33 @@ [`simple-git-push`]: ./scripts/simple-git-push.ts [`tauon-controls`]: ./scripts/tauon-controls.ts +## Cliffy + +For CLI creation [Cliffy] is used, a Deno-specific framework for handling input and parsing arguments. + +* A simple command with a `--file ` argument: + +```ts +// Assuming the script location is `$BAUKE_DIR/scripts`. +import { Command } from "./dependencies.ts"; + +const { options } = await new Command() + // CLI information, shown in --help. + .name("example-cli") + .description("Description of the program.") + // Add the --file option with a default value. + .option("-f, --file ", "Example file", { + default: "example.txt" + }) + .parse(Deno.args); + +console.log(options.file); +``` + +* An example of subcommands can be seen in [`bulk`], each command is created like above but added to the main CLI via `.command("name", Command)`. + +[Cliffy]: https://cliffy.io + ## Why `bin/` + `scripts/` Deno has [some issues](https://github.com/denoland/deno/issues/17195) with running files without a file extension (like what you'd want in `bin/`). So instead all the scripts are located in `scripts/` with proper file extensions and the `bin/` files call those scripts using `deno run`.