1
Fork 0
dotfiles/.bauke/Deno.md

2.2 KiB

Deno Scripts

Scripts

Cliffy

For CLI creation Cliffy is used, a Deno-specific framework for handling input and parsing arguments.

  • A simple command with a --file <file> argument:
// 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 <file: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).

Why bin/ + scripts/

Deno has some issues 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.

Though even if Deno didn't have these issues, having massive shebangs would also not be nice, so this setup is fine.