A configuration object may be provided in the class constructor. The available options are:
Base path where the ProcessingOutput.location will start from.
Default: path.dirname(entryFile)
Base path where the ProcessingOutput.location will start from.
Default: path.dirname(entryFile)
Warning Deprecated since 0.13.0 in favor of
CliOptions.baseLocation
Path where the single-command scripts (not contained in any namespace) are stored. A relative value can be provided, using CliOptions.baseLocation as base path.
Default: "commands"
Configuration related to when errors should be displayed. The order of the lists containing the error-types matters, as it changes which error-messages are shown first (elements appearing first have a higher order of precedence). The available error-types are:
command_not_found: an unknown argument is encountered when a command was expectedoption_wrong_value: the option parser considers the given value as incorrect (e.g.type:numberwhen given"a123")option_required: an option is marked as required but is not providedoption_missing_dependencies: some requirement specified for an option (Option.requires) is missing.option_missing_value: an option is provided without its corresponding valueoption_not_found: an unknown argument is encountered when an option was expected
List of error-types that will get displayed before help
Default: ["command_not_found"]
List of error-types that will cause to end execution with exit(1)
Default: ["command_not_found", "option_wrong_value", "option_required", "option_missing_value", "option_missing_dependencies", "option_not_found"]
Help-related configuration
Whether to generate help option
Default: true
Aliases to be used for help option
Default: ["h", "help"]
Description for the option
Template to be used when generating help. There are five distinct sections: usage, description, namespaces, commands and options. This can be used to include a header/footer, change the order of the sections, or remove a section altogether. If a section has no content, it will be removed along with any line-breaks that follow. You can see a use-case for this in the docker example
Default: \n{usage}\n{description}\n{namespaces}\n{commands}\n{options}\n
Version-related configuration
Whether to generate version option
Default: true
Aliases to be used for version option
Default: ["v", "version"]
Description for the option
Whether the cli implements a root command (invocation with no additional namespaces/commands).
If a string is provided, it will be used as the default command to execute
Default: true
Logger to be used by the cli. It contains two methods, log and error, that can be used to add a prefix to the log (e.g. "error ") or change the output color, as demonstrated in this docker example.
Default: /src/cli-logger.ts
Cli name to be used instead of the one defined in package.json
Default: packageJson.name
Cli version to be used instead of the one defined in package.json
Default: packageJson.version
Cli description to be used instead of the one defined in package.json
Default: packageJson.description
Enable debug mode. This is intended for the development phase of the cli. It will:
- Print verbose errors when a script in not found in the expected path during
Cli.run. - Print warnings for deprecated properties/methods, useful for detecting and applying these changes before updating to the next version.
Its value can also be configured using an enviroment variable:
$ CLIER_DEBUG=1 node cli.jsDefault: process.env.CLIER_DEBUG
Configure bash-completion functionality
Whether to create bash-completion command
Default: true
Name of the completion command
Default: generate-completions
Object containing the messages to be used in the Cli, to override the default ones defined by this library. This enables internationalization and customization of cli-native messages. You can see a use-case in this intl-cli example
Default: defined in /src/cli-messages and /src/cli-errors
Enable configuration file processing
Names of config files to search for
Override default JSON parser. Receives the contents of such file (string), and the full path for the file found.
Configure a prefix for environment variables to be included as options