# cli-kit **Repository Path**: mirrors_wickedest/cli-kit ## Basic Information - **Project Name**: cli-kit - **Description**: Everything you need to create awesome Node.js command line interfaces - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-19 - **Last Updated**: 2025-06-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # cli-kit A command line application toolkit for Node.js. [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![Travis CI Build][travis-image]][travis-url] [![Appveyor CI Build][appveyor-image]][appveyor-url] [![Test Coverage][coveralls-image]][coveralls-url] [![Greenkeeper badge][greenkeeper-image]][greenkeeper-url] [![Deps][david-image]][david-url] [![Dev Deps][david-dev-image]][david-dev-url] ## Features * Command line parsing * Support for command hierarchies * Auto-generated help * CLI template engine * External CLI extensions * Automatic Node.js version enforcement ## Installation npm i cli-kit --save ## Usage ```js import CLI from 'cli-kit'; (async () => { const { argv, _ } = await new CLI({ options: { '-f, --force': 'use the force', '--timeout [value]': { desc: 'the timeout duration', type: 'int' } } }).exec(); console.log('options:', argv); console.log('args:', _); })(); ``` ## Architecture In cli-kit, commands and options are grouped into "contexts". The main CLI instance defines the "global context". Each command defines a new context. Each context can have its own commands, options, and arguments. What you end up with is a hierarchy of contexts. When cli-kit parses the command line arguments, it will check each argument against the global context to see if the argument can be identified as a known command, option, or argument. If it finds a command, it adds the command's context to a stack and re-parses any unidentified arguments. This allows you to create deep and dynamic hierarchies of commands, options, and arguments. ## API ### class `CLI` A `CLI` intance defines a global context for which you add commands, options, and arguments. Extends `Context` > [`HookEmitter`](https://www.npmjs.com/package/hook-emitter). #### `constuctor(opts)` * `opts` : `Object` (optional) Various options to initialize the `CLI` instance. ##### Example ```js const cli = new CLI({ // An array of argument definitions. They are parsed in the order they are defined. args: [ // An argument can be as simple as its name. Wrapping the name with `<` and `>` signifies // that the argument is required. '', // To define an optional arguemnt, you can use `[` and `]`. '[arg2]', // Or simply omit the brackets 'arg3', // For more options, you can specify an argument descriptor { // The argument name. Follows the same rules as above. name: 'arg4', // The argument's description to show in the help output. desc: undefined, // When `true`, hides the argument from usage string in the help output. hidden: false, // When `true`, captures all subsequent argument values into an array multiple: false, // Overrides the brackets and forces the argument to be required or optional. required: false, // There are several built-in types. See the "types" section below for more info. type: 'string' }, // Adding `...` will capture all subsequent argument values into an array 'arg4...' ], // Global flag to camel case property names derived from multi-word options/arguments. // Defaults to true, can be overwritten by the option/argument. camelCase: true, // An object of command names to command descriptors. commands: { 'some-command': { // The action to perform when the command is parsed. action({ argv, _ }) { console.log('options:', argv); console.log('args:', _); }, // An array of alternate command names. aliases: [ 'another-command' ], // Command specific args. See `args` section above. args: [], // When `true`, camel case all option and argument names in the `argv` result. camelCase: true, // An object of subcommand names to subcommand descriptors. commands: {}, // The command description. desc: undefined, // When `true`, hides the command from the help output. hidden: false, // An object of option formats to option descriptors. See the `options` section below. options: {}, // The command name to display in the help output. Defaults to the command name. title: undefined } }, // The default command `exec()` should run if no command was found during parsing. // If `help` is `true` and no default command is specified, it will default to displaying the // help screen. If you want help, but do not want to default to the help command, then set the // `defaultCommand` to `null`. defaultCommand: undefined, // The CLI description to print on the help screen between the usage and commands/options/args. desc: undefined, // Adds the `-h, --help` to the global flags and enables the auto-generated help screen. // Defaults to `true`. help: true, // The exit code to return when the help screen is displayed. This is useful if you want to // force the program to exit if `--help` is specified and the user is chaining commands together // or after displaying the help screen and prevent further execution in the CLI's promise chain. helpExitCode: undefined, // The name of the program used by the help screen to display the command's usage. // Defaults to "program". name: 'program', // An object of option formats to option descriptors or an array of sorted group names and // objects of option formats to option descriptors. options: { // }, // The title for the top-level (or "Global") context. This title is displayed on the help screen // when displaying the list of options. title: 'Global', // When set, it will automatically wire up the `-v, --version` option. Upon calling with your // program with `--version`, it will display the version and exit with a success (zero) exit // code. version: null }); ``` #### `exec(args)` Parses the command line args and executes a command, if found. * `args` : `Array` (optional) An array of arguments. Each argument is expected to be a string. Defaults to `process.argv.slice(2)`. Returns a `Promise` that resolves an `Arguments` object. This object will contain the parsed options in `argv` and arguments in `_`. ##### Example ```js cli.exec() .then(({ argv, _ }) => { console.log('options:', argv); console.log('args:', _); }); ``` ### class `Context` Base class for `CLI` and `Command` classes. Extends [`HookEmitter`](https://www.npmjs.com/package/hook-emitter). #### `argument(arg)` Adds an argument to a `CLI` or `Command`. * `arg` : `Argument`, `Object`, or `String`. An argument descriptor. Either an `Argument` instance or an `Object` to pass into a `Argument` constructor. An argument requires a `name`. Returns a reference to the `CLI` or `Command`. ##### Example ```js // define a non-required argument "foo" cli.argument('foo'); // define a non-required argument "wiz" cli.argument('[wiz]'); // define a required argument "pow" cli.argument(''); cli.argument({ name: 'bar', type: 'int' }); cli.argument(new Argument('baz')); ``` #### `command(cmd, opts)` Adds a command to a `CLI` or `Command`. > TODO #### `option(optOrFormat, group, params)` Adds an option or group of options to a `CLI` or `Command`. > TODO ## cli-kit vs other libraries

