Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

clix

royriojas5.6kMIT5.0.0

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

cli, command, line, tool, command, line, helper, parse, options, optionator

readme

NPM Version Build Status

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.resolve( __dirname, '../package.json' ),

 // 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.resolve( __dirname, '../configs/esformatter.json' ),

   // 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 module
var clix = require( '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 options
clix.launch( programOptions, function ( program ) {
  // this callback will be called with a program object with the following api
  //
  // program.showHelp() // <== method used to show the generated help if required to do it by other commands
  // program.showVersion() // <== will print the version in the stdout
  // program.getVersion() // <== will return the version of the package
  // program.opts // <== the optionator parsed arguments
  //   for example program.opts.useCache, will be true if the cli was called
  //   doing `cli -useCache=true
  //
  // logging methods
  // program.ok, program.error, program.log, program.subtle, program.success
  // if the option -q, --quiet is used, program.log and program.subtle calls will not print any output
  //
  // program.getConfig() // <== method to get the configuration as JSON from one of the possible paths
  // either the provided one, looking for a file in the current working directory or
  // using a default one distributed with the command line being developed
} );

Changelog

Changelog

changelog

clix - Changelog

v5.0.0

v4.0.0

v3.0.0

  • Refactoring
    • Remove critical warning from audit - 41c3f5c, Roy, 11/06/2019 03:05:22

v2.2.2

v2.2.1

v2.2.0

v2.1.0

  • Features
    • add ext and rename options similar to grunt.file.expandMapping ones - 7e810d8, [Roy Riojas](https://github.com/Roy Riojas), 21/08/2015 03:39:08
  • Enhancements
    • Add loadConfig method helper to load a configuration file other than the default one - 15107e9, royriojas, 16/08/2015 00:52:07
  • Tests Related fixes
  • Refactoring
    • Extend getTargets to also resolve the files property using the expandMapping method - 81eed95, royriojas, 15/08/2015 05:56:16

v2.0.9

  • Features
    • Implement expandMapping similar to the one in grunt - 7c052d8, royriojas, 15/08/2015 05:07:57

v2.0.8

  • Build Scripts Changes
    • Update optionator to get default booleans - 52712d1, royriojas, 15/08/2015 02:53:39

v2.0.7

  • Features
  • Build Scripts Changes
  • Refactoring

    • do not resolve paths by default - 8ba8b30, royriojas, 15/08/2015 01:16:29

      If the full paths are needed specify the option resolvePaths: true

      var files = cli.expandGlobs(globs, { resolvePaths: true });
    • remove unnecessary try/catch - 30791fa, royriojas, 15/08/2015 00:58:18

v2.0.6

v2.0.5

v2.0.4

  • Features
    • Add a convenience method to expand globs - 1f3ddf1, royriojas, 14/08/2015 21:20:25

v2.0.3

  • Build Scripts Changes
    • update clix dep to get nicer log output - 20af260, royriojas, 11/08/2015 19:30:06

v2.0.16

v2.0.15

  • Features
    • add ext and rename options similar to grunt.file.expandMapping ones - 7e810d8, [Roy Riojas](https://github.com/Roy Riojas), 21/08/2015 03:39:08

v2.0.14

v2.0.13

  • Features

v2.0.12

  • Enhancements
    • Add loadConfig method helper to load a configuration file other than the default one - 15107e9, royriojas, 16/08/2015 00:52:07

v2.0.11

  • Tests Related fixes

v2.0.10

  • Refactoring
    • Extend getTargets to also resolve the files property using the expandMapping method - 81eed95, royriojas, 15/08/2015 05:56:16
  • do not resolve paths by default - 8ba8b30, royriojas, 15/08/2015 01:16:29

    If the full paths are needed specify the option resolvePaths: true

    var files = cli.expandGlobs(globs, { resolvePaths: true });
  • remove unnecessary try/catch - 30791fa, royriojas, 15/08/2015 00:58:18

  • Features
    • Implement expandMapping similar to the one in grunt - 7c052d8, royriojas, 15/08/2015 05:07:57
  • Add a convenience method to expand globs - 1f3ddf1, royriojas, 14/08/2015 21:20:25
  • Build Scripts Changes
    • Update optionator to get default booleans - 52712d1, royriojas, 15/08/2015 02:53:39
  • update clix dep to get nicer log output - 20af260, royriojas, 11/08/2015 19:30:06

v2.0.1

  • Enhancements

v2.0.0

  • Refactoring
    • better error handling and added helper to create task targets similar to grunt - 4337ad9, royriojas, 10/08/2015 00:02:39

v1.1.6

  • Build Scripts Changes
    • Use clix-logger module for logs, updated dependencies and build scripts - 5950e1b, royriojas, 07/08/2015 23:39:15

v1.1.5

  • Refactoring
    • Prevent failing if the env variable is not set - 3e7d447, royriojas, 12/07/2015 21:24:35

v1.1.4

  • Build Scripts Changes
  • Enhancements
    • Added the print option to print in gray messages even if quiet mode is set - e1cf344, royriojas, 12/07/2015 21:00:14
  • Added the print option to print in gray messages even if quiet mode is set - de208f0, royriojas, 12/07/2015 20:59:42

v1.1.2

config

  • Enhancements
    • config file can be a js module exporting a function - 760d055, royriojas, 03/07/2015 23:45:19

v1.1.1

  • Build Scripts Changes

v1.1.0

  • Features

    • turn off colorized output by default - f51e5c3, royriojas, 03/07/2015 18:24:24

      BREAKING CHANGE: Well not really, but it changes the way it behaved before, aesthetically speaking

      To enable the colored output pass the option colored-ouptut to the command line like

      ./bin/cli.js --colored-output

v1.0.7

  • Build Scripts Changes
    • Change the building scripts to use the cache to only beautify changed files - 660b82b, [Roy Riojas](https://github.com/Roy Riojas), 25/05/2015 06:56:59
  • Bug Fixes