{"_id":"@expo/commander","_rev":"1017740","name":"@expo/commander","description":"the complete solution for node.js command-line programs","dist-tags":{"latest":"5.0.0"},"maintainers":[{"name":"andyboythekid","email":"andyboythekid@gmail.com"},{"name":"bbarthec","email":"bartlomiejbukowski.b+npm@gmail.com"},{"name":"brentvatne","email":"brentvatne@gmail.com"},{"name":"bycedric","email":"me@bycedric.com"},{"name":"ccheever","email":"ccheever@gmail.com"},{"name":"charliecruzan","email":"charliecruzan@gmail.com"},{"name":"dsokal","email":"dominiksokal@gmail.com"},{"name":"esamelson","email":"eric@expo.io"},{"name":"evanbacon","email":"baconbrix@gmail.com"},{"name":"fiber-god","email":"datwheat@gmail.com"},{"name":"fson","email":"ville.immonen@iki.fi"},{"name":"ide","email":"ide+npm@jameside.com"},{"name":"jkhales","email":"jonathan@expo.io"},{"name":"jonsamp","email":"sampjon@gmail.com"},{"name":"kudochien","email":"ckchien@gmail.com"},{"name":"quinlanj","email":"quinlanjung@gmail.com"},{"name":"tcdavis","email":"tc@expo.io"},{"name":"tsapeta","email":"sapeta.tomasz@gmail.com"},{"name":"wkozyra","email":"wojciech.kozyra@swmansion.com"},{"name":"wschurman","email":"wschurman@gmail.com"}],"time":{"modified":"2021-09-28T15:37:58.000Z","created":"2019-06-19T08:39:04.356Z","5.0.0":"2020-04-14T16:18:09.556Z","2.21.1":"2019-06-25T09:19:32.418Z","2.21.0":"2019-06-24T09:03:04.567Z","2.20.0":"2019-06-19T08:39:04.356Z"},"users":{},"author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"repository":{"type":"git","url":"git+https://github.com/tj/commander.js.git"},"versions":{"5.0.0":{"name":"@expo/commander","version":"5.0.0","description":"the complete solution for node.js command-line programs","keywords":["commander","command","option","parser","cli","argument","args","argv"],"author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/tj/commander.js.git"},"scripts":{"lint":"eslint index.js \"tests/**/*.js\"","typescript-lint":"eslint typings/*.ts","test":"jest && npm run test-typings","test-typings":"tsc -p tsconfig.json"},"main":"index","dependencies":{"ansi-regex":"5.0.0","chalk":"^3.0.0","strip-ansi":"6.0.0"},"devDependencies":{"@types/jest":"^25.1.4","@types/node":"^12.12.26","@typescript-eslint/eslint-plugin":"^2.23.0","eslint":"^6.8.0","eslint-config-standard-with-typescript":"^14.0.0","eslint-plugin-jest":"^23.8.2","jest":"^25.1.0","standard":"^14.3.1","typescript":"^3.7.5"},"typings":"typings/index.d.ts","engines":{"node":">= 6"},"gitHead":"dfa2934c1d53a6a32c3698af73023bea402bda16","bugs":{"url":"https://github.com/tj/commander.js/issues"},"homepage":"https://github.com/tj/commander.js#readme","_id":"@expo/commander@5.0.0","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"shasum":"cb0447e13326ddcefd87eb5ab6961c8c8bdc7066","size":29658,"noattachment":false,"key":"/@expo/commander/-/@expo/commander-5.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@expo/commander/download/@expo/commander-5.0.0.tgz"},"maintainers":[{"name":"andyboythekid","email":"andyboythekid@gmail.com"},{"name":"bbarthec","email":"bartlomiejbukowski.b+npm@gmail.com"},{"name":"brentvatne","email":"brentvatne@gmail.com"},{"name":"bycedric","email":"me@bycedric.com"},{"name":"ccheever","email":"ccheever@gmail.com"},{"name":"charliecruzan","email":"charliecruzan@gmail.com"},{"name":"dsokal","email":"dominiksokal@gmail.com"},{"name":"esamelson","email":"eric@expo.io"},{"name":"evanbacon","email":"baconbrix@gmail.com"},{"name":"fiber-god","email":"datwheat@gmail.com"},{"name":"fson","email":"ville.immonen@iki.fi"},{"name":"ide","email":"ide+npm@jameside.com"},{"name":"jkhales","email":"jonathan@expo.io"},{"name":"jonsamp","email":"sampjon@gmail.com"},{"name":"kudochien","email":"ckchien@gmail.com"},{"name":"quinlanj","email":"quinlanjung@gmail.com"},{"name":"tcdavis","email":"tc@expo.io"},{"name":"tsapeta","email":"sapeta.tomasz@gmail.com"},{"name":"wkozyra","email":"wojciech.kozyra@swmansion.com"},{"name":"wschurman","email":"wschurman@gmail.com"}],"_npmUser":{"name":"bbarthec","email":"bartlomiejbukowski.b@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/commander_5.0.0_1586881089415_0.8111628257956793"},"_hasShrinkwrap":false,"publish_time":1586881089556,"_cnpm_publish_time":1586881089556},"2.21.1":{"name":"@expo/commander","version":"2.21.1","description":"the complete solution for node.js command-line programs","keywords":["commander","command","option","parser"],"author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/tj/commander.js.git"},"scripts":{"lint":"eslint index.js","test":"node test/run.js && npm run test-typings","test-typings":"tsc -p tsconfig.json"},"main":"index","dependencies":{"chalk":"^2.4.2"},"devDependencies":{"@types/node":"^10.11.3","eslint":"^5.16.0","should":"^13.2.3","sinon":"^6.3.4","standard":"^12.0.1","ts-node":"^7.0.1","typescript":"^2.9.2"},"typings":"typings/index.d.ts","gitHead":"dbf35edeef73391aa58d00cff6bef58a9557ae6d","bugs":{"url":"https://github.com/tj/commander.js/issues"},"homepage":"https://github.com/tj/commander.js#readme","_id":"@expo/commander@2.21.1","_nodeVersion":"10.11.0","_npmVersion":"6.9.0","dist":{"shasum":"17dd83850a182f4745bf60f55cba0c2d6aa638a7","size":20226,"noattachment":false,"key":"/@expo/commander/-/@expo/commander-2.21.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@expo/commander/download/@expo/commander-2.21.1.tgz"},"maintainers":[{"name":"andyboythekid","email":"andyboythekid@gmail.com"},{"name":"bbarthec","email":"bartlomiejbukowski.b+npm@gmail.com"},{"name":"brentvatne","email":"brentvatne@gmail.com"},{"name":"bycedric","email":"me@bycedric.com"},{"name":"ccheever","email":"ccheever@gmail.com"},{"name":"charliecruzan","email":"charliecruzan@gmail.com"},{"name":"dsokal","email":"dominiksokal@gmail.com"},{"name":"esamelson","email":"eric@expo.io"},{"name":"evanbacon","email":"baconbrix@gmail.com"},{"name":"fiber-god","email":"datwheat@gmail.com"},{"name":"fson","email":"ville.immonen@iki.fi"},{"name":"ide","email":"ide+npm@jameside.com"},{"name":"jkhales","email":"jonathan@expo.io"},{"name":"jonsamp","email":"sampjon@gmail.com"},{"name":"kudochien","email":"ckchien@gmail.com"},{"name":"quinlanj","email":"quinlanjung@gmail.com"},{"name":"tcdavis","email":"tc@expo.io"},{"name":"tsapeta","email":"sapeta.tomasz@gmail.com"},{"name":"wkozyra","email":"wojciech.kozyra@swmansion.com"},{"name":"wschurman","email":"wschurman@gmail.com"}],"_npmUser":{"name":"tsapeta","email":"sapeta.tomasz@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/commander_2.21.1_1561454372276_0.13693433686521006"},"_hasShrinkwrap":false,"publish_time":1561454372418,"_cnpm_publish_time":1561454372418},"2.21.0":{"name":"@expo/commander","version":"2.21.0","description":"the complete solution for node.js command-line programs","keywords":["commander","command","option","parser"],"author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/tj/commander.js.git"},"scripts":{"lint":"eslint index.js","test":"node test/run.js && npm run test-typings","test-typings":"tsc -p tsconfig.json"},"main":"index","dependencies":{"chalk":"^2.4.2"},"devDependencies":{"@types/node":"^10.11.3","eslint":"^5.16.0","should":"^13.2.3","sinon":"^6.3.4","standard":"^12.0.1","ts-node":"^7.0.1","typescript":"^2.9.2"},"typings":"typings/index.d.ts","gitHead":"cd19bf16d485fb13bbe963c14d5afd4d5739d690","bugs":{"url":"https://github.com/tj/commander.js/issues"},"homepage":"https://github.com/tj/commander.js#readme","_id":"@expo/commander@2.21.0","_nodeVersion":"10.11.0","_npmVersion":"6.9.0","dist":{"shasum":"72ba24ec68b4cae16b3006c55de50883d2a9fd85","size":20233,"noattachment":false,"key":"/@expo/commander/-/@expo/commander-2.21.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@expo/commander/download/@expo/commander-2.21.0.tgz"},"maintainers":[{"name":"andyboythekid","email":"andyboythekid@gmail.com"},{"name":"bbarthec","email":"bartlomiejbukowski.b+npm@gmail.com"},{"name":"brentvatne","email":"brentvatne@gmail.com"},{"name":"bycedric","email":"me@bycedric.com"},{"name":"ccheever","email":"ccheever@gmail.com"},{"name":"charliecruzan","email":"charliecruzan@gmail.com"},{"name":"dsokal","email":"dominiksokal@gmail.com"},{"name":"esamelson","email":"eric@expo.io"},{"name":"evanbacon","email":"baconbrix@gmail.com"},{"name":"fiber-god","email":"datwheat@gmail.com"},{"name":"fson","email":"ville.immonen@iki.fi"},{"name":"ide","email":"ide+npm@jameside.com"},{"name":"jkhales","email":"jonathan@expo.io"},{"name":"jonsamp","email":"sampjon@gmail.com"},{"name":"kudochien","email":"ckchien@gmail.com"},{"name":"quinlanj","email":"quinlanjung@gmail.com"},{"name":"tcdavis","email":"tc@expo.io"},{"name":"tsapeta","email":"sapeta.tomasz@gmail.com"},{"name":"wkozyra","email":"wojciech.kozyra@swmansion.com"},{"name":"wschurman","email":"wschurman@gmail.com"}],"_npmUser":{"name":"tsapeta","email":"sapeta.tomasz@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/commander_2.21.0_1561366984390_0.8333265239358942"},"_hasShrinkwrap":false,"publish_time":1561366984567,"_cnpm_publish_time":1561366984567},"2.20.0":{"name":"@expo/commander","version":"2.20.0","description":"the complete solution for node.js command-line programs","keywords":["commander","command","option","parser"],"author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/tj/commander.js.git"},"scripts":{"lint":"eslint index.js","test":"node test/run.js && npm run test-typings","test-typings":"tsc -p tsconfig.json"},"main":"index","dependencies":{},"devDependencies":{"@types/node":"^10.11.3","eslint":"^5.16.0","should":"^13.2.3","sinon":"^6.3.4","standard":"^12.0.1","ts-node":"^7.0.1","typescript":"^2.9.2"},"typings":"typings/index.d.ts","gitHead":"1b2b95016eb92bea53a2bd7bcb9d530cd554d95c","bugs":{"url":"https://github.com/tj/commander.js/issues"},"homepage":"https://github.com/tj/commander.js#readme","_id":"@expo/commander@2.20.0","_nodeVersion":"10.11.0","_npmVersion":"6.9.0","dist":{"shasum":"f598a404fd09e8eb0144ffaf517450d794e6d8fb","size":19527,"noattachment":false,"key":"/@expo/commander/-/@expo/commander-2.20.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@expo/commander/download/@expo/commander-2.20.0.tgz"},"maintainers":[{"name":"andyboythekid","email":"andyboythekid@gmail.com"},{"name":"bbarthec","email":"bartlomiejbukowski.b+npm@gmail.com"},{"name":"brentvatne","email":"brentvatne@gmail.com"},{"name":"bycedric","email":"me@bycedric.com"},{"name":"ccheever","email":"ccheever@gmail.com"},{"name":"charliecruzan","email":"charliecruzan@gmail.com"},{"name":"dsokal","email":"dominiksokal@gmail.com"},{"name":"esamelson","email":"eric@expo.io"},{"name":"evanbacon","email":"baconbrix@gmail.com"},{"name":"fiber-god","email":"datwheat@gmail.com"},{"name":"fson","email":"ville.immonen@iki.fi"},{"name":"ide","email":"ide+npm@jameside.com"},{"name":"jkhales","email":"jonathan@expo.io"},{"name":"jonsamp","email":"sampjon@gmail.com"},{"name":"kudochien","email":"ckchien@gmail.com"},{"name":"quinlanj","email":"quinlanjung@gmail.com"},{"name":"tcdavis","email":"tc@expo.io"},{"name":"tsapeta","email":"sapeta.tomasz@gmail.com"},{"name":"wkozyra","email":"wojciech.kozyra@swmansion.com"},{"name":"wschurman","email":"wschurman@gmail.com"}],"_npmUser":{"name":"tsapeta","email":"sapeta.tomasz@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/commander_2.20.0_1560933544210_0.46411157253642665"},"_hasShrinkwrap":false,"publish_time":1560933544356,"_cnpm_publish_time":1560933544356}},"readme":"# Commander.js\n\n[![Build Status](https://api.travis-ci.org/tj/commander.js.svg?branch=master)](http://travis-ci.org/tj/commander.js)\n[![NPM Version](http://img.shields.io/npm/v/commander.svg?style=flat)](https://www.npmjs.org/package/commander)\n[![NPM Downloads](https://img.shields.io/npm/dm/commander.svg?style=flat)](https://npmcharts.com/compare/commander?minimal=true)\n[![Install Size](https://packagephobia.now.sh/badge?p=commander)](https://packagephobia.now.sh/result?p=commander)\n\nThe complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/commander-rb/commander).\n\nRead this in other languages: English | [简体中文](./Readme_zh-CN.md)\n\n- [Commander.js](#commanderjs)\n  - [Installation](#installation)\n  - [Declaring _program_ variable](#declaring-program-variable)\n  - [Options](#options)\n    - [Common option types, boolean and value](#common-option-types-boolean-and-value)\n    - [Default option value](#default-option-value)\n    - [Other option types, negatable boolean and flag|value](#other-option-types-negatable-boolean-and-flagvalue)\n    - [Custom option processing](#custom-option-processing)\n    - [Required option](#required-option)\n    - [Version option](#version-option)\n  - [Commands](#commands)\n    - [Specify the argument syntax](#specify-the-argument-syntax)\n    - [Action handler (sub)commands](#action-handler-subcommands)\n    - [Stand-alone executable (sub)commands](#stand-alone-executable-subcommands)\n  - [Automated help](#automated-help)\n    - [Custom help](#custom-help)\n    - [.usage and .name](#usage-and-name)\n    - [.help(cb)](#helpcb)\n    - [.outputHelp(cb)](#outputhelpcb)\n    - [.helpInformation()](#helpinformation)\n    - [.helpOption(flags, description)](#helpoptionflags-description)\n    - [.addHelpCommand()](#addhelpcommand)\n  - [Custom event listeners](#custom-event-listeners)\n  - [Bits and pieces](#bits-and-pieces)\n    - [.parse() and .parseAsync()](#parse-and-parseasync)\n    - [Avoiding option name clashes](#avoiding-option-name-clashes)\n    - [TypeScript](#typescript)\n    - [createCommand()](#createcommand)\n    - [Node options such as `--harmony`](#node-options-such-as---harmony)\n    - [Debugging stand-alone executable subcommands](#debugging-stand-alone-executable-subcommands)\n    - [Override exit handling](#override-exit-handling)\n  - [Examples](#examples)\n  - [License](#license)\n  - [Support](#support)\n    - [Commander for enterprise](#commander-for-enterprise)\n\n## Installation\n\n```bash\nnpm install commander\n```\n\n## Declaring _program_ variable\n\nCommander exports a global object which is convenient for quick programs.\nThis is used in the examples in this README for brevity.\n\n```js\nconst { program } = require('commander');\nprogram.version('0.0.1');\n```\n\nFor larger programs which may use commander in multiple ways, including unit testing, it is better to create a local Command object to use.\n\n ```js\n const { Command } = require('commander');\n const program = new Command();\n program.version('0.0.1');\n ```\n\n## Options\n\nOptions are defined with the `.option()` method, also serving as documentation for the options. Each option can have a short flag (single character) and a long name, separated by a comma or space or vertical bar ('|').\n\nThe options can be accessed as properties on the Command object. Multi-word options such as \"--template-engine\" are camel-cased, becoming `program.templateEngine` etc. See also optional new behaviour to [avoid name clashes](#avoiding-option-name-clashes).\n\nMultiple short flags may optionally be combined in a single argument following the dash: boolean flags, the last flag may take a value, and the value.\nFor example `-a -b -p 80` may be written as `-ab -p80` or even `-abp80`.\n\nYou can use `--` to indicate the end of the options, and any remaining arguments will be used without being interpreted.\nThis is particularly useful for passing options through to another\ncommand, like: `do -- git --version`.\n\nOptions on the command line are not positional, and can be specified before or after other command arguments.\n\n### Common option types, boolean and value\n\nThe two most used option types are a boolean flag, and an option which takes a value (declared using angle brackets). Both are `undefined` unless specified on command line.\n\n```js\nconst { program } = require('commander');\n\nprogram\n  .option('-d, --debug', 'output extra debugging')\n  .option('-s, --small', 'small pizza size')\n  .option('-p, --pizza-type <type>', 'flavour of pizza');\n\nprogram.parse(process.argv);\n\nif (program.debug) console.log(program.opts());\nconsole.log('pizza details:');\nif (program.small) console.log('- small pizza size');\nif (program.pizzaType) console.log(`- ${program.pizzaType}`);\n```\n\n```bash\n$ pizza-options -d\n{ debug: true, small: undefined, pizzaType: undefined }\npizza details:\n$ pizza-options -p\nerror: option '-p, --pizza-type <type>' argument missing\n$ pizza-options -ds -p vegetarian\n{ debug: true, small: true, pizzaType: 'vegetarian' }\npizza details:\n- small pizza size\n- vegetarian\n$ pizza-options --pizza-type=cheese\npizza details:\n- cheese\n```\n\n`program.parse(arguments)` processes the arguments, leaving any args not consumed by the program options in the `program.args` array.\n\n### Default option value\n\nYou can specify a default value for an option which takes a value.\n\n```js\nconst { program } = require('commander');\n\nprogram\n  .option('-c, --cheese <type>', 'add the specified type of cheese', 'blue');\n\nprogram.parse(process.argv);\n\nconsole.log(`cheese: ${program.cheese}`);\n```\n\n```bash\n$ pizza-options\ncheese: blue\n$ pizza-options --cheese stilton\ncheese: stilton\n```\n\n### Other option types, negatable boolean and flag|value\n\nYou can specify a boolean option long name with a leading `no-` to set the option value to false when used.\nDefined alone this also makes the option true by default.\n\nIf you define `--foo` first, adding `--no-foo` does not change the default value from what it would\notherwise be. You can specify a default boolean value for a boolean flag and it can be overridden on command line.\n\n```js\nconst { program } = require('commander');\n\nprogram\n  .option('--no-sauce', 'Remove sauce')\n  .option('--cheese <flavour>', 'cheese flavour', 'mozzarella')\n  .option('--no-cheese', 'plain with no cheese')\n  .parse(process.argv);\n\nconst sauceStr = program.sauce ? 'sauce' : 'no sauce';\nconst cheeseStr = (program.cheese === false) ? 'no cheese' : `${program.cheese} cheese`;\nconsole.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`);\n```\n\n```bash\n$ pizza-options\nYou ordered a pizza with sauce and mozzarella cheese\n$ pizza-options --sauce\nerror: unknown option '--sauce'\n$ pizza-options --cheese=blue\nYou ordered a pizza with sauce and blue cheese\n$ pizza-options --no-sauce --no-cheese\nYou ordered a pizza with no sauce and no cheese\n```\n\nYou can specify an option which functions as a flag but may also take a value (declared using square brackets).\n\n```js\nconst { program } = require('commander');\n\nprogram\n  .option('-c, --cheese [type]', 'Add cheese with optional type');\n\nprogram.parse(process.argv);\n\nif (program.cheese === undefined) console.log('no cheese');\nelse if (program.cheese === true) console.log('add cheese');\nelse console.log(`add cheese type ${program.cheese}`);\n```\n\n```bash\n$ pizza-options\nno cheese\n$ pizza-options --cheese\nadd cheese\n$ pizza-options --cheese mozzarella\nadd cheese type mozzarella\n```\n\n### Custom option processing\n\nYou may specify a function to do custom processing of option values. The callback function receives two parameters, the user specified value and the\nprevious value for the option. It returns the new value for the option.\n\nThis allows you to coerce the option value to the desired type, or accumulate values, or do entirely custom processing.\n\nYou can optionally specify the default/starting value for the option after the function.\n\n```js\nconst { program } = require('commander');\n\nfunction myParseInt(value, dummyPrevious) {\n  // parseInt takes a string and an optional radix\n  return parseInt(value);\n}\n\nfunction increaseVerbosity(dummyValue, previous) {\n  return previous + 1;\n}\n\nfunction collect(value, previous) {\n  return previous.concat([value]);\n}\n\nfunction commaSeparatedList(value, dummyPrevious) {\n  return value.split(',');\n}\n\nprogram\n  .option('-f, --float <number>', 'float argument', parseFloat)\n  .option('-i, --integer <number>', 'integer argument', myParseInt)\n  .option('-v, --verbose', 'verbosity that can be increased', increaseVerbosity, 0)\n  .option('-c, --collect <value>', 'repeatable value', collect, [])\n  .option('-l, --list <items>', 'comma separated list', commaSeparatedList)\n;\n\nprogram.parse(process.argv);\n\nif (program.float !== undefined) console.log(`float: ${program.float}`);\nif (program.integer !== undefined) console.log(`integer: ${program.integer}`);\nif (program.verbose > 0) console.log(`verbosity: ${program.verbose}`);\nif (program.collect.length > 0) console.log(program.collect);\nif (program.list !== undefined) console.log(program.list);\n```\n\n```bash\n$ custom -f 1e2\nfloat: 100\n$ custom --integer 2\ninteger: 2\n$ custom -v -v -v\nverbose: 3\n$ custom -c a -c b -c c\n[ 'a', 'b', 'c' ]\n$ custom --list x,y,z\n[ 'x', 'y', 'z' ]\n```\n\n### Required option\n\nYou may specify a required (mandatory) option using `.requiredOption`. The option must have a value after parsing, usually specified on the command line, or perhaps from a default value (say from environment). The method is otherwise the same as `.option` in format, taking flags and description, and optional default value or custom processing.\n\n```js\nconst { program } = require('commander');\n\nprogram\n  .requiredOption('-c, --cheese <type>', 'pizza must have cheese');\n\nprogram.parse(process.argv);\n```\n\n```bash\n$ pizza\nerror: required option '-c, --cheese <type>' not specified\n```\n\n### Version option\n\nThe optional `version` method adds handling for displaying the command version. The default option flags are `-V` and `--version`, and when present the command prints the version number and exits.\n\n```js\nprogram.version('0.0.1');\n```\n\n```bash\n$ ./examples/pizza -V\n0.0.1\n```\n\nYou may change the flags and description by passing additional parameters to the `version` method, using\nthe same syntax for flags as the `option` method. The version flags can be named anything, but a long name is required.\n\n```js\nprogram.version('0.0.1', '-v, --vers', 'output the current version');\n```\n\n## Commands\n\nYou can specify (sub)commands for your top-level command using `.command()` or `.addCommand()`. There are two ways these can be implemented: using an action handler attached to the command, or as a stand-alone executable file (described in more detail later). The subcommands may be nested ([example](./examples/nestedCommands.js)).\n\nIn the first parameter to `.command()` you specify the command name and any command arguments. The arguments may be `<required>` or `[optional]`, and the last argument may also be `variadic...`.\n\nYou can use `.addCommand()` to add an already configured subcommand to the program.\n\nFor example:\n\n```js\n// Command implemented using action handler (description is supplied separately to `.command`)\n// Returns new command for configuring.\nprogram\n  .command('clone <source> [destination]')\n  .description('clone a repository into a newly created directory')\n  .action((source, destination) => {\n    console.log('clone command called');\n  });\n\n// Command implemented using stand-alone executable file (description is second parameter to `.command`)\n// Returns top-level command for adding more commands.\nprogram\n  .command('start <service>', 'start named service')\n  .command('stop [service]', 'stop named service, or all if no name supplied');\n\n// Command prepared separately.\n// Returns top-level command for adding more commands.\nprogram\n  .addCommand(build.makeBuildCommand());\n```\n\nConfiguration options can be passed with the call to `.command()`. Specifying `true` for `opts.noHelp` will remove the command from the generated help output. Specifying `true` for `opts.isDefault` will run the subcommand if no other subcommand is specified ([example](./examples/defaultCommand.js)).\n\n### Specify the argument syntax\n\nYou use `.arguments` to specify the arguments for the top-level command, and for subcommands they are included in the `.command` call. Angled brackets (e.g. `<required>`) indicate required input. Square brackets (e.g. `[optional]`) indicate optional input.\n\n```js\nconst { program } = require('commander');\n\nprogram\n  .version('0.1.0')\n  .arguments('<cmd> [env]')\n  .action(function (cmd, env) {\n    cmdValue = cmd;\n    envValue = env;\n  });\n\nprogram.parse(process.argv);\n\nif (typeof cmdValue === 'undefined') {\n  console.error('no command given!');\n  process.exit(1);\n}\nconsole.log('command:', cmdValue);\nconsole.log('environment:', envValue || \"no environment given\");\n```\n\n The last argument of a command can be variadic, and only the last argument.  To make an argument variadic you\n append `...` to the argument name. For example:\n\n```js\nconst { program } = require('commander');\n\nprogram\n  .version('0.1.0')\n  .command('rmdir <dir> [otherDirs...]')\n  .action(function (dir, otherDirs) {\n    console.log('rmdir %s', dir);\n    if (otherDirs) {\n      otherDirs.forEach(function (oDir) {\n        console.log('rmdir %s', oDir);\n      });\n    }\n  });\n\nprogram.parse(process.argv);\n```\n\nThe variadic argument is passed to the action handler as an array.\n\n### Action handler (sub)commands\n\nYou can add options to a command that uses an action handler.\nThe action handler gets passed a parameter for each argument you declared, and one additional argument which is the\ncommand object itself. This command argument has the values for the command-specific options added as properties.\n\n```js\nconst { program } = require('commander');\n\nprogram\n  .command('rm <dir>')\n  .option('-r, --recursive', 'Remove recursively')\n  .action(function (dir, cmdObj) {\n    console.log('remove ' + dir + (cmdObj.recursive ? ' recursively' : ''))\n  })\n\nprogram.parse(process.argv)\n```\n\nYou may supply an `async` action handler, in which case you call `.parseAsync` rather than `.parse`.\n\n```js\nasync function run() { /* code goes here */ }\n\nasync function main() {\n  program\n    .command('run')\n    .action(run);\n  await program.parseAsync(process.argv);\n}\n```\n\nA command's options on the command line are validated when the command is used. Any unknown options will be reported as an error.\n\n### Stand-alone executable (sub)commands\n\nWhen `.command()` is invoked with a description argument, this tells Commander that you're going to use stand-alone executables for subcommands.\nCommander will search the executables in the directory of the entry script (like `./examples/pm`) with the name `program-subcommand`, like `pm-install`, `pm-search`.\nYou can specify a custom name with the `executableFile` configuration option.\n\nYou handle the options for an executable (sub)command in the executable, and don't declare them at the top-level.\n\n```js\n// file: ./examples/pm\nconst { program } = require('commander');\n\nprogram\n  .version('0.1.0')\n  .command('install [name]', 'install one or more packages')\n  .command('search [query]', 'search with optional query')\n  .command('update', 'update installed packages', {executableFile: 'myUpdateSubCommand'})\n  .command('list', 'list packages installed', {isDefault: true})\n  .parse(process.argv);\n```\n\nIf the program is designed to be installed globally, make sure the executables have proper modes, like `755`.\n\n## Automated help\n\nThe help information is auto-generated based on the information commander already knows about your program. The default\nhelp option is `-h,--help`. ([example](./examples/pizza))\n\n```bash\n$ node ./examples/pizza --help\nUsage: pizza [options]\n\nAn application for pizzas ordering\n\nOptions:\n  -V, --version        output the version number\n  -p, --peppers        Add peppers\n  -c, --cheese <type>  Add the specified type of cheese (default: \"marble\")\n  -C, --no-cheese      You do not want any cheese\n  -h, --help           display help for command\n```\n\nA `help` command is added by default if your command has subcommands. It can be used alone, or with a subcommand name to show\nfurther help for the subcommand. These are effectively the same if the `shell` program has implicit help:\n\n```bash\nshell help\nshell --help\n\nshell help spawn\nshell spawn --help\n```\n\n### Custom help\n\nYou can display extra information by listening for \"--help\". ([example](./examples/custom-help))\n\n```js\nprogram\n  .option('-f, --foo', 'enable some foo');\n\n// must be before .parse()\nprogram.on('--help', () => {\n  console.log('');\n  console.log('Example call:');\n  console.log('  $ custom-help --help');\n});\n```\n\nYields the following help output:\n\n```Text\nUsage: custom-help [options]\n\nOptions:\n  -f, --foo   enable some foo\n  -h, --help  display help for command\n\nExample call:\n  $ custom-help --help\n```\n\n### .usage and .name\n\nThese allow you to customise the usage description in the first line of the help. The name is otherwise\ndeduced from the (full) program arguments. Given:\n\n```js\nprogram\n  .name(\"my-command\")\n  .usage(\"[global options] command\")\n```\n\nThe help will start with:\n\n```Text\nUsage: my-command [global options] command\n```\n\n### .help(cb)\n\nOutput help information and exit immediately. Optional callback cb allows post-processing of help text before it is displayed.\n\n### .outputHelp(cb)\n\nOutput help information without exiting.\nOptional callback cb allows post-processing of help text before it is displayed.\n\n### .helpInformation()\n\nGet the command help information as a string for processing or displaying yourself. (The text does not include the custom help\nfrom `--help` listeners.)\n\n### .helpOption(flags, description)\n\nOverride the default help flags and description.\n\n```js\nprogram\n  .helpOption('-e, --HELP', 'read more information');\n```\n\n### .addHelpCommand()\n\nYou can explicitly turn on or off the implicit help command with `.addHelpCommand()` and `.addHelpCommand(false)`.\n\nYou can both turn on and customise the help command by supplying the name and description:\n\n```js\nprogram.addHelpCommand('assist [command]', 'show assistance');\n```\n\n## Custom event listeners\n\nYou can execute custom actions by listening to command and option events.\n\n```js\nprogram.on('option:verbose', function () {\n  process.env.VERBOSE = this.verbose;\n});\n\nprogram.on('command:*', function (operands) {\n  console.error(`error: unknown command '${operands[0]}'`);\n  const availableCommands = program.commands.map(cmd => cmd.name());\n  mySuggestBestMatch(operands[0], availableCommands);\n  process.exitCode = 1;\n});\n```\n\n## Bits and pieces\n\n### .parse() and .parseAsync()\n\nThe first argument to `.parse` is the array of strings to parse. You may omit the parameter to implicitly use `process.argv`.\n\nIf the arguments follow different conventions than node you can pass a `from` option in the second parameter:\n\n- 'node': default, `argv[0]` is the application and `argv[1]` is the script being run, with user parameters after that\n- 'electron': `argv[1]` varies depending on whether the electron application is packaged\n- 'user': all of the arguments from the user\n\nFor example:\n\n```js\nprogram.parse(process.argv); // Explicit, node conventions\nprogram.parse(); // Implicit, and auto-detect electron\nprogram.parse(['-f', 'filename'], { from: 'user' });\n```\n\n### Avoiding option name clashes\n\nThe original and default behaviour is that the option values are stored\nas properties on the program, and the action handler is passed a\ncommand object with the options values stored as properties.\nThis is very convenient to code, but the downside is possible clashes with\nexisting properties of Command.\n\nThere are two new routines to change the behaviour, and the default behaviour may change in the future:\n\n- `storeOptionsAsProperties`: whether to store option values as properties on command object, or store separately (specify false) and access using `.opts()`\n- `passCommandToAction`: whether to pass command to action handler,\nor just the options (specify false)\n\n([example](./examples/storeOptionsAsProperties-action.js))\n\n```js\nprogram\n  .storeOptionsAsProperties(false)\n  .passCommandToAction(false);\n\nprogram\n  .name('my-program-name')\n  .option('-n,--name <name>');\n\nprogram\n  .command('show')\n  .option('-a,--action <action>')\n  .action((options) => {\n    console.log(options.action);\n  });\n\nprogram.parse(process.argv);\n\nconst programOptions = program.opts();\nconsole.log(programOptions.name);\n```\n\n### TypeScript\n\nThe Commander package includes its TypeScript Definition file.\n\nIf you use `ts-node` and  stand-alone executable subcommands written as `.ts` files, you need to call your program through node to get the subcommands called correctly. e.g.\n\n```bash\nnode -r ts-node/register pm.ts\n```\n\n### createCommand()\n\nThis factory function creates a new command. It is exported and may be used instead of using `new`, like:\n\n```js\nconst { createCommand } = require('commander');\nconst program = createCommand();\n```\n\n`createCommand` is also a method of the Command object, and creates a new command rather than a subcommand. This gets used internally\nwhen creating subcommands using `.command()`, and you may override it to\ncustomise the new subcommand (examples using [subclass](./examples/custom-command-class.js) and [function](./examples/custom-command-function.js)).\n\n### Node options such as `--harmony`\n\nYou can enable `--harmony` option in two ways:\n\n- Use `#! /usr/bin/env node --harmony` in the subcommands scripts. (Note Windows does not support this pattern.)\n- Use the `--harmony` option when call the command, like `node --harmony examples/pm publish`. The `--harmony` option will be preserved when spawning subcommand process.\n\n### Debugging stand-alone executable subcommands\n\nAn executable subcommand is launched as a separate child process.\n\nIf you are using the node inspector for [debugging](https://nodejs.org/en/docs/guides/debugging-getting-started/) executable subcommands using `node --inspect` et al,\nthe inspector port is incremented by 1 for the spawned subcommand.\n\nIf you are using VSCode to debug executable subcommands you need to set the `\"autoAttachChildProcesses\": true` flag in your launch.json configuration.\n\n### Override exit handling\n\nBy default Commander calls `process.exit` when it detects errors, or after displaying the help or version. You can override\nthis behaviour and optionally supply a callback. The default override throws a `CommanderError`.\n\nThe override callback is passed a `CommanderError` with properties `exitCode` number, `code` string, and `message`. The default override behaviour is to throw the error, except for async handling of executable subcommand completion which carries on. The normal display of error messages or version or help\nis not affected by the override which is called after the display.\n\n``` js\nprogram.exitOverride();\n\ntry {\n  program.parse(process.argv);\n} catch (err) {\n  // custom processing...\n}\n```\n\n## Examples\n\n```js\nconst { program } = require('commander');\n\nprogram\n  .version('0.1.0')\n  .option('-C, --chdir <path>', 'change the working directory')\n  .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')\n  .option('-T, --no-tests', 'ignore test hook');\n\nprogram\n  .command('setup [env]')\n  .description('run setup commands for all envs')\n  .option(\"-s, --setup_mode [mode]\", \"Which setup mode to use\")\n  .action(function(env, options){\n    const mode = options.setup_mode || \"normal\";\n    env = env || 'all';\n    console.log('setup for %s env(s) with %s mode', env, mode);\n  });\n\nprogram\n  .command('exec <cmd>')\n  .alias('ex')\n  .description('execute the given remote cmd')\n  .option(\"-e, --exec_mode <mode>\", \"Which exec mode to use\")\n  .action(function(cmd, options){\n    console.log('exec \"%s\" using %s mode', cmd, options.exec_mode);\n  }).on('--help', function() {\n    console.log('');\n    console.log('Examples:');\n    console.log('');\n    console.log('  $ deploy exec sequential');\n    console.log('  $ deploy exec async');\n  });\n\nprogram.parse(process.argv);\n```\n\nMore Demos can be found in the [examples](https://github.com/tj/commander.js/tree/master/examples) directory.\n\n## License\n\n[MIT](https://github.com/tj/commander.js/blob/master/LICENSE)\n\n## Support\n\nCommander 5.x is fully supported on Long Term Support versions of Node, and is likely to work with Node 6 but not tested.\n(For versions of Node below Node 6, use Commander 3.x or 2.x.)\n\nThe main forum for free and community support is the project [Issues](https://github.com/tj/commander.js/issues) on GitHub.\n\n### Commander for enterprise\n\nAvailable as part of the Tidelift Subscription\n\nThe maintainers of Commander and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-commander?utm_source=npm-commander&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)\n","_attachments":{},"homepage":"https://github.com/tj/commander.js#readme","bugs":{"url":"https://github.com/tj/commander.js/issues"},"license":"MIT"}