Skip to main content
Deno 2 is finally here 🎉️
Learn more

The Command Line Y-interface.

CLY

A tiny solution for creating tiny command line applications, with zero third-party dependencies. Easy to setup and configurable!

See the Deno module here: https://deno.land/x/cly

import { ClyApp } from "https://deno.land/x/cly/mod.ts";

const app = new ClyApp("App name")
  .default(() => console.log("Hello!"))
  .command("help", () => console.log(app.getHelp()));

app.run();

Look, how easy it is!

See the examples.ts for a full example.

This library is minimal, but powerful. Few methods and stuff. But you can do a lot with it. Here are the options that you can configure.

Options

const app = new ClyApp("App", {
  description: "App description",
  version: "1.0.0",
  help: "Work with App from the command line!",
  executableName: "app-command-name",
  parseOptions: {},
  forUnknownShow: "error",
  unknownMsg: (cmd) => `error: command not found '${cmd}'`,
});
  • help ─ A custom help message to be used when help message has to be printed. If not set, a help message is generated with available commands, version, usage, and description.
  • version ─ Version to print under the generated help message. If not specified, just the app name is printed. Version is prefixed with v.
  • description ─ Description to add on top of the generated help message. Nothing is printed as description if not used.
  • execName ─ Executable name for the usage hint in the help message.
  • parseOptions ─ Argument options to be used with the Deno’s standard flag module’s argument parser. https://deno.land/std/flags/mod.ts
  • forUnknownShow ─ You can pass “error”, “help”, or “default_handler” as the value. So, when an unknown command is used with your CLI application, you could either print out “unknown command” error (or the custom error, if one set using unknownMsg), or help message or the default handler, if one is set.
  • unknownMsg ─ A custom error message for unknown commands. A function that returns a that custom error message as string. It takes the entered command as a parameter.

Methods

  • default ─ Registers a default handler. Used when no commands are passed in.

  • command ─ Registers a command and it’s handler.

    import { ClyApp } from "https://deno.land/x/cly/mod.ts";
    
    const app = new ClyApp("App");
    
    app.command("help", handler);
    app.command(["joke", "tell-joke"], handler);
    app.command({
      command: "command", // or ["command", "alias-1", "alias-2", ...],
      // description to be used in the help generated message.
      description: "Command description",
    }, handler);

    The handler function takes parsed arguments as the arguments. Doesn’t have to return anything.

    You could also type the arguments.

    app.command<{ A: boolean }>("run", (args) => {
      console.log(args.A);
    });
  • run ─ Start your application.

  • getHelp ─ Returns the help message.


Go, create your Command Line Y-Interface
Licensed under MIT