# cmd-args

> A simple command-line argument parser for NodeJS command-line tools.

Latest version **2.0.7** (published 2020-08-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install cmd-args
pnpm add cmd-args
yarn add cmd-args
bun add cmd-args
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.7 |
| Published | 2020-08-17 |
| First published | 2016-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 66 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Michaelangelo Jong |
| Maintainers | mike96angelo |
| Keywords | cli, cmd, command, line, args, argv, flags, parser |

## Links

- npm: https://www.npmjs.com/package/cmd-args
- Repository: https://github.com/Mike96Angelo/cmd-args
- Homepage: https://github.com/Mike96Angelo/cmd-args#readme
- Issues: https://github.com/Mike96Angelo/cmd-args/issues
- npm.io page: https://npm.io/package/cmd-args

## 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

- 2.0.7 (latest) — 2020-08-17
- 2.0.6 — 2020-08-16
- 2.0.5 — 2020-08-16
- 2.0.4 — 2020-08-16
- 2.0.3 — 2020-08-16
- 2.0.2 — 2020-08-16
- 2.0.1 — 2020-08-16
- 2.0.0 — 2020-08-16
- 2.0.0-alpha-3 — 2020-08-15
- 2.0.0-alpha-2 — 2020-08-15
- 2.0.0-alpha — 2020-08-15
- 1.0.0 — 2016-09-30
- 0.1.0 — 2016-09-26
- 0.0.2 — 2016-09-26
- 0.0.1 — 2016-09-26

## README

# cmd-args

[![GitHub release](https://img.shields.io/github/release/Mike96angelo/cmd-args.svg?maxAge=21600)](https://github.com/Mike96Angelo/cmd-args)
[![npm version](https://img.shields.io/npm/v/cmd-args.svg?maxAge=21600)](https://www.npmjs.com/package/cmd-args)
[![npm downloads](https://img.shields.io/npm/dm/cmd-args.svg?maxAge=604800)](https://www.npmjs.com/package/cmd-args)
[![npm downloads](https://img.shields.io/npm/dt/cmd-args.svg?maxAge=604800)](https://www.npmjs.com/package/cmd-args)

A simple command-line argument parser for NodeJS command-line tools.

Install:

```
$ npm install cmd-args
```

example:

```typescript
import { createArgParser } from 'cmd-args'

const myParser = createArgParser({
  cmd: 'my-cmd',
  title: 'My CMD',
  description: 'my-cmd description...',
  help: true,
  version: 'v1.0.0',
  run: (options) => {
    console.log(options)
  },
  options: [
    {
      type: 'flag',
      key: 'verbose',
      alias: 'v',
      description: 'Enable verbose mode.',
    },
    {
      type: 'option',
      key: 'output-file',
      alias: 'o',
      description:
        'Specifies location to write the output file. If not set the output will go to stdout.',
    },
  ],
  arguments: [
    {
      key: 'input-files',
      description: 'List of input files to be used.',
      multi: true,
      required: true,
    },
  ],
})

myParser.run()
```

example run:

```bash
$ my-cmd --version
```

outputs:

```
v1.0.0
```

example run:

```bash
$ my-cmd --help
```

outputs:

```
My CMD

my-cmd description...

Usage:
  my-cmd [OPTIONS] --help
  OR
  my-cmd [OPTIONS] <input-files>...

my-cmd [OPTIONS]:
      --version            Prints version of this command.
      --help               Prints help text for this command.
  -v, --verbose            Enable verbose mode.
  -o, --output-file[=ARG]  Specifies location to write the output file. If not set the output will go to stdout.

ARGUMENTS:
  input-files=ARG+  List of input files to be used.

```

example run:

```bash
$ my-cmd file1 file2
```

outputs:

```json
{
  "verbose": false,
  "input-files": ["file1", "file2"]
}
```

example run:

```bash
$ my-cmd file1 file2 -o file-out
```

outputs:

```json
{
  "verbose": false,
  "input-files": ["file1", "file2"],
  "output-file": "file-out"
}
```

example run:

```bash
$ my-cmd file1 file2 --output-file file-out
```

outputs:

```json
{
  "verbose": false,
  "input-files": ["file1", "file2"],
  "output-file": "file-out"
}
```

example run:

```bash
$ my-cmd -v file1 file2 --output-file file-out
```

outputs:

```json
{
  "verbose": true,
  "input-files": ["file1", "file2"],
  "output-file": "file-out"
}
```

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