Cliffy - A Framework For Interactive CLIs
Cliffy is a simple, powerful utility for making interactive command line interfaces.
Cliffy is run as a REPL. This allows you to accept multiple commands with one running node process. Cliffy is NOT an argv parser.
Features:
- REPL Style interface
- Simple API
- Can parse negative numbers
- Typed parameters
- Git Style Sub-Commands
- Optional parameters (New in v2)
- Rest parameters (New in v2)
- Options
- Auto generated help
- Typescript Support
Gotchas:
- Options are specified with an
@
symbol. Not-
or--
. This is what allows Cliffy to parse negatives. - Requires node v6+
Quickstart
Installation:
npm i cliffy # --save if using npm < v5
Usage
; .setDelimiter"-->" .command"run", .show;
Result:
--> run to nevadaI ran to nevada--> help Available commands: run [options] <destination> Run somewhere --> help run Run somewhere Usage: run [options] <destination> Options: @quickly Run quickly Sub-Commands: to [options] <destination> Run to a destination from [options] <destination> Run from a destination
API
new CLI()
Interface:
Usage:
cli.addCommand(name: string, command: Command): this
Register a command
Takes a name and a command object.
The command name is what the user will enter to execute the command.
The command interface is defined as follows:
Example Usage:
cli.command"run",
cli.addCommand(name: string, opts: Action): this
Register a basic command.
This overload allows you to pass the action function directy. Useful for quick commands where parameters, options, and a description may not be needed.
Example usage:
cli.command"speak",sayHello"World";
cli.addCommands(commands: { [name: string]: Command | Action }): this
Register multiple commands at once.
Example usage:
cli.commands;
cli.setDelimiter(delimiter: string): this
Set the CLI delimiter
Defaults to: "$>"
cli.setInfo(info: string): this
Set the CLI info.
Info is meant to give an overview of what the CLI does and how to use it. If it is set it is shown directly under the CLI name.
Defaults to: none
cli.setName(name: string): this
Set the name of the CLI (Shown at the top of the help menu)
Defaults to: none
cli.setVersion(version: string): this
Set the CLI version. Shown beside the CLI name if set.
Defaults to: none
cli.show(): this
Show the CLI
cli.hide(): this
Hide the cli
Autogenerated Help Menu
Cliffy automatically generates a help menu for each command.
To get an overview of all the commands simply type:
help
To get help with a specific command, type help followed by the command.
help ls
This works with subcommands as well
help git pull
Build instructions
- Clone this repo
- CD into the repo
npm install
npm run build