General

cli-kitCaporal.jsCommander.jsdashdashfieldsgetoptsinquirermeowminimistmrioclifpromptpromptlypromptsyargs
Latest version0.4.11.1.02.19.01.14.10.1.242.2.36.2.15.0.01.2.01.1.11.12.71.0.03.0.32.0.012.0.5
Actively maintained
(within last year)
:white_check_mark::white_check_mark::white_check_mark::warning:
Last release Dec 2016
:warning:
Last release Jul 2015
:white_check_mark::white_check_mark::white_check_mark::warning:
Last release Sep 2015
:white_check_mark::white_check_mark::warning:
Last release Mar 2016
:white_check_mark::white_check_mark::white_check_mark:
LicenseMITMITMITMITMITMITMITMITMITMITMITMITMITMITMIT
LanguageJavaScriptJavaScriptJavaScriptJavaScriptJavaScriptJavaScriptJavaScriptJavaScriptJavaScriptJavaScriptTypeScriptJavaScriptJavaScriptJavaScriptJavaScript
Async/promise support:white_check_mark::white_check_mark: 1:x::x::x::x::white_check_mark::x::x::x::white_check_mark: 1:x::white_check_mark::white_check_mark::x:
Data type coercion:white_check_mark::white_check_mark::white_check_mark::white_check_mark::x::white_check_mark::x::white_check_mark::white_check_mark::white_check_mark::white_check_mark::x::x::white_check_mark::white_check_mark:
User-defined input/output stream:white_check_mark::x::x::x::x::x::white_check_mark::x::x::x::x::white_check_mark::white_check_mark::white_check_mark::x:

Parsing

cli-kitCaporal.jsCommander.jsdashdashfieldsgetoptsinquirermeowminimistmrioclifpromptpromptlypromptsyargs
Command:white_check_mark::white_check_mark::white_check_mark::x:n/a:x:n/a:x::x::x::white_check_mark:n/an/an/a:white_check_mark:
Command aliases:white_check_mark::white_check_mark::white_check_mark::x:n/a:x:n/a:x::x::x::white_check_mark:n/an/an/a:white_check_mark:
Subcommands:white_check_mark::warning: 2:warning: 3:x:n/a:x:n/a:x::x::x::white_check_mark:n/an/an/a:warning: 2
Options:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/a:white_check_mark:n/a:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/an/an/a:white_check_mark:
Options aliases:white_check_mark::x::x::white_check_mark:n/a:white_check_mark:n/a:white_check_mark::white_check_mark::white_check_mark::x:n/an/an/a:white_check_mark:
Custom option validator:white_check_mark::white_check_mark::white_check_mark::x:n/a:x:n/a:x::x::x::white_check_mark:n/an/an/a:x: 4
Flags (true/false):white_check_mark::x::white_check_mark::white_check_mark:n/a:white_check_mark:n/a:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/an/an/a:white_check_mark:
Flag negation (--no-<name>):white_check_mark::x::white_check_mark::x:n/a:x:n/a:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/an/an/a:white_check_mark:
Argument support:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/a:white_check_mark:n/a:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/an/an/a:white_check_mark:
Custom argument validator:white_check_mark::white_check_mark::white_check_mark::x:n/a:x:n/a:x::x::x::white_check_mark:n/an/an/a:white_check_mark:
Stop parsing --:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/a:white_check_mark:n/a:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/an/an/a:white_check_mark:
Default option/argument values:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/a:white_check_mark:n/a:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/an/an/a:white_check_mark:
Environment variable support:white_check_mark::x::x::white_check_mark:n/a:x:n/a:x::x::x::white_check_mark:n/an/an/a:white_check_mark: 5
Auto-generated help screen:white_check_mark::white_check_mark::white_check_mark::white_check_mark: 6n/a:x:n/a:white_check_mark::x::x::white_check_mark:n/an/an/a:white_check_mark:
Custom help exit code:white_check_mark::x::x::x:n/a:x:n/a:white_check_mark::x::x::x:n/an/an/a:x:

