# command-line-args

> A mature, feature-complete library to parse command-line options.

Latest version **6.0.2** (published 2026-03-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install command-line-args
pnpm add command-line-args
yarn add command-line-args
bun add command-line-args
```

## Health

**Score 63/100 (C)** — status: active.

Positive: has types package; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.0.2 |
| Published | 2026-03-23 |
| First published | 2014-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/command-line-args) |
| Module format | ESM |
| Node | >=12.20 |
| Dependencies | 4 |
| Unpacked size | 66.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 719 |
| Author | Lloyd Brookes |
| Maintainers | 75lb |
| Keywords | argv, parse, argument, args, option, options, parser, parsing, cli, command, line |

## Links

- npm: https://www.npmjs.com/package/command-line-args
- Repository: https://github.com/75lb/command-line-args
- Homepage: https://github.com/75lb/command-line-args#readme
- Issues: https://github.com/75lb/command-line-args/issues
- npm.io page: https://npm.io/package/command-line-args

## Dependencies (4)

- [typical](https://npm.io/package/typical.md) ^7.3.0
- [array-back](https://npm.io/package/array-back.md) ^6.2.3
- [find-replace](https://npm.io/package/find-replace.md) ^5.0.2
- [lodash.camelcase](https://npm.io/package/lodash.camelcase.md) ^4.3.0

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

- 6.0.2 (latest) — 2026-03-23
- 6.0.1 — 2024-10-28
- 6.0.0 — 2024-07-05
- 5.2.1 — 2022-01-29
- 5.2.0 — 2021-07-29
- 5.1.3 — 2021-07-12
- 5.1.2 — 2021-07-11
- 5.1.1 — 2019-03-31
- 5.1.0 — 2019-03-24
- 6.0.0-preview.1 — 2018-06-25
- 5.0.2 — 2018-02-07
- 5.0.1 — 2018-01-19
- 5.0.0 — 2018-01-17
- 5.0.0-alpha.2 — 2018-01-17
- 5.0.0-alpha.1 — 2018-01-16
- … 61 more at https://npm.io/package/command-line-args/versions

## README

[![view on npm](https://badgen.net/npm/v/command-line-args)](https://www.npmjs.org/package/command-line-args)
[![npm module downloads](https://badgen.net/npm/dt/command-line-args)](https://www.npmjs.org/package/command-line-args)
[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/command-line-args)](https://github.com/75lb/command-line-args/network/dependents?dependent_type=REPOSITORY)
[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/command-line-args)](https://github.com/75lb/command-line-args/network/dependents?dependent_type=PACKAGE)
[![Node.js CI](https://github.com/75lb/command-line-args/actions/workflows/node.js.yml/badge.svg)](https://github.com/75lb/command-line-args/actions/workflows/node.js.yml)

***Upgraders, please read the [release notes](https://github.com/75lb/command-line-args/releases)***

# command-line-args

A mature, feature-complete library to parse command-line options.

## Synopsis

You can set options using the main notation standards ([learn more](https://github.com/75lb/command-line-args/wiki/Notation-rules)). These commands are all equivalent, setting the same values:
```
$ example --verbose --timeout=1000 --src one.js --src two.js
$ example --verbose --timeout 1000 --src one.js two.js
$ example -vt 1000 --src one.js two.js
$ example -vt 1000 one.js two.js
```

To access the values, first create a list of [option definitions](https://github.com/75lb/command-line-args/blob/master/doc/option-definition.md) describing the options your application accepts. The [`type`](https://github.com/75lb/command-line-args/blob/master/doc/option-definition.md#optiontype--function) property is a setter function (the value supplied is passed through this), giving you full control over the value received.

```js
const optionDefinitions = [
  { name: 'verbose', alias: 'v', type: Boolean },
  { name: 'src', type: String, multiple: true, defaultOption: true },
  { name: 'timeout', alias: 't', type: Number }
]
```

Next, parse the options using [commandLineArgs()](https://github.com/75lb/command-line-args/blob/master/doc/API.md#commandlineargsoptiondefinitions-options--object-):

```js
import commandLineArgs from 'command-line-args'
const options = commandLineArgs(optionDefinitions)
```

`options` now looks like this:

```js
{
  src: [
    'one.js',
    'two.js'
  ],
  verbose: true,
  timeout: 1000
}
```

### Advanced usage

Beside the above typical usage, you can configure command-line-args to accept more advanced syntax forms.

* [Command-based syntax](https://github.com/75lb/command-line-args/wiki/Implement-command-parsing-(git-style)) (git style) in the form:

  ```
  $ executable <command> [options]
  ```

  For example.

  ```
  $ git commit --squash -m "This is my commit message"
  ```

* [Command and sub-command syntax](https://github.com/75lb/command-line-args/wiki/Implement-multiple-command-parsing-(docker-style)) (docker style) in the form:

  ```
  $ executable <command> [options] <sub-command> [options]
  ```

  For example.

  ```
  $ docker run --detached --image centos bash -c yum install -y httpd
  ```

## Usage guide generation

A usage guide (typically printed when `--help` is set) can be generated using [command-line-usage](https://github.com/75lb/command-line-usage). See the examples below and [read the documentation](https://github.com/75lb/command-line-usage) for instructions how to create them.

A typical usage guide example.

![usage](https://raw.githubusercontent.com/75lb/command-line-usage/master/example/screens/footer.png)

The [polymer-cli](https://github.com/Polymer/polymer-cli/) usage guide is a good real-life example.

![usage](https://raw.githubusercontent.com/75lb/command-line-usage/master/example/screens/polymer.png)

## Further Reading

There is plenty more to learn, please see [the wiki](https://github.com/75lb/command-line-args/wiki) for examples and documentation.

## Install

```sh
$ npm install command-line-args --save
```
* * *

&copy; 2014-26 [Lloyd Brookes](https://github.com/75lb) \<opensource@75lb.com\>.

Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).

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