# bagofcli

> A bag-of-holding containing CLI utility functions.

Latest version **3.1.0** (published 2026-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install bagofcli
pnpm add bagofcli
yarn add bagofcli
bun add bagofcli
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2026-08-22 |
| First published | 2013-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >= 22.0.0 |
| Dependencies | 7 |
| Unpacked size | 70.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | Cliffano Subagio |
| Maintainers | cliffano |
| Keywords | cli, command line |

## Links

- npm: https://www.npmjs.com/package/bagofcli
- Repository: https://github.com/cliffano/bagofcli
- Homepage: http://github.com/cliffano/bagofcli
- Issues: http://github.com/cliffano/bagofcli/issues
- npm.io page: https://npm.io/package/bagofcli

## Dependencies (7)

- [async](https://npm.io/package/async.md) ^3.2.6
- [chalk](https://npm.io/package/chalk.md) ^6.0.0
- [lodash](https://npm.io/package/lodash.md) ^4.18.1
- [yaml-js](https://npm.io/package/yaml-js.md) ^0.3.1
- [inquirer](https://npm.io/package/inquirer.md) ^14.1.0
- [commander](https://npm.io/package/commander.md) ^15.0.0
- [validator](https://npm.io/package/validator.md) ^13.15.35

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2026-08-22
- 3.0.0 — 2026-07-05
- 2.5.0 — 2025-11-17
- 2.4.1 — 2023-07-22
- 2.4.0 — 2023-07-21
- 2.3.0 — 2022-06-04
- 2.2.0 — 2022-01-29
- 2.1.0 — 2020-11-01
- 2.0.2 — 2020-06-07
- 2.0.1 — 2020-05-22
- 2.0.0 — 2020-05-13
- 1.1.0 — 2018-02-14
- 1.0.0 — 2016-10-13
- 0.2.5 — 2016-08-13
- 0.2.4 — 2016-08-06
- … 15 more at https://npm.io/package/bagofcli/versions

## README

<!-- BEGIN:AVATAR -->
![Avatar](avatar.jpg)
<!-- END:AVATAR -->

<!-- BEGIN:BADGES -->
[![Build Status](https://github.com/cliffano/bagofcli/workflows/CI/badge.svg)](https://github.com/cliffano/bagofcli/actions?query=workflow%3ACI)
[![Dependencies Status](https://img.shields.io/librariesio/release/npm/bagofcli)](https://libraries.io/npm/bagofcli)
[![Code Scanning Status](https://github.com/cliffano/bagofcli/workflows/CodeQL/badge.svg)](https://github.com/cliffano/bagofcli/actions?query=workflow%3ACodeQL)
[![Coverage Status](https://coveralls.io/repos/github/cliffano/bagofcli/badge.svg?branch=main)](https://coveralls.io/r/cliffano/bagofcli?branch=main)
[![Security Status](https://snyk.io/test/github/cliffano/bagofcli/badge.svg)](https://snyk.io/test/github/cliffano/bagofcli)
[![Published Version](https://img.shields.io/npm/v/bagofcli.svg)](https://www.npmjs.com/package/bagofcli)
<!-- END:BADGES -->

# Bag Of CLI

Bag Of CLI contains utility CLI functions.

Define a commands JSON file containing CLI commands with descriptions, arguments, options, example usages. Bag of CLI essentially hooks up each command to a function, and passing the options and arguments to the function.

By default, the command also gets `--help` and `--version` flags.

## Installation

```shell
npm install bagofcli
```

or as a dependency in package.json file:

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

## Usage

Commands:

```javascript
// 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](https://github.com/cliffano/bagofcli/blob/master/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`

Argument/option validation rules are backed by [validator](https://www.npmjs.com/package/validator). Available rule names:
`required`, `empty`, `blank`, `string`, `number`, `int`, `decimal`, `boolean`, `email`, `alphaNumeric`, `anArray`, `date`, `ip`, `cc`, `phone`, `postal`, `ssn`.

## Colophon

<!-- BEGIN:DEVELOPERS_GUIDE -->
[Developer's Guide](https:/cliffano.github.io/developers-guide-nodejs.html)
<!-- END:DEVELOPERS_GUIDE -->

<!-- BEGIN:BUILD_REPORTS -->
Build reports:

* [Code complexity report](https://cliffano.github.io/bagofcli/complexity/plato/index.html)
* [Unit tests report](https://cliffano.github.io/bagofcli/test/mocha.txt)
* [Test coverage report](https://cliffano.github.io/bagofcli/coverage/c8/index.html)
* [Integration tests report](https://cliffano.github.io/bagofcli/test-integration/mocha.txt)
* [API Documentation](https://cliffano.github.io/bagofcli/doc/jsdoc/index.html)

<!-- END:BUILD_REPORTS -->

---
_Source: https://npm.io/package/bagofcli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