Prompting

cli-kitCaporal.jsCommander.jsdashdashfieldsgetoptsinquirermeowminimistmrioclifpromptpromptlypromptsyargs
Single-line text prompting:grey_question:n/an/an/a:white_check_mark:n/a:white_check_mark:n/an/an/a:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/a
Multi-line text prompting:grey_question:n/an/an/a:x:n/a:x:n/an/an/a:x::x::x::x:n/a
Password prompting:grey_question:n/an/an/a:white_check_mark:n/a:white_check_mark:n/an/an/a:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/a
Confirm (yes/no) prompting:grey_question:n/an/an/a:white_check_mark: 7n/a:white_check_mark:n/an/an/a:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/a
Press any key to continue prompting:grey_question:n/an/an/a:x:n/a:x:n/an/an/a:white_check_mark::x::white_check_mark::x:n/a
Inline list prompting:grey_question:n/an/an/a:white_check_mark: 7n/a:white_check_mark: 8n/an/an/a:x::x::x::white_check_mark: 9n/a
Numbered select list prompting:grey_question:n/an/an/a:white_check_mark:n/a:white_check_mark:n/an/an/a:x::x::x::x:n/a
Scrollable select list prompting:grey_question:n/an/an/a:x:n/a:white_check_mark:n/an/an/a:x::x::x::white_check_mark:n/a
Multi-select/checkbox list prompting:grey_question:n/an/an/a:x:n/a:white_check_mark:n/an/an/a:x::x::x::white_check_mark:n/a
File/directory prompting:grey_question:n/an/an/a:white_check_mark:n/a:white_check_mark: 10n/an/an/a:x::x::x::x:n/a
Numeric-only prompting:grey_question:n/an/an/a:x:n/a:x:n/an/an/a:x::x::x::white_check_mark:n/a
Date/time prompting:grey_question:n/an/an/a:x:n/a:white_check_mark: 11n/an/an/a:x::x::x::x:n/a
Multiple prompt chaining:grey_question:n/an/an/a:white_check_mark:n/a:white_check_mark:n/an/an/a:x::x::x::white_check_mark:n/a
External editor support:grey_question:n/an/an/a:x:n/a:white_check_mark:n/an/an/a:x::x::x::x:n/a
Custom value formatter/transformer:grey_question:n/an/an/a:white_check_mark: 12n/a:white_check_mark: 13n/an/an/a:x::white_check_mark: 14:white_check_mark: 12:white_check_mark:n/a
Custom validation:grey_question:n/an/an/a:x:n/a:white_check_mark:n/an/an/a:x::white_check_mark::white_check_mark::white_check_mark:n/a
Default prompt values:grey_question:n/an/an/a:white_check_mark:n/a:white_check_mark:n/an/an/a:white_check_mark::white_check_mark::white_check_mark::white_check_mark:n/a
Prompt history:grey_question:n/an/an/a:white_check_mark:n/a:white_check_mark: 15n/an/an/a:x::white_check_mark::x::x:n/a
Auto-suggest mismatch:grey_question:n/an/an/a:white_check_mark:n/a:white_check_mark: 16n/an/an/a:x::white_check_mark::x::x:n/a
Autocomplete:grey_question:n/an/an/a:white_check_mark:n/a:white_check_mark:n/an/an/a:x::x::x::white_check_mark:n/a
Custom prompt types/plugins:grey_question:n/an/an/a:x:n/a:white_check_mark:n/an/an/a:x::x::x::x:n/a
Multiple answers (repeat prompt):grey_question:n/an/an/a:x:n/a:x:n/an/an/a:x::x::x::white_check_mark:n/a

Logging

