5.2.1 • Published 2 years ago

command-line-args v5.2.1

Weekly downloads
642,628
License
MIT
Repository
github
Last release
2 years ago

view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI Coverage Status js-standard-style

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.

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

const commandLineArgs = require('command-line-args')
const options = commandLineArgs(optionDefinitions)

options now looks like this:

{
  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 <command> [options]

    For example.

    $ git commit --squash -m "This is my commit message"
  • Command and sub-command syntax (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. See the examples below and read the documentation for instructions how to create them.

A typical usage guide example.

usage

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

usage

Further Reading

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

Install

$ npm install command-line-args --save

© 2014-22 Lloyd Brookes \75pound@gmail.com\. Documented by jsdoc-to-markdown.

vuquangchien-ynab-converter-v2vuquangchien-ynab-converter-v3@acceleratxr/licensingcreate-czyvite@ledgerhq/live-clinode-spfm@quasimatic/castapi-doublemyfirstvidteqtestprogsp-server-initializer@cotep/role-and-task@office-iss/rex-win32-symbolsfile-server-expressjoni7777-sp-test@pegasusspiele/missing-orders@pegasusspiele/peg-missing-ordersstub-server-with-uiactive-react-scriptsdependency-list-to-markdownswagger-previewpreview-builder@ranb2002/prpl-server@preons/clifdbtop-testweb3daggerzzzpgservlingquick-epexpress-gen-ts@sentry/quicktype-with-markdownteamgitsql-to-apipixel-taggerexecutable-helpers@pegasusspiele/missing-orders-cli@codesteps/codesteps-cli@testwizard/boilerplate-session-testwizardbugsnag-react-native-clicustom_node_minifynode-red-contrib-vdoodocmodel-clidxp-console-iacenforcetabsdesq-staticdrupedrupe-env@drupe/cherry@drupe/core@drupe/env@npmineral/local-storage-apiunova-nodes-contracts@diviniumchain/unova-node-contractstsagdelp.ptenapso-graphdb-cli@noggin/elastic-noggin-utilsms-express-clims-react-climsdc-clighatamarcao-stt-experimentmarcao-wa-experimentunova-node-contract@pboi20/svgbundleemgen-auth-proxypwc-code-generator@socialgorithm/tic-tac-toe-game-server@socialgorithm/ultimate-ttt-game-server@webinmars/mars-awesomenpm-git-lab-testnpm-test-public-packagenpm-test-public-package-express-example@ngneat/optimizegrade-io@xvlcw/wavdio-expresslogdmsauthfeed-wallpaperuniconv@src-works/npm-ts-gulpsemantic-version-managerrmr-specscrtcwl-nuxt-generate-component@kappasquare/eskimoearlycause-molecular-sequences-generator@yippiecloud/cdk-stack-static@yippiecloud/cliprueba-nacho-5prueba-nacho-6prueba-nacho-7i18n-deepl-translator@airboat/adapters-localunova-node-contractsseek-asia-style-guidenewman-dr@ton-actions/tonos-se-package-test2@unovablockchain/unova-node-contractsdebox-sequelize-auto-migrationssvg2sfddns-nameserver
5.2.1

2 years ago

5.2.0

3 years ago

5.1.3

3 years ago

5.1.2

3 years ago

5.1.1

5 years ago

5.1.0

5 years ago

6.0.0-preview.1

6 years ago

5.0.2

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

5.0.0-alpha.2

6 years ago

5.0.0-alpha.1

6 years ago

5.0.0-alpha.0

6 years ago

4.0.7

7 years ago

4.0.6

7 years ago

4.0.5

7 years ago

4.0.4

7 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

4.0.0-1

7 years ago

4.0.0-0

7 years ago

3.0.5

7 years ago

3.0.4

7 years ago

3.0.3

7 years ago

3.0.3-0

7 years ago

3.0.2

7 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.1.6

8 years ago

2.1.5

8 years ago

2.1.4

8 years ago

2.1.3

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

1.1.0-1

9 years ago

1.1.0-0

9 years ago

1.0.0-4

9 years ago

1.0.0-3

9 years ago

1.0.0-2

9 years ago

1.0.0-1

9 years ago

1.0.0-0

9 years ago

0.5.9

9 years ago

0.5.8

9 years ago

0.5.7

9 years ago

0.5.6

9 years ago

0.5.5

9 years ago

0.5.4

9 years ago

0.5.3

9 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago