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

Package detail

bagofcli

cliffano940MIT2.4.1

A bag-of-holding containing CLI utility functions.

cli, command line

readme

Avatar

Build Status Security Status Dependencies Status Coverage Status Published Version

Bag Of CLI

Bag Of CLI contains CLI utility functions.

This is handy when you want to have a set of common CLI commands with descriptions, options, help, and example usages, by just defining them in a JSON file. Bag of CLI essentially allows you to define those info in a configuration file instead of code.

Installation

npm install bagofcli

or as a dependency in package.json file:

"dependencies": {
  "bagofcli": "x.y.z"
}

Usage

Commands:

// create conf/commands.json file containing commands configuration

{
  "options": [
    { "arg": "-f, --file <file>", "desc": "This is a global option, applicable to all commands." }
  ],
  "commands": {
    "command1": {
      "desc": "This is the first command",
      "options": [
        { "arg": "-r, --registry <registry>", "desc": "This is a command option, applicable only to command1"}
      ],
      "examples": [
        "<bin> command1 --registry someregistry"
      ]
    },
    "command2": {
      "desc": "This is the second command",
      "options": [
        { "arg": "-d, --debug", "desc": "This is a command option, applicable only to command2"}
      ],
      "examples": [
        "<bin> command2 --debug"
      ]
    }
  }
}

// setup command handlers

var bag = require('bagofcli');

var actions = {
  commands: {
    command1: {
      action: function (args) {
        console.log(args.registry);
      }
    },
    command2: {
      action: function (args) {
        console.log(args.debug);
      }
    }
  }
};

bag.command(__dirname, actions);

Check out lib/bagofcli.js for more utility functions.

Upgrade

From 0.0.x to 0.1.x .

Update commands.json argument validation rules:

  • notEmpty to required
  • isNumeric to number
  • isEmail to email

Check out iz for available validation rules.

Colophon

Developer's Guide

Build reports:

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

2.4.1 - 2023-07-22

Fixed

  • Fix lack of spacing between log labels and message

2.4.0 - 2023-07-21

Added

  • Add labels option support for logStepHeading, logStepItem(Success|Warning|Error)

2.3.0 - 2022-06-04

Added

  • Add logStepHeading, logStepItem(Success|Warning|Error)

2.2.0 - 2022-01-29

Added

  • Add GH Actions release-* and publish-*

Changed

  • Set min node engine >= 16.0.0

2.1.0 - 2020-11-01

Changed

  • Replace buster-istanbul with c8 for test coverage
  • Replace prompt with inquirer for input prompt

2.0.2 - 2020-06-07

Fixed

  • Fixed missing extension on package.json main property
  • Fixed commander arguments handling in version 5.1.0

2.0.1 - 2020-05-22

Fixed

  • Fixed rules validation check

2.0.0 - 2020-05-13

Changed

  • Changed module to be ESM
  • Replace Buster with Mocha for unit tests
  • Replace Travis CI with GitHub Actions

Removed

  • Remove sub-dependency to Contextify (no more node-gyp errors)

1.1.0 - 2018-02-14

Added

  • Add execAndCollect function

1.0.0 - 2016-10-13

Changed

  • Upgrade deps to latest

0.2.5 - 2016-08-14

Changed

  • Use safe colors
  • Set min node engine to v4.0.0

0.2.3 - 2015-07-12

Added

  • Add lookupConfig function

0.2.2 - 2015-06-21

Added

  • Add build reports to readme

0.2.1 - 2014-11-09

Added

  • Add command option validation
  • Add global option validation

0.2.0 - 2014-09-08

Changed

  • Set min node engine to v0.10.0

0.1.0 - 2014-08-31

Changed

  • Replace validation package from validator to iz

0.0.10 - 2014-08-28

Added

  • Add invalid argument rule check

0.0.9 - 2014-06-27

Changed

  • Update documentation, upgrade dependencies
  • Change test lib to buster-node + referee
  • Set min node engine to v0.8.0

0.0.6 - 2013-10-13

Added

  • Add files function

0.0.5 - 2013-07-15

Added

  • Add optional arg support for usage display

0.0.4 - 2013-07-09

0.0.3 - 2013-07-08

Added

  • Add command arguments validation support
  • Add help examples support

Changed

  • Change exec to display stdout and stderr in chunks
  • Display help when command is unspecified
  • Display error message when command is unknown

0.0.2 - 2013-06-20

Changed

  • Colourise success and error output

0.0.1 - 2013-06-01

Added

  • Initial version, extracted from cliffano/bagofholding