# bossy

> Command line options parser

Latest version **4.0.3** (published 2018-11-01) · BSD-3-Clause license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 4.0.3 |
| Published | 2018-11-01 |
| First published | 2014-09-10 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.12.0 |
| Dependencies | 3 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 45 |
| Maintainers | arb, hueniverse, sericaia, wyatt |
| Keywords | cli, command line, options, parser |

## Links

- npm: https://www.npmjs.com/package/bossy
- Repository: https://github.com/hapijs/bossy
- Homepage: https://github.com/hapijs/bossy#readme
- Issues: https://github.com/hapijs/bossy/issues
- npm.io page: https://npm.io/package/bossy

## Dependencies (3)

- [joi](https://npm.io/package/joi.md) 14.x.x
- [boom](https://npm.io/package/boom.md) 7.x.x
- [hoek](https://npm.io/package/hoek.md) 6.x.x

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 4.0.3 (latest) — 2018-11-01
- 4.0.2 — 2018-10-31
- 4.0.1 — 2017-11-03
- 4.0.0 — 2017-10-23
- 3.0.4 — 2016-12-29
- 3.0.3 — 2016-12-01
- 3.0.2 — 2016-10-18
- 3.0.1 — 2016-07-29
- 3.0.0 — 2016-04-28
- 2.0.1 — 2016-02-12
- 2.0.0 — 2015-07-05
- 1.0.3 — 2015-05-29
- 1.0.2 — 2014-09-15
- 1.0.1 — 2014-09-12
- 1.0.0 — 2014-09-11
- … 2 more at https://npm.io/package/bossy/versions

## README

# bossy

Command line options parser.

[![Build Status](https://secure.travis-ci.org/hapijs/bossy.png)](http://travis-ci.org/hapijs/bossy)

Lead Maintainer - [Eran Hammer](https://github.com/hueniverse)


## Usage

```js
var Bossy = require('bossy');

var definition = {
    h: {
        description: 'Show help',
        alias: 'help',
        type: 'boolean'
    },
    n: {
        description: 'Show your name',
        alias: 'name'
    }
};


var args = Bossy.parse(definition);

if (args instanceof Error) {
    console.error(args.message);
    return;
}

if (args.h || !args.n) {
    console.log(Bossy.usage(definition, 'hello -n <name>'));
    return;
}

console.log('Hello ' + args.n);
console.log('Hello ' + args.name);
```

## Methods

### `parse(definition, [options])`

Expects a *bossy* definition object and will return the parsed `process.argv` arguments provided.  If there is an error
then the return value will be an `instanceof Error`.

Options accepts the following keys:
* `argv` - custom argv array value.  Defaults to process.argv.

### `usage(definition, [usage], [options])`

Format a  *bossy* definition object for display in the console.  If `usage` is provided the returned value will
include the usage value formatted at the top of the message.

Options accepts the following keys:
* `colors` - Determines if colors are enabled when formatting usage.  Defaults to whatever TTY supports.


## Definition Object

The definition object should be structured with each object key representing the short form of an available command
line argument.  Each argument key supports the following properties:

* `alias`: A string or array of strings that can also be used as the argument name.  For example:
```
h: {
    alias: 'help'
}
```

* `type`: Available types are: `boolean`, `range`, `number`, `string`, and `help`.  Defaults to `string`.

    `help` is a special type that allows the switch to be executed even though
    other paramters are required. Use case is to display a help message and
    quit. This will bypass all other errors, so be sure to capture it. It
    behaves like a `boolean`.

* `multiple` : Boolean to indicate if the same argument can be provided multiple times. If true, the parsed value
will always be an array of `type`'s. Defaults to `false`.

* `description`: Description message that will be returned with usage information.

* `require`: Boolean to indicate if the argument is required.  Defaults to `false`

* `default`: A default value to assign to the argument if its not provided as an argument.

* `valid`: A value or array of values that the argument is allowed to equal.

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