用于交互式 CLI 的 NodeJS 框架
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:
Gotchas:
@ symbol. Not - or --.
This is what allows Cliffy to parse negatives.Installation:
…Result:
--> run to nevada
I ran to nevada
--> help
Available commands:
run [options] Run somewhere
--> help run
Run somewhere
Usage:
run [options]
Options:
@quickly Run quickly
Sub-Commands:
to [options] Run to a destination
from [options] Run from a destinationParameters may be quoted using either ' (single) or " (double) quotes. For example the command could be
say "Hello World" 'Lovely Weather'This would give two parameters of Hello World and Lovely Weather. When inside the quoted parameter, the other type of quotes can be used. This lets JSON be entered for example.
say '{"text": "This is the weather"}'Will give a parameter of the string, {"text": "This is the weather"} that can then be parsed as JSON.
Cliffy automatically generates a help menu for each command.
To get an overview of all the commands simply type:
helpTo get help with a specific command, type help followed by the command.
help lsThis works with subcommands as well
help git pullnpm installnpm run buildnew CLI()Interface:
class CLI {
constructor(opts: {
input?: NodeJS.ReadableStream,
output?: NodeJS.WritableStream,
/** Set to true to prevent cliffy from displaying help text after entering a blank line. Defaults to false */
quietBlank?: boolean
} = {})
}Usage:
const cli = new CLI(opts)cli.addCommand(name: string, command: Command): thisRegister 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.addCommand(name: string, opts: Action): thisRegister 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.addCommand("speak", () => sayHello("World"));cli.addCommands(commands: { [name: string]: Command | Action }): thisRegister multiple commands at once.
Example usage:
cli.addCommands({
run: {
action(params, options) {
console.log("Running");
}
},
jog: {
action(params, options) {
console.log("Jogging");
}
},
walk: {
action(params, options) {
console.log("Walking");
}
}
});cli.setDelimiter(delimiter: string): thisSet the CLI delimiter
Defaults to: "$>"
cli.setInfo(info: string): thisSet 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): thisSet the name of the CLI (Shown at the top of the help menu)
Defaults to: none
cli.setVersion(version: string): thisSet the CLI version. Shown beside the CLI name if set.
Defaults to: none
cli.show(): thisShow the CLI.
cli.hide(): thisHide the cli.
cli.showHelp(): thisShow the main help menu.
暂无开放 Issues,或尚未同步最近议题。