Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

command-line-args

> 包管理
Open source

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

720 stars0 likes1 views
WebsiteGitHub

About

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

Upgraders, please read the release notes

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). 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 describing the options your application accepts. The type property is a setter function (the value supplied is passed through this), giving you full control over the value received.

javascript
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():

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

options now looks like this:

javascript
{
  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 (git style) in the form:

    $ executable  [options]

    For example.

    $ git commit --squash -m "This is my commit message"
  • Command and sub-command syntax (docker style) in the form:

    $ executable  [options]  [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. See the examples below and read the documentation for instructions how to create them.

A typical usage guide example.

The polymer-cli usage guide is a good real-life example.

Further Reading

There is plenty more to learn, please see the wiki for examples and documentation.

Install

bash
$ npm install command-line-args --save

© 2014-26 Lloyd Brookes .

Documented by jsdoc-to-markdown.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptargvcommand-line-parsergetoptnodejs-modules

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category包管理
PricingOpen source

> Related tools

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image