clix
A tiny utility to make easy to create command line tools that require a config file in an easy way. It uses optionator to parse the arguments
Overview
This module aims to make it easy the development of cli commands. It include the following options by default:
-
-h, --help
, useful help message (thanks to optionator). -
-v, --version
, output the version of the module -
-q, --quiet
, if the app prints logs using the provided log methods in the returned instance, this will suppress the verbose output showing only a summary of the cli execution -
-c, --config
, path to the configuration file (as json) to be used by this module -
--colored-output
, wheter to use or not use color in the output messages.false
by default. **If you do want to enable colors without passing this option you can set the environment variable__CLIX_COLORED_OUTPUT__
to true doing:export __CLIX_COLORED_OUTPUT__=true
Install
npm i --save-dev clix
Usage
// ./bin/cli.js #!/usr/bin/env node var programOptions = // the path to the package json of the current module (used to get the version of the module) pkgJSONPath: path // if this object is set the -c, --config option will be available configFile: // the default name of the configuration file to look for in the process.cwd() defaultName: '.esformatter' // optionally a default config file can be provided inside the module pathToLocalConfig: path // the description for the config option. This will be shown in the help description: 'Path to your `esformatter` config, if not provided will try to use the `.esformatter` file in your current working directory, if not found will use the one provided with this package' // options passed to optionator. Check the optionator page for more info // the following is just an example of the configuration used in esbeautifier optionator: prepend: 'Usage: esbeautifier [options] glob [glob1] [glob2]..[globN]' options: heading: 'Options' option: 'checkOnly' alias: 'k' type: 'Boolean' description: 'Will just run the beautifier and report which files need to be beautified' option: 'useCache' alias: 'u' type: 'Boolean' description: 'If true, this module will remember the `mtime` and `size` of the beatufied files and only operate on the ones that changed. If false, the cache will be destroyed. Cache will only be kept between executions with the useCache flag set to true.' ; // require the clix modulevar clix = ; // if you want to handle the error and call process.exit by yourself// just provide an onError callback in the clix object// clix.onError = function (args) {// // args.error // <== the error thrown when running the module// // handle the error here// }; // call launch, passing the optionsclix;