cli-kitCaporal.jsCommander.jsdashdashfieldsgetoptsinquirermeowminimistmrioclifpromptpromptlypromptsyargs
Application logging:white_check_mark::white_check_mark: 17n/an/an/an/an/an/an/an/a:white_check_mark:n/an/an/an/a
Application debug logging:white_check_mark: 18:x:n/an/an/an/an/a:white_check_mark:n/a:x::x:n/an/an/an/a
Internal debug logging:white_check_mark: 18:x:n/an/a:x::x:n/an/an/an/a:white_check_mark: 19n/an/an/an/a

Misc

cli-kitCaporal.jsCommander.jsdashdashfieldsgetoptsinquirermeowminimistmrioclifpromptpromptlypromptsyargs
Dedicated website:white_check_mark::x::x::x::x::x::x::x::x::x::white_check_mark::x::x::x::white_check_mark:
External CLI extensions:white_check_mark::x::x::x:n/an/an/a:white_check_mark::x::x::white_check_mark:n/an/an/a:x:
Internal hook system:white_check_mark::x::x::x::x::x::x::x::x::x::white_check_mark::x::x::x::x:
Bash completion:grey_question::white_check_mark::x::white_check_mark:n/a:x:n/a:x::x::x::x:n/an/an/a:x:
REPL:grey_question::x::x::x::x::x::x::x::x::x::x::x::x::x::x:
Built-in i18n support:grey_question::x::x::x::white_check_mark::x::x::x::x::x::x::x::x::x::x:
Project generator CLI:grey_question::x::white_check_mark: 20:x::x::x::x::x::x::x::white_check_mark::x::x::x::white_check_mark: 21
Built-in update notifications:grey_question::x::x::x::x::x::x::x::x::x::x::x::x::x::x:
1. Command actions only. The actually parsing is sync.
2. Requires reparsing with subcommand context or manually subprocessing.
3. Automatically spawns subcommand in new process, otherwise requires reparsing with subcommand context.
4. Only the last parsed invalid option error is raised.
5. Custom environment variable names are not supported. The names must match a prefixed option name.
6. Options only. (e.g no usage, etc)
7. Via select list input type.
8. Via expand input type.
9. Maximum 2 options via toggle input type.
10. Via [inquirer-fuzzy-path](https://www.npmjs.com/package/inquirer-fuzzy-path) plugin.
11. Via [inquirer-datepicker-prompt](https://www.npmjs.com/package/inquirer-datepicker-prompt) plugin.
12. Via validator callback.
13. Via filter callback.
14. Via `before()` callback.
15. Via [inquirer-command-prompt](https://www.npmjs.com/package/inquirer-command-prompt) plugin.
16. Via [inquirer-prompt-suggest](https://www.npmjs.com/package/inquirer-prompt-suggest) plugin.
17. Via [winston](https://npmjs.com/package/winston).
18. Uses [snooplogg](https://npmjs.com/package/snooplogg).
19. Uses [debug](https://npmjs.com/package/debug).
20. Via [generator-commander](https://www.npmjs.com/package/generator-commander) and [generator-node-cli-commander](https://www.npmjs.com/package/generator-node-cli-commander) Yeoman plugin.
21. Via [generator-yargs](https://www.npmjs.com/package/generator-yargs) Yeoman plugin.
> :sparkles: If you find any inaccuracies (aside from the version numbers), please feel free to submit a PR. ## Who Uses cli-kit? * [Axway](https://www.axway.com) ## License MIT [npm-image]: https://img.shields.io/npm/v/cli-kit.svg [npm-url]: https://npmjs.org/package/cli-kit [downloads-image]: https://img.shields.io/npm/dm/cli-kit.svg [downloads-url]: https://npmjs.org/package/cli-kit [travis-image]: https://travis-ci.org/cb1kenobi/cli-kit.svg?branch=master [travis-url]: https://travis-ci.org/cb1kenobi/cli-kit [appveyor-image]: https://ci.appveyor.com/api/projects/status/nhbqpsx6jc10xnjw?svg=true [appveyor-url]: https://ci.appveyor.com/project/cb1kenobi/cli-kit [coveralls-image]: https://img.shields.io/coveralls/cb1kenobi/cli-kit/master.svg [coveralls-url]: https://coveralls.io/r/cb1kenobi/cli-kit [greenkeeper-image]: https://badges.greenkeeper.io/cb1kenobi/cli-kit.svg [greenkeeper-url]: https://greenkeeper.io/ [david-image]: https://img.shields.io/david/cb1kenobi/cli-kit.svg [david-url]: https://david-dm.org/cb1kenobi/cli-kit [david-dev-image]: https://img.shields.io/david/dev/cb1kenobi/cli-kit.svg [david-dev-url]: https://david-dm.org/cb1kenobi/cli-kit#info=devDependencies