summaryrefslogtreecommitdiff
path: root/src/node_modules/commander
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_modules/commander')
-rw-r--r--src/node_modules/commander/CHANGELOG.md354
-rw-r--r--src/node_modules/commander/LICENSE22
-rw-r--r--src/node_modules/commander/Readme.md791
-rw-r--r--src/node_modules/commander/index.js1881
-rw-r--r--src/node_modules/commander/package.json51
-rw-r--r--src/node_modules/commander/typings/index.d.ts410
6 files changed, 3509 insertions, 0 deletions
diff --git a/src/node_modules/commander/CHANGELOG.md b/src/node_modules/commander/CHANGELOG.md
new file mode 100644
index 0000000..c329ca3
--- /dev/null
+++ b/src/node_modules/commander/CHANGELOG.md
@@ -0,0 +1,354 @@
+# Changelog
+
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
+and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). (Format adopted after v3.0.0.)
+
+<!-- markdownlint-disable MD024 -->
+<!-- markdownlint-disable MD004 -->
+
+## [6.2.0] (2020-10-25)
+
+### Added
+
+- added 'tsx' file extension for stand-alone executable subcommands ([#1368])
+- documented second parameter to `.description()` to describe command arguments ([#1353])
+- documentation of special cases with options taking varying numbers of option-arguments ([#1332])
+- documentation for terminology ([#1361])
+
+### Fixed
+
+- add missing TypeScript definition for `.addHelpCommand()' ([#1375])
+- removed blank line after "Arguments:" in help, to match "Options:" and "Commands:" ([#1360])
+
+### Changed
+
+- update dependencies
+
+## [6.1.0] (2020-08-28)
+
+### Added
+
+- include URL to relevant section of README for error for potential conflict between Command properties and option values ([#1306])
+- `.combineFlagAndOptionalValue(false)` to ease upgrade path from older versions of Commander ([#1326])
+- allow disabling the built-in help option using `.helpOption(false)` ([#1325])
+- allow just some arguments in `argumentDescription` to `.description()` ([#1323])
+
+### Changed
+
+- tidy async test and remove lint override ([#1312])
+
+### Fixed
+
+- executable subcommand launching when script path not known ([#1322])
+
+## [6.0.0] (2020-07-21)
+
+### Added
+
+- add support for variadic options ([#1250])
+- allow options to be added with just a short flag ([#1256])
+ - *Breaking* the option property has same case as flag. e.g. flag `-n` accessed as `opts().n` (previously uppercase)
+- *Breaking* throw an error if there might be a clash between option name and a Command property, with advice on how to resolve ([#1275])
+
+### Fixed
+
+- Options which contain -no- in the middle of the option flag should not be treated as negatable. ([#1301])
+
+## [6.0.0-0] (2020-06-20)
+
+(Released in 6.0.0)
+
+## [5.1.0] (2020-04-25)
+
+### Added
+
+- support for multiple command aliases, the first of which is shown in the auto-generated help ([#531], [#1236])
+- configuration support in `addCommand()` for `hidden` and `isDefault` ([#1232])
+
+### Fixed
+
+- omit masked help flags from the displayed help ([#645], [#1247])
+- remove old short help flag when change help flags using `helpOption` ([#1248])
+
+### Changed
+
+- remove use of `arguments` to improve auto-generated help in editors ([#1235])
+- rename `.command()` configuration `noHelp` to `hidden` (but not remove old support) ([#1232])
+- improvements to documentation
+- update dependencies
+- update tested versions of node
+- eliminate lint errors in TypeScript ([#1208])
+
+## [5.0.0] (2020-03-14)
+
+### Added
+
+* support for nested commands with action-handlers ([#1] [#764] [#1149])
+* `.addCommand()` for adding a separately configured command ([#764] [#1149])
+* allow a non-executable to be set as the default command ([#742] [#1149])
+* implicit help command when there are subcommands (previously only if executables) ([#1149])
+* customise implicit help command with `.addHelpCommand()` ([#1149])
+* display error message for unknown subcommand, by default ([#432] [#1088] [#1149])
+* display help for missing subcommand, by default ([#1088] [#1149])
+* combined short options as single argument may include boolean flags and value flag and value (e.g. `-a -b -p 80` can be written as `-abp80`) ([#1145])
+* `.parseOption()` includes short flag and long flag expansions ([#1145])
+* `.helpInformation()` returns help text as a string, previously a private routine ([#1169])
+* `.parse()` implicitly uses `process.argv` if arguments not specified ([#1172])
+* optionally specify where `.parse()` arguments "from", if not following node conventions ([#512] [#1172])
+* suggest help option along with unknown command error ([#1179])
+* TypeScript definition for `commands` property of `Command` ([#1184])
+* export `program` property ([#1195])
+* `createCommand` factory method to simplify subclassing ([#1191])
+
+### Fixed
+
+* preserve argument order in subcommands ([#508] [#962] [#1138])
+* do not emit `command:*` for executable subcommands ([#809] [#1149])
+* action handler called whether or not there are non-option arguments ([#1062] [#1149])
+* combining option short flag and value in single argument now works for subcommands ([#1145])
+* only add implicit help command when it will not conflict with other uses of argument ([#1153] [#1149])
+* implicit help command works with command aliases ([#948] [#1149])
+* options are validated whether or not there is an action handler ([#1149])
+
+### Changed
+
+* *Breaking* `.args` contains command arguments with just recognised options removed ([#1032] [#1138])
+* *Breaking* display error if required argument for command is missing ([#995] [#1149])
+* tighten TypeScript definition of custom option processing function passed to `.option()` ([#1119])
+* *Breaking* `.allowUnknownOption()` ([#802] [#1138])
+ * unknown options included in arguments passed to command action handler
+ * unknown options included in `.args`
+* only recognised option short flags and long flags are expanded (e.g. `-ab` or `--foo=bar`) ([#1145])
+* *Breaking* `.parseOptions()` ([#1138])
+ * `args` in returned result renamed `operands` and does not include anything after first unknown option
+ * `unknown` in returned result has arguments after first unknown option including operands, not just options and values
+* *Breaking* `.on('command:*', callback)` and other command events passed (changed) results from `.parseOptions`, i.e. operands and unknown ([#1138])
+* refactor Option from prototype to class ([#1133])
+* refactor Command from prototype to class ([#1159])
+* changes to error handling ([#1165])
+ * throw for author error, not just display message
+ * preflight for variadic error
+ * add tips to missing subcommand executable
+* TypeScript fluent return types changed to be more subclass friendly, return `this` rather than `Command` ([#1180])
+* `.parseAsync` returns `Promise<this>` to be consistent with `.parse()` ([#1180])
+* update dependencies
+
+### Removed
+
+* removed EventEmitter from TypeScript definition for Command, eliminating implicit peer dependency on `@types/node` ([#1146])
+* removed private function `normalize` (the functionality has been integrated into `parseOptions`) ([#1145])
+* `parseExpectedArgs` is now private ([#1149])
+
+### Migration Tips
+
+If you use `.on('command:*')` or more complicated tests to detect an unrecognised subcommand, you may be able to delete the code and rely on the default behaviour.
+
+If you use `program.args` or more complicated tests to detect a missing subcommand, you may be able to delete the code and rely on the default behaviour.
+
+If you use `.command('*')` to add a default command, you may be be able to switch to `isDefault:true` with a named command.
+
+If you want to continue combining short options with optional values as though they were boolean flags, set `combineFlagAndOptionalValue(false)`
+to expand `-fb` to `-f -b` rather than `-f b`.
+
+## [5.0.0-4] (2020-03-03)
+
+(Released in 5.0.0)
+
+## [5.0.0-3] (2020-02-20)
+
+(Released in 5.0.0)
+
+## [5.0.0-2] (2020-02-10)
+
+(Released in 5.0.0)
+
+## [5.0.0-1] (2020-02-08)
+
+(Released in 5.0.0)
+
+## [5.0.0-0] (2020-02-02)
+
+(Released in 5.0.0)
+
+## [4.1.1] (2020-02-02)
+
+### Fixed
+
+* TypeScript definition for `.action()` should include Promise for async ([#1157])
+
+## [4.1.0] (2020-01-06)
+
+### Added
+
+* two routines to change how option values are handled, and eliminate name clashes with command properties ([#933] [#1102])
+ * see storeOptionsAsProperties and passCommandToAction in README
+* `.parseAsync` to use instead of `.parse` if supply async action handlers ([#806] [#1118])
+
+### Fixed
+
+* Remove trailing blanks from wrapped help text ([#1096])
+
+### Changed
+
+* update dependencies
+* extend security coverage for Commander 2.x to 2020-02-03
+* improvements to README
+* improvements to TypeScript definition documentation
+* move old versions out of main CHANGELOG
+* removed explicit use of `ts-node` in tests
+
+## [4.0.1] (2019-11-12)
+
+### Fixed
+
+* display help when requested, even if there are missing required options ([#1091])
+
+## [4.0.0] (2019-11-02)
+
+### Added
+
+* automatically wrap and indent help descriptions for options and commands ([#1051])
+* `.exitOverride()` allows override of calls to `process.exit` for additional error handling and to keep program running ([#1040])
+* support for declaring required options with `.requiredOptions()` ([#1071])
+* GitHub Actions support ([#1027])
+* translation links in README
+
+### Changed
+
+* dev: switch tests from Sinon+Should to Jest with major rewrite of tests ([#1035])
+* call default subcommand even when there are unknown options ([#1047])
+* *Breaking* Commander is only officially supported on Node 8 and above, and requires Node 6 ([#1053])
+
+### Fixed
+
+* *Breaking* keep command object out of program.args when action handler called ([#1048])
+ * also, action handler now passed array of unknown arguments
+* complain about unknown options when program argument supplied and action handler ([#1049])
+ * this changes parameters to `command:*` event to include unknown arguments
+* removed deprecated `customFds` option from call to `child_process.spawn` ([#1052])
+* rework TypeScript declarations to bring all types into imported namespace ([#1081])
+
+### Migration Tips
+
+#### Testing for no arguments
+
+If you were previously using code like:
+
+```js
+if (!program.args.length) ...
+```
+
+a partial replacement is:
+
+```js
+if (program.rawArgs.length < 3) ...
+```
+
+## [4.0.0-1] Prerelease (2019-10-08)
+
+(Released in 4.0.0)
+
+## [4.0.0-0] Prerelease (2019-10-01)
+
+(Released in 4.0.0)
+
+## Older versions
+
+* [3.x](./changelogs/CHANGELOG-3.md)
+* [2.x](./changelogs/CHANGELOG-2.md)
+* [1.x](./changelogs/CHANGELOG-1.md)
+* [0.x](./changelogs/CHANGELOG-0.md)
+
+[#1]: https://github.com/tj/commander.js/issues/1
+[#432]: https://github.com/tj/commander.js/issues/432
+[#508]: https://github.com/tj/commander.js/issues/508
+[#512]: https://github.com/tj/commander.js/issues/512
+[#531]: https://github.com/tj/commander.js/issues/531
+[#645]: https://github.com/tj/commander.js/issues/645
+[#742]: https://github.com/tj/commander.js/issues/742
+[#764]: https://github.com/tj/commander.js/issues/764
+[#802]: https://github.com/tj/commander.js/issues/802
+[#806]: https://github.com/tj/commander.js/issues/806
+[#809]: https://github.com/tj/commander.js/issues/809
+[#948]: https://github.com/tj/commander.js/issues/948
+[#962]: https://github.com/tj/commander.js/issues/962
+[#995]: https://github.com/tj/commander.js/issues/995
+[#1027]: https://github.com/tj/commander.js/pull/1027
+[#1032]: https://github.com/tj/commander.js/issues/1032
+[#1035]: https://github.com/tj/commander.js/pull/1035
+[#1040]: https://github.com/tj/commander.js/pull/1040
+[#1047]: https://github.com/tj/commander.js/pull/1047
+[#1048]: https://github.com/tj/commander.js/pull/1048
+[#1049]: https://github.com/tj/commander.js/pull/1049
+[#1051]: https://github.com/tj/commander.js/pull/1051
+[#1052]: https://github.com/tj/commander.js/pull/1052
+[#1053]: https://github.com/tj/commander.js/pull/1053
+[#1062]: https://github.com/tj/commander.js/pull/1062
+[#1071]: https://github.com/tj/commander.js/pull/1071
+[#1081]: https://github.com/tj/commander.js/pull/1081
+[#1088]: https://github.com/tj/commander.js/issues/1088
+[#1091]: https://github.com/tj/commander.js/pull/1091
+[#1096]: https://github.com/tj/commander.js/pull/1096
+[#1102]: https://github.com/tj/commander.js/pull/1102
+[#1118]: https://github.com/tj/commander.js/pull/1118
+[#1119]: https://github.com/tj/commander.js/pull/1119
+[#1133]: https://github.com/tj/commander.js/pull/1133
+[#1138]: https://github.com/tj/commander.js/pull/1138
+[#1145]: https://github.com/tj/commander.js/pull/1145
+[#1146]: https://github.com/tj/commander.js/pull/1146
+[#1149]: https://github.com/tj/commander.js/pull/1149
+[#1153]: https://github.com/tj/commander.js/issues/1153
+[#1157]: https://github.com/tj/commander.js/pull/1157
+[#1159]: https://github.com/tj/commander.js/pull/1159
+[#1165]: https://github.com/tj/commander.js/pull/1165
+[#1169]: https://github.com/tj/commander.js/pull/1169
+[#1172]: https://github.com/tj/commander.js/pull/1172
+[#1179]: https://github.com/tj/commander.js/pull/1179
+[#1180]: https://github.com/tj/commander.js/pull/1180
+[#1184]: https://github.com/tj/commander.js/pull/1184
+[#1191]: https://github.com/tj/commander.js/pull/1191
+[#1195]: https://github.com/tj/commander.js/pull/1195
+[#1208]: https://github.com/tj/commander.js/pull/1208
+[#1232]: https://github.com/tj/commander.js/pull/1232
+[#1235]: https://github.com/tj/commander.js/pull/1235
+[#1236]: https://github.com/tj/commander.js/pull/1236
+[#1247]: https://github.com/tj/commander.js/pull/1247
+[#1248]: https://github.com/tj/commander.js/pull/1248
+[#1250]: https://github.com/tj/commander.js/pull/1250
+[#1256]: https://github.com/tj/commander.js/pull/1256
+[#1275]: https://github.com/tj/commander.js/pull/1275
+[#1301]: https://github.com/tj/commander.js/issues/1301
+[#1306]: https://github.com/tj/commander.js/pull/1306
+[#1312]: https://github.com/tj/commander.js/pull/1312
+[#1322]: https://github.com/tj/commander.js/pull/1322
+[#1323]: https://github.com/tj/commander.js/pull/1323
+[#1325]: https://github.com/tj/commander.js/pull/1325
+[#1326]: https://github.com/tj/commander.js/pull/1326
+[#1332]: https://github.com/tj/commander.js/pull/1332
+[#1353]: https://github.com/tj/commander.js/pull/1353
+[#1360]: https://github.com/tj/commander.js/pull/1360
+[#1361]: https://github.com/tj/commander.js/pull/1361
+[#1368]: https://github.com/tj/commander.js/pull/1368
+[#1375]: https://github.com/tj/commander.js/pull/1375
+
+
+[Unreleased]: https://github.com/tj/commander.js/compare/master...develop
+[6.2.0]: https://github.com/tj/commander.js/compare/v6.1.0..v6.2.0
+[6.1.0]: https://github.com/tj/commander.js/compare/v6.0.0..v6.1.0
+[6.0.0]: https://github.com/tj/commander.js/compare/v5.1.0..v6.0.0
+[6.0.0-0]: https://github.com/tj/commander.js/compare/v5.1.0..v6.0.0-0
+[5.1.0]: https://github.com/tj/commander.js/compare/v5.0.0..v5.1.0
+[5.0.0]: https://github.com/tj/commander.js/compare/v4.1.1..v5.0.0
+[5.0.0-4]: https://github.com/tj/commander.js/compare/v5.0.0-3..v5.0.0-4
+[5.0.0-3]: https://github.com/tj/commander.js/compare/v5.0.0-2..v5.0.0-3
+[5.0.0-2]: https://github.com/tj/commander.js/compare/v5.0.0-1..v5.0.0-2
+[5.0.0-1]: https://github.com/tj/commander.js/compare/v5.0.0-0..v5.0.0-1
+[5.0.0-0]: https://github.com/tj/commander.js/compare/v4.1.1..v5.0.0-0
+[4.1.1]: https://github.com/tj/commander.js/compare/v4.1.0..v4.1.1
+[4.1.0]: https://github.com/tj/commander.js/compare/v4.0.1..v4.1.0
+[4.0.1]: https://github.com/tj/commander.js/compare/v4.0.0..v4.0.1
+[4.0.0]: https://github.com/tj/commander.js/compare/v3.0.2..v4.0.0
+[4.0.0-1]: https://github.com/tj/commander.js/compare/v4.0.0-0..v4.0.0-1
+[4.0.0-0]: https://github.com/tj/commander.js/compare/v3.0.2...v4.0.0-0
diff --git a/src/node_modules/commander/LICENSE b/src/node_modules/commander/LICENSE
new file mode 100644
index 0000000..10f997a
--- /dev/null
+++ b/src/node_modules/commander/LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/src/node_modules/commander/Readme.md b/src/node_modules/commander/Readme.md
new file mode 100644
index 0000000..45cd755
--- /dev/null
+++ b/src/node_modules/commander/Readme.md
@@ -0,0 +1,791 @@
+# Commander.js
+
+[![Build Status](https://api.travis-ci.org/tj/commander.js.svg?branch=master)](http://travis-ci.org/tj/commander.js)
+[![NPM Version](http://img.shields.io/npm/v/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
+[![NPM Downloads](https://img.shields.io/npm/dm/commander.svg?style=flat)](https://npmcharts.com/compare/commander?minimal=true)
+[![Install Size](https://packagephobia.now.sh/badge?p=commander)](https://packagephobia.now.sh/result?p=commander)
+
+The complete solution for [node.js](http://nodejs.org) command-line interfaces.
+
+Read this in other languages: English | [简体中文](./Readme_zh-CN.md)
+
+- [Commander.js](#commanderjs)
+ - [Installation](#installation)
+ - [Declaring _program_ variable](#declaring-program-variable)
+ - [Options](#options)
+ - [Common option types, boolean and value](#common-option-types-boolean-and-value)
+ - [Default option value](#default-option-value)
+ - [Other option types, negatable boolean and boolean|value](#other-option-types-negatable-boolean-and-booleanvalue)
+ - [Custom option processing](#custom-option-processing)
+ - [Required option](#required-option)
+ - [Variadic option](#variadic-option)
+ - [Version option](#version-option)
+ - [Commands](#commands)
+ - [Specify the argument syntax](#specify-the-argument-syntax)
+ - [Action handler (sub)commands](#action-handler-subcommands)
+ - [Stand-alone executable (sub)commands](#stand-alone-executable-subcommands)
+ - [Automated help](#automated-help)
+ - [Custom help](#custom-help)
+ - [.usage and .name](#usage-and-name)
+ - [.help(cb)](#helpcb)
+ - [.outputHelp(cb)](#outputhelpcb)
+ - [.helpInformation()](#helpinformation)
+ - [.helpOption(flags, description)](#helpoptionflags-description)
+ - [.addHelpCommand()](#addhelpcommand)
+ - [Custom event listeners](#custom-event-listeners)
+ - [Bits and pieces](#bits-and-pieces)
+ - [.parse() and .parseAsync()](#parse-and-parseasync)
+ - [Avoiding option name clashes](#avoiding-option-name-clashes)
+ - [TypeScript](#typescript)
+ - [createCommand()](#createcommand)
+ - [Import into ECMAScript Module](#import-into-ecmascript-module)
+ - [Node options such as `--harmony`](#node-options-such-as---harmony)
+ - [Debugging stand-alone executable subcommands](#debugging-stand-alone-executable-subcommands)
+ - [Override exit handling](#override-exit-handling)
+ - [Examples](#examples)
+ - [Support](#support)
+ - [Commander for enterprise](#commander-for-enterprise)
+
+For information about terms used in this document see: [terminology](./docs/terminology.md)
+
+## Installation
+
+```bash
+npm install commander
+```
+
+## Declaring _program_ variable
+
+Commander exports a global object which is convenient for quick programs.
+This is used in the examples in this README for brevity.
+
+```js
+const { program } = require('commander');
+program.version('0.0.1');
+```
+
+For larger programs which may use commander in multiple ways, including unit testing, it is better to create a local Command object to use.
+
+```js
+const { Command } = require('commander');
+const program = new Command();
+program.version('0.0.1');
+```
+
+## Options
+
+Options 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 ('|').
+
+The 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).
+
+Multiple short flags may optionally be combined in a single argument following the dash: boolean flags, followed by a single option taking a value (possibly followed by the value).
+For example `-a -b -p 80` may be written as `-ab -p80` or even `-abp80`.
+
+You can use `--` to indicate the end of the options, and any remaining arguments will be used without being interpreted.
+
+Options on the command line are not positional, and can be specified before or after other arguments.
+
+### Common option types, boolean and value
+
+The two most used option types are a boolean option, and an option which takes its value
+from the following argument (declared with angle brackets like `--expect <value>`). Both are `undefined` unless specified on command line.
+
+Example file: [options-common.js](./examples/options-common.js)
+
+```js
+program
+ .option('-d, --debug', 'output extra debugging')
+ .option('-s, --small', 'small pizza size')
+ .option('-p, --pizza-type <type>', 'flavour of pizza');
+
+program.parse(process.argv);
+
+if (program.debug) console.log(program.opts());
+console.log('pizza details:');
+if (program.small) console.log('- small pizza size');
+if (program.pizzaType) console.log(`- ${program.pizzaType}`);
+```
+
+```bash
+$ pizza-options -d
+{ debug: true, small: undefined, pizzaType: undefined }
+pizza details:
+$ pizza-options -p
+error: option '-p, --pizza-type <type>' argument missing
+$ pizza-options -ds -p vegetarian
+{ debug: true, small: true, pizzaType: 'vegetarian' }
+pizza details:
+- small pizza size
+- vegetarian
+$ pizza-options --pizza-type=cheese
+pizza details:
+- cheese
+```
+
+`program.parse(arguments)` processes the arguments, leaving any args not consumed by the program options in the `program.args` array.
+
+### Default option value
+
+You can specify a default value for an option which takes a value.
+
+Example file: [options-defaults.js](./examples/options-defaults.js)
+
+```js
+program
+ .option('-c, --cheese <type>', 'add the specified type of cheese', 'blue');
+
+program.parse(process.argv);
+
+console.log(`cheese: ${program.cheese}`);
+```
+
+```bash
+$ pizza-options
+cheese: blue
+$ pizza-options --cheese stilton
+cheese: stilton
+```
+
+### Other option types, negatable boolean and boolean|value
+
+You can define a boolean option long name with a leading `no-` to set the option value to false when used.
+Defined alone this also makes the option true by default.
+
+If you define `--foo` first, adding `--no-foo` does not change the default value from what it would
+otherwise be. You can specify a default boolean value for a boolean option and it can be overridden on command line.
+
+Example file: [options-negatable.js](./examples/options-negatable.js)
+
+```js
+program
+ .option('--no-sauce', 'Remove sauce')
+ .option('--cheese <flavour>', 'cheese flavour', 'mozzarella')
+ .option('--no-cheese', 'plain with no cheese')
+ .parse(process.argv);
+
+const sauceStr = program.sauce ? 'sauce' : 'no sauce';
+const cheeseStr = (program.cheese === false) ? 'no cheese' : `${program.cheese} cheese`;
+console.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`);
+```
+
+```bash
+$ pizza-options
+You ordered a pizza with sauce and mozzarella cheese
+$ pizza-options --sauce
+error: unknown option '--sauce'
+$ pizza-options --cheese=blue
+You ordered a pizza with sauce and blue cheese
+$ pizza-options --no-sauce --no-cheese
+You ordered a pizza with no sauce and no cheese
+```
+
+You can specify an option which may be used as a boolean option but may optionally take an option-argument
+(declared with square brackets like `--optional [value]`).
+
+Example file: [options-boolean-or-value.js](./examples/options-boolean-or-value.js)
+
+```js
+program
+ .option('-c, --cheese [type]', 'Add cheese with optional type');
+
+program.parse(process.argv);
+
+if (program.cheese === undefined) console.log('no cheese');
+else if (program.cheese === true) console.log('add cheese');
+else console.log(`add cheese type ${program.cheese}`);
+```
+
+```bash
+$ pizza-options
+no cheese
+$ pizza-options --cheese
+add cheese
+$ pizza-options --cheese mozzarella
+add cheese type mozzarella
+```
+
+For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
+
+### Custom option processing
+
+You may specify a function to do custom processing of option-arguments. The callback function receives two parameters,
+the user specified option-argument and the previous value for the option. It returns the new value for the option.
+
+This allows you to coerce the option-argument to the desired type, or accumulate values, or do entirely custom processing.
+
+You can optionally specify the default/starting value for the option after the function parameter.
+
+Example file: [options-custom-processing.js](./examples/options-custom-processing.js)
+
+```js
+function myParseInt(value, dummyPrevious) {
+ // parseInt takes a string and an optional radix
+ return parseInt(value);
+}
+
+function increaseVerbosity(dummyValue, previous) {
+ return previous + 1;
+}
+
+function collect(value, previous) {
+ return previous.concat([value]);
+}
+
+function commaSeparatedList(value, dummyPrevious) {
+ return value.split(',');
+}
+
+program
+ .option('-f, --float <number>', 'float argument', parseFloat)
+ .option('-i, --integer <number>', 'integer argument', myParseInt)
+ .option('-v, --verbose', 'verbosity that can be increased', increaseVerbosity, 0)
+ .option('-c, --collect <value>', 'repeatable value', collect, [])
+ .option('-l, --list <items>', 'comma separated list', commaSeparatedList)
+;
+
+program.parse(process.argv);
+
+if (program.float !== undefined) console.log(`float: ${program.float}`);
+if (program.integer !== undefined) console.log(`integer: ${program.integer}`);
+if (program.verbose > 0) console.log(`verbosity: ${program.verbose}`);
+if (program.collect.length > 0) console.log(program.collect);
+if (program.list !== undefined) console.log(program.list);
+```
+
+```bash
+$ custom -f 1e2
+float: 100
+$ custom --integer 2
+integer: 2
+$ custom -v -v -v
+verbose: 3
+$ custom -c a -c b -c c
+[ 'a', 'b', 'c' ]
+$ custom --list x,y,z
+[ 'x', 'y', 'z' ]
+```
+
+### Required option
+
+You 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.
+
+Example file: [options-required.js](./examples/options-required.js)
+
+```js
+program
+ .requiredOption('-c, --cheese <type>', 'pizza must have cheese');
+
+program.parse(process.argv);
+```
+
+```bash
+$ pizza
+error: required option '-c, --cheese <type>' not specified
+```
+
+### Variadic option
+
+You may make an option variadic by appending `...` to the value placeholder when declaring the option. On the command line you
+can then specify multiple option-arguments, and the parsed option value will be an array. The extra arguments
+are read until the first argument starting with a dash. The special argument `--` stops option processing entirely. If a value
+is specified in the same argument as the option then no further values are read.
+
+Example file: [options-variadic.js](./examples/options-variadic.js)
+
+```js
+program
+ .option('-n, --number <numbers...>', 'specify numbers')
+ .option('-l, --letter [letters...]', 'specify letters');
+
+program.parse();
+
+console.log('Options: ', program.opts());
+console.log('Remaining arguments: ', program.args);
+```
+
+```bash
+$ collect -n 1 2 3 --letter a b c
+Options: { number: [ '1', '2', '3' ], letter: [ 'a', 'b', 'c' ] }
+Remaining arguments: []
+$ collect --letter=A -n80 operand
+Options: { number: [ '80' ], letter: [ 'A' ] }
+Remaining arguments: [ 'operand' ]
+$ collect --letter -n 1 -n 2 3 -- operand
+Options: { number: [ '1', '2', '3' ], letter: true }
+Remaining arguments: [ 'operand' ]
+```
+
+For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
+
+### Version option
+
+The 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.
+
+```js
+program.version('0.0.1');
+```
+
+```bash
+$ ./examples/pizza -V
+0.0.1
+```
+
+You may change the flags and description by passing additional parameters to the `version` method, using
+the same syntax for flags as the `option` method.
+
+```js
+program.version('0.0.1', '-v, --vers', 'output the current version');
+```
+
+## Commands
+
+You can specify (sub)commands 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)).
+
+In 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...`.
+
+You can use `.addCommand()` to add an already configured subcommand to the program.
+
+For example:
+
+```js
+// Command implemented using action handler (description is supplied separately to `.command`)
+// Returns new command for configuring.
+program
+ .command('clone <source> [destination]')
+ .description('clone a repository into a newly created directory')
+ .action((source, destination) => {
+ console.log('clone command called');
+ });
+
+// Command implemented using stand-alone executable file (description is second parameter to `.command`)
+// Returns `this` for adding more commands.
+program
+ .command('start <service>', 'start named service')
+ .command('stop [service]', 'stop named service, or all if no name supplied');
+
+// Command prepared separately.
+// Returns `this` for adding more commands.
+program
+ .addCommand(build.makeBuildCommand());
+```
+
+Configuration options can be passed with the call to `.command()` and `.addCommand()`. Specifying `hidden: true` will
+remove the command from the generated help output. Specifying `isDefault: true` will run the subcommand if no other
+subcommand is specified ([example](./examples/defaultCommand.js)).
+
+### Specify the argument syntax
+
+You use `.arguments` to specify the expected command-arguments for the top-level command, and for subcommands they are usually
+included in the `.command` call. Angled brackets (e.g. `<required>`) indicate required command-arguments.
+Square brackets (e.g. `[optional]`) indicate optional command-arguments.
+You can optionally describe the arguments in the help by supplying a hash as second parameter to `.description()`.
+
+Example file: [env](./examples/env)
+
+```js
+program
+ .version('0.1.0')
+ .arguments('<cmd> [env]')
+ .description('test command', {
+ cmd: 'command to run',
+ env: 'environment to run test in'
+ })
+ .action(function (cmd, env) {
+ console.log('command:', cmd);
+ console.log('environment:', env || 'no environment given');
+ });
+
+program.parse(process.argv);
+```
+
+ The last argument of a command can be variadic, and only the last argument. To make an argument variadic you
+ append `...` to the argument name. For example:
+
+```js
+const { program } = require('commander');
+
+program
+ .version('0.1.0')
+ .command('rmdir <dir> [otherDirs...]')
+ .action(function (dir, otherDirs) {
+ console.log('rmdir %s', dir);
+ if (otherDirs) {
+ otherDirs.forEach(function (oDir) {
+ console.log('rmdir %s', oDir);
+ });
+ }
+ });
+
+program.parse(process.argv);
+```
+
+The variadic argument is passed to the action handler as an array.
+
+### Action handler (sub)commands
+
+You can add options to a command that uses an action handler.
+The action handler gets passed a parameter for each argument you declared, and one additional argument which is the
+command object itself. This command argument has the values for the command-specific options added as properties.
+
+```js
+const { program } = require('commander');
+
+program
+ .command('rm <dir>')
+ .option('-r, --recursive', 'Remove recursively')
+ .action(function (dir, cmdObj) {
+ console.log('remove ' + dir + (cmdObj.recursive ? ' recursively' : ''))
+ })
+
+program.parse(process.argv)
+```
+
+You may supply an `async` action handler, in which case you call `.parseAsync` rather than `.parse`.
+
+```js
+async function run() { /* code goes here */ }
+
+async function main() {
+ program
+ .command('run')
+ .action(run);
+ await program.parseAsync(process.argv);
+}
+```
+
+A command's options on the command line are validated when the command is used. Any unknown options will be reported as an error.
+
+### Stand-alone executable (sub)commands
+
+When `.command()` is invoked with a description argument, this tells Commander that you're going to use stand-alone executables for subcommands.
+Commander will search the executables in the directory of the entry script (like `./examples/pm`) with the name `program-subcommand`, like `pm-install`, `pm-search`.
+You can specify a custom name with the `executableFile` configuration option.
+
+You handle the options for an executable (sub)command in the executable, and don't declare them at the top-level.
+
+Example file: [pm](./examples/pm)
+
+```js
+program
+ .version('0.1.0')
+ .command('install [name]', 'install one or more packages')
+ .command('search [query]', 'search with optional query')
+ .command('update', 'update installed packages', { executableFile: 'myUpdateSubCommand' })
+ .command('list', 'list packages installed', { isDefault: true });
+
+program.parse(process.argv);
+```
+
+If the program is designed to be installed globally, make sure the executables have proper modes, like `755`.
+
+## Automated help
+
+The help information is auto-generated based on the information commander already knows about your program. The default
+help option is `-h,--help`.
+
+Example file: [pizza](./examples/pizza)
+
+```bash
+$ node ./examples/pizza --help
+Usage: pizza [options]
+
+An application for pizzas ordering
+
+Options:
+ -V, --version output the version number
+ -p, --peppers Add peppers
+ -c, --cheese <type> Add the specified type of cheese (default: "marble")
+ -C, --no-cheese You do not want any cheese
+ -h, --help display help for command
+```
+
+A `help` command is added by default if your command has subcommands. It can be used alone, or with a subcommand name to show
+further help for the subcommand. These are effectively the same if the `shell` program has implicit help:
+
+```bash
+shell help
+shell --help
+
+shell help spawn
+shell spawn --help
+```
+
+### Custom help
+
+You can display extra information by listening for "--help".
+
+Example file: [custom-help](./examples/custom-help)
+
+```js
+program
+ .option('-f, --foo', 'enable some foo');
+
+// must be before .parse()
+program.on('--help', () => {
+ console.log('');
+ console.log('Example call:');
+ console.log(' $ custom-help --help');
+});
+```
+
+Yields the following help output:
+
+```Text
+Usage: custom-help [options]
+
+Options:
+ -f, --foo enable some foo
+ -h, --help display help for command
+
+Example call:
+ $ custom-help --help
+```
+
+### .usage and .name
+
+These allow you to customise the usage description in the first line of the help. The name is otherwise
+deduced from the (full) program arguments. Given:
+
+```js
+program
+ .name("my-command")
+ .usage("[global options] command")
+```
+
+The help will start with:
+
+```Text
+Usage: my-command [global options] command
+```
+
+### .help(cb)
+
+Output help information and exit immediately. Optional callback cb allows post-processing of help text before it is displayed.
+
+### .outputHelp(cb)
+
+Output help information without exiting.
+Optional callback cb allows post-processing of help text before it is displayed.
+
+### .helpInformation()
+
+Get the command help information as a string for processing or displaying yourself. (The text does not include the custom help
+from `--help` listeners.)
+
+### .helpOption(flags, description)
+
+Override the default help flags and description. Pass false to disable the built-in help option.
+
+```js
+program
+ .helpOption('-e, --HELP', 'read more information');
+```
+
+### .addHelpCommand()
+
+You can explicitly turn on or off the implicit help command with `.addHelpCommand()` and `.addHelpCommand(false)`.
+
+You can both turn on and customise the help command by supplying the name and description:
+
+```js
+program.addHelpCommand('assist [command]', 'show assistance');
+```
+
+## Custom event listeners
+
+You can execute custom actions by listening to command and option events.
+
+```js
+program.on('option:verbose', function () {
+ process.env.VERBOSE = this.verbose;
+});
+
+program.on('command:*', function (operands) {
+ console.error(`error: unknown command '${operands[0]}'`);
+ const availableCommands = program.commands.map(cmd => cmd.name());
+ mySuggestBestMatch(operands[0], availableCommands);
+ process.exitCode = 1;
+});
+```
+
+## Bits and pieces
+
+### .parse() and .parseAsync()
+
+The first argument to `.parse` is the array of strings to parse. You may omit the parameter to implicitly use `process.argv`.
+
+If the arguments follow different conventions than node you can pass a `from` option in the second parameter:
+
+- 'node': default, `argv[0]` is the application and `argv[1]` is the script being run, with user parameters after that
+- 'electron': `argv[1]` varies depending on whether the electron application is packaged
+- 'user': all of the arguments from the user
+
+For example:
+
+```js
+program.parse(process.argv); // Explicit, node conventions
+program.parse(); // Implicit, and auto-detect electron
+program.parse(['-f', 'filename'], { from: 'user' });
+```
+
+### Avoiding option name clashes
+
+The original and default behaviour is that the option values are stored
+as properties on the program, and the action handler is passed a
+command object with the options values stored as properties.
+This is very convenient to code, but the downside is possible clashes with
+existing properties of Command.
+
+There are two new routines to change the behaviour, and the default behaviour may change in the future:
+
+- `storeOptionsAsProperties`: whether to store option values as properties on command object, or store separately (specify false) and access using `.opts()`
+- `passCommandToAction`: whether to pass command to action handler,
+or just the options (specify false)
+
+Example file: [storeOptionsAsProperties-action.js](./examples/storeOptionsAsProperties-action.js)
+
+```js
+program
+ .storeOptionsAsProperties(false)
+ .passCommandToAction(false);
+
+program
+ .name('my-program-name')
+ .option('-n,--name <name>');
+
+program
+ .command('show')
+ .option('-a,--action <action>')
+ .action((options) => {
+ console.log(options.action);
+ });
+
+program.parse(process.argv);
+
+const programOptions = program.opts();
+console.log(programOptions.name);
+```
+
+### TypeScript
+
+The Commander package includes its TypeScript Definition file.
+
+If 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.
+
+```bash
+node -r ts-node/register pm.ts
+```
+
+### createCommand()
+
+This factory function creates a new command. It is exported and may be used instead of using `new`, like:
+
+```js
+const { createCommand } = require('commander');
+const program = createCommand();
+```
+
+`createCommand` is also a method of the Command object, and creates a new command rather than a subcommand. This gets used internally
+when creating subcommands using `.command()`, and you may override it to
+customise the new subcommand (examples using [subclass](./examples/custom-command-class.js) and [function](./examples/custom-command-function.js)).
+
+### Import into ECMAScript Module
+
+Commander is currently a CommonJS package, and the default export can be imported into an ES Module:
+
+```js
+// index.mjs
+import commander from 'commander';
+const program = commander.program;
+const newCommand = new commander.Command();
+```
+
+### Node options such as `--harmony`
+
+You can enable `--harmony` option in two ways:
+
+- Use `#! /usr/bin/env node --harmony` in the subcommands scripts. (Note Windows does not support this pattern.)
+- Use the `--harmony` option when call the command, like `node --harmony examples/pm publish`. The `--harmony` option will be preserved when spawning subcommand process.
+
+### Debugging stand-alone executable subcommands
+
+An executable subcommand is launched as a separate child process.
+
+If you are using the node inspector for [debugging](https://nodejs.org/en/docs/guides/debugging-getting-started/) executable subcommands using `node --inspect` et al,
+the inspector port is incremented by 1 for the spawned subcommand.
+
+If you are using VSCode to debug executable subcommands you need to set the `"autoAttachChildProcesses": true` flag in your launch.json configuration.
+
+### Override exit handling
+
+By default Commander calls `process.exit` when it detects errors, or after displaying the help or version. You can override
+this behaviour and optionally supply a callback. The default override throws a `CommanderError`.
+
+The 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
+is not affected by the override which is called after the display.
+
+```js
+program.exitOverride();
+
+try {
+ program.parse(process.argv);
+} catch (err) {
+ // custom processing...
+}
+```
+
+## Examples
+
+Example file: [deploy](./examples/deploy)
+
+```js
+const { program } = require('commander');
+
+program
+ .version('0.1.0')
+ .option('-C, --chdir <path>', 'change the working directory')
+ .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
+ .option('-T, --no-tests', 'ignore test hook');
+
+program
+ .command('setup [env]')
+ .description('run setup commands for all envs')
+ .option("-s, --setup_mode [mode]", "Which setup mode to use")
+ .action(function(env, options){
+ const mode = options.setup_mode || "normal";
+ env = env || 'all';
+ console.log('setup for %s env(s) with %s mode', env, mode);
+ });
+
+program
+ .command('exec <cmd>')
+ .alias('ex')
+ .description('execute the given remote cmd')
+ .option("-e, --exec_mode <mode>", "Which exec mode to use")
+ .action(function(cmd, options){
+ console.log('exec "%s" using %s mode', cmd, options.exec_mode);
+ }).on('--help', function() {
+ console.log('');
+ console.log('Examples:');
+ console.log('');
+ console.log(' $ deploy exec sequential');
+ console.log(' $ deploy exec async');
+ });
+
+program.parse(process.argv);
+```
+
+More Demos can be found in the [examples](https://github.com/tj/commander.js/tree/master/examples) directory.
+
+## Support
+
+The current version of Commander is fully supported on Long Term Support versions of Node, and is likely to work with Node 6 but not tested.
+(For versions of Node below Node 6, use Commander 3.x or 2.x.)
+
+The main forum for free and community support is the project [Issues](https://github.com/tj/commander.js/issues) on GitHub.
+
+### Commander for enterprise
+
+Available as part of the Tidelift Subscription
+
+The 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)
diff --git a/src/node_modules/commander/index.js b/src/node_modules/commander/index.js
new file mode 100644
index 0000000..c85f725
--- /dev/null
+++ b/src/node_modules/commander/index.js
@@ -0,0 +1,1881 @@
+/**
+ * Module dependencies.
+ */
+
+const EventEmitter = require('events').EventEmitter;
+const spawn = require('child_process').spawn;
+const path = require('path');
+const fs = require('fs');
+
+// @ts-check
+
+class Option {
+ /**
+ * Initialize a new `Option` with the given `flags` and `description`.
+ *
+ * @param {string} flags
+ * @param {string} description
+ * @api public
+ */
+
+ constructor(flags, description) {
+ this.flags = flags;
+ this.required = flags.includes('<'); // A value must be supplied when the option is specified.
+ this.optional = flags.includes('['); // A value is optional when the option is specified.
+ // variadic test ignores <value,...> et al which might be used to describe custom splitting of single argument
+ this.variadic = /\w\.\.\.[>\]]$/.test(flags); // The option can take multiple values.
+ this.mandatory = false; // The option must have a value after parsing, which usually means it must be specified on command line.
+ const optionFlags = _parseOptionFlags(flags);
+ this.short = optionFlags.shortFlag;
+ this.long = optionFlags.longFlag;
+ this.negate = false;
+ if (this.long) {
+ this.negate = this.long.startsWith('--no-');
+ }
+ this.description = description || '';
+ this.defaultValue = undefined;
+ }
+
+ /**
+ * Return option name.
+ *
+ * @return {string}
+ * @api private
+ */
+
+ name() {
+ if (this.long) {
+ return this.long.replace(/^--/, '');
+ }
+ return this.short.replace(/^-/, '');
+ };
+
+ /**
+ * Return option name, in a camelcase format that can be used
+ * as a object attribute key.
+ *
+ * @return {string}
+ * @api private
+ */
+
+ attributeName() {
+ return camelcase(this.name().replace(/^no-/, ''));
+ };
+
+ /**
+ * Check if `arg` matches the short or long flag.
+ *
+ * @param {string} arg
+ * @return {boolean}
+ * @api private
+ */
+
+ is(arg) {
+ return this.short === arg || this.long === arg;
+ };
+}
+
+/**
+ * CommanderError class
+ * @class
+ */
+class CommanderError extends Error {
+ /**
+ * Constructs the CommanderError class
+ * @param {number} exitCode suggested exit code which could be used with process.exit
+ * @param {string} code an id string representing the error
+ * @param {string} message human-readable description of the error
+ * @constructor
+ */
+ constructor(exitCode, code, message) {
+ super(message);
+ // properly capture stack trace in Node.js
+ Error.captureStackTrace(this, this.constructor);
+ this.name = this.constructor.name;
+ this.code = code;
+ this.exitCode = exitCode;
+ this.nestedError = undefined;
+ }
+}
+
+class Command extends EventEmitter {
+ /**
+ * Initialize a new `Command`.
+ *
+ * @param {string} [name]
+ * @api public
+ */
+
+ constructor(name) {
+ super();
+ this.commands = [];
+ this.options = [];
+ this.parent = null;
+ this._allowUnknownOption = false;
+ this._args = [];
+ this.rawArgs = null;
+ this._scriptPath = null;
+ this._name = name || '';
+ this._optionValues = {};
+ this._storeOptionsAsProperties = true; // backwards compatible by default
+ this._storeOptionsAsPropertiesCalled = false;
+ this._passCommandToAction = true; // backwards compatible by default
+ this._actionResults = [];
+ this._actionHandler = null;
+ this._executableHandler = false;
+ this._executableFile = null; // custom name for executable
+ this._defaultCommandName = null;
+ this._exitCallback = null;
+ this._aliases = [];
+ this._combineFlagAndOptionalValue = true;
+
+ this._hidden = false;
+ this._hasHelpOption = true;
+ this._helpFlags = '-h, --help';
+ this._helpDescription = 'display help for command';
+ this._helpShortFlag = '-h';
+ this._helpLongFlag = '--help';
+ this._hasImplicitHelpCommand = undefined; // Deliberately undefined, not decided whether true or false
+ this._helpCommandName = 'help';
+ this._helpCommandnameAndArgs = 'help [command]';
+ this._helpCommandDescription = 'display help for command';
+ }
+
+ /**
+ * Define a command.
+ *
+ * There are two styles of command: pay attention to where to put the description.
+ *
+ * Examples:
+ *
+ * // Command implemented using action handler (description is supplied separately to `.command`)
+ * program
+ * .command('clone <source> [destination]')
+ * .description('clone a repository into a newly created directory')
+ * .action((source, destination) => {
+ * console.log('clone command called');
+ * });
+ *
+ * // Command implemented using separate executable file (description is second parameter to `.command`)
+ * program
+ * .command('start <service>', 'start named service')
+ * .command('stop [service]', 'stop named service, or all if no name supplied');
+ *
+ * @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
+ * @param {Object|string} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
+ * @param {Object} [execOpts] - configuration options (for executable)
+ * @return {Command} returns new command for action handler, or `this` for executable command
+ * @api public
+ */
+
+ command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
+ let desc = actionOptsOrExecDesc;
+ let opts = execOpts;
+ if (typeof desc === 'object' && desc !== null) {
+ opts = desc;
+ desc = null;
+ }
+ opts = opts || {};
+ const args = nameAndArgs.split(/ +/);
+ const cmd = this.createCommand(args.shift());
+
+ if (desc) {
+ cmd.description(desc);
+ cmd._executableHandler = true;
+ }
+ if (opts.isDefault) this._defaultCommandName = cmd._name;
+
+ cmd._hidden = !!(opts.noHelp || opts.hidden);
+ cmd._hasHelpOption = this._hasHelpOption;
+ cmd._helpFlags = this._helpFlags;
+ cmd._helpDescription = this._helpDescription;
+ cmd._helpShortFlag = this._helpShortFlag;
+ cmd._helpLongFlag = this._helpLongFlag;
+ cmd._helpCommandName = this._helpCommandName;
+ cmd._helpCommandnameAndArgs = this._helpCommandnameAndArgs;
+ cmd._helpCommandDescription = this._helpCommandDescription;
+ cmd._exitCallback = this._exitCallback;
+ cmd._storeOptionsAsProperties = this._storeOptionsAsProperties;
+ cmd._passCommandToAction = this._passCommandToAction;
+ cmd._combineFlagAndOptionalValue = this._combineFlagAndOptionalValue;
+
+ cmd._executableFile = opts.executableFile || null; // Custom name for executable file, set missing to null to match constructor
+ this.commands.push(cmd);
+ cmd._parseExpectedArgs(args);
+ cmd.parent = this;
+
+ if (desc) return this;
+ return cmd;
+ };
+
+ /**
+ * Factory routine to create a new unattached command.
+ *
+ * See .command() for creating an attached subcommand, which uses this routine to
+ * create the command. You can override createCommand to customise subcommands.
+ *
+ * @param {string} [name]
+ * @return {Command} new command
+ * @api public
+ */
+
+ createCommand(name) {
+ return new Command(name);
+ };
+
+ /**
+ * Add a prepared subcommand.
+ *
+ * See .command() for creating an attached subcommand which inherits settings from its parent.
+ *
+ * @param {Command} cmd - new subcommand
+ * @param {Object} [opts] - configuration options
+ * @return {Command} `this` command for chaining
+ * @api public
+ */
+
+ addCommand(cmd, opts) {
+ if (!cmd._name) throw new Error('Command passed to .addCommand() must have a name');
+
+ // To keep things simple, block automatic name generation for deeply nested executables.
+ // Fail fast and detect when adding rather than later when parsing.
+ function checkExplicitNames(commandArray) {
+ commandArray.forEach((cmd) => {
+ if (cmd._executableHandler && !cmd._executableFile) {
+ throw new Error(`Must specify executableFile for deeply nested executable: ${cmd.name()}`);
+ }
+ checkExplicitNames(cmd.commands);
+ });
+ }
+ checkExplicitNames(cmd.commands);
+
+ opts = opts || {};
+ if (opts.isDefault) this._defaultCommandName = cmd._name;
+ if (opts.noHelp || opts.hidden) cmd._hidden = true; // modifying passed command due to existing implementation
+
+ this.commands.push(cmd);
+ cmd.parent = this;
+ return this;
+ };
+
+ /**
+ * Define argument syntax for the command.
+ *
+ * @api public
+ */
+
+ arguments(desc) {
+ return this._parseExpectedArgs(desc.split(/ +/));
+ };
+
+ /**
+ * Override default decision whether to add implicit help command.
+ *
+ * addHelpCommand() // force on
+ * addHelpCommand(false); // force off
+ * addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
+ *
+ * @return {Command} `this` command for chaining
+ * @api public
+ */
+
+ addHelpCommand(enableOrNameAndArgs, description) {
+ if (enableOrNameAndArgs === false) {
+ this._hasImplicitHelpCommand = false;
+ } else {
+ this._hasImplicitHelpCommand = true;
+ if (typeof enableOrNameAndArgs === 'string') {
+ this._helpCommandName = enableOrNameAndArgs.split(' ')[0];
+ this._helpCommandnameAndArgs = enableOrNameAndArgs;
+ }
+ this._helpCommandDescription = description || this._helpCommandDescription;
+ }
+ return this;
+ };
+
+ /**
+ * @return {boolean}
+ * @api private
+ */
+
+ _lazyHasImplicitHelpCommand() {
+ if (this._hasImplicitHelpCommand === undefined) {
+ this._hasImplicitHelpCommand = this.commands.length && !this._actionHandler && !this._findCommand('help');
+ }
+ return this._hasImplicitHelpCommand;
+ };
+
+ /**
+ * Parse expected `args`.
+ *
+ * For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
+ *
+ * @param {Array} args
+ * @return {Command} `this` command for chaining
+ * @api private
+ */
+
+ _parseExpectedArgs(args) {
+ if (!args.length) return;
+ args.forEach((arg) => {
+ const argDetails = {
+ required: false,
+ name: '',
+ variadic: false
+ };
+
+ switch (arg[0]) {
+ case '<':
+ argDetails.required = true;
+ argDetails.name = arg.slice(1, -1);
+ break;
+ case '[':
+ argDetails.name = arg.slice(1, -1);
+ break;
+ }
+
+ if (argDetails.name.length > 3 && argDetails.name.slice(-3) === '...') {
+ argDetails.variadic = true;
+ argDetails.name = argDetails.name.slice(0, -3);
+ }
+ if (argDetails.name) {
+ this._args.push(argDetails);
+ }
+ });
+ this._args.forEach((arg, i) => {
+ if (arg.variadic && i < this._args.length - 1) {
+ throw new Error(`only the last argument can be variadic '${arg.name}'`);
+ }
+ });
+ return this;
+ };
+
+ /**
+ * Register callback to use as replacement for calling process.exit.
+ *
+ * @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
+ * @return {Command} `this` command for chaining
+ * @api public
+ */
+
+ exitOverride(fn) {
+ if (fn) {
+ this._exitCallback = fn;
+ } else {
+ this._exitCallback = (err) => {
+ if (err.code !== 'commander.executeSubCommandAsync') {
+ throw err;
+ } else {
+ // Async callback from spawn events, not useful to throw.
+ }
+ };
+ }
+ return this;
+ };
+
+ /**
+ * Call process.exit, and _exitCallback if defined.
+ *
+ * @param {number} exitCode exit code for using with process.exit
+ * @param {string} code an id string representing the error
+ * @param {string} message human-readable description of the error
+ * @return never
+ * @api private
+ */
+
+ _exit(exitCode, code, message) {
+ if (this._exitCallback) {
+ this._exitCallback(new CommanderError(exitCode, code, message));
+ // Expecting this line is not reached.
+ }
+ process.exit(exitCode);
+ };
+
+ /**
+ * Register callback `fn` for the command.
+ *
+ * Examples:
+ *
+ * program
+ * .command('help')
+ * .description('display verbose help')
+ * .action(function() {
+ * // output help here
+ * });
+ *
+ * @param {Function} fn
+ * @return {Command} `this` command for chaining
+ * @api public
+ */
+
+ action(fn) {
+ const listener = (args) => {
+ // The .action callback takes an extra parameter which is the command or options.
+ const expectedArgsCount = this._args.length;
+ const actionArgs = args.slice(0, expectedArgsCount);
+ if (this._passCommandToAction) {
+ actionArgs[expectedArgsCount] = this;
+ } else {
+ actionArgs[expectedArgsCount] = this.opts();
+ }
+ // Add the extra arguments so available too.
+ if (args.length > expectedArgsCount) {
+ actionArgs.push(args.slice(expectedArgsCount));
+ }
+
+ const actionResult = fn.apply(this, actionArgs);
+ // Remember result in case it is async. Assume parseAsync getting called on root.
+ let rootCommand = this;
+ while (rootCommand.parent) {
+ rootCommand = rootCommand.parent;
+ }
+ rootCommand._actionResults.push(actionResult);
+ };
+ this._actionHandler = listener;
+ return this;
+ };
+
+ /**
+ * Internal routine to check whether there is a clash storing option value with a Command property.
+ *
+ * @param {Option} option
+ * @api private
+ */
+
+ _checkForOptionNameClash(option) {
+ if (!this._storeOptionsAsProperties || this._storeOptionsAsPropertiesCalled) {
+ // Storing options safely, or user has been explicit and up to them.
+ return;
+ }
+ // User may override help, and hard to tell if worth warning.
+ if (option.name() === 'help') {
+ return;
+ }
+
+ const commandProperty = this._getOptionValue(option.attributeName());
+ if (commandProperty === undefined) {
+ // no clash
+ return;
+ }
+
+ let foundClash = true;
+ if (option.negate) {
+ // It is ok if define foo before --no-foo.
+ const positiveLongFlag = option.long.replace(/^--no-/, '--');
+ foundClash = !this._findOption(positiveLongFlag);
+ } else if (option.long) {
+ const negativeLongFlag = option.long.replace(/^--/, '--no-');
+ foundClash = !this._findOption(negativeLongFlag);
+ }
+
+ if (foundClash) {
+ throw new Error(`option '${option.name()}' clashes with existing property '${option.attributeName()}' on Command
+- call storeOptionsAsProperties(false) to store option values safely,
+- or call storeOptionsAsProperties(true) to suppress this check,
+- or change option name
+
+Read more on https://git.io/JJc0W`);
+ }
+ };
+
+ /**
+ * Internal implementation shared by .option() and .requiredOption()
+ *
+ * @param {Object} config
+ * @param {string} flags
+ * @param {string} description
+ * @param {Function|*} [fn] - custom option processing function or default value
+ * @param {*} [defaultValue]
+ * @return {Command} `this` command for chaining
+ * @api private
+ */
+
+ _optionEx(config, flags, description, fn, defaultValue) {
+ const option = new Option(flags, description);
+ const oname = option.name();
+ const name = option.attributeName();
+ option.mandatory = !!config.mandatory;
+
+ this._checkForOptionNameClash(option);
+
+ // default as 3rd arg
+ if (typeof fn !== 'function') {
+ if (fn instanceof RegExp) {
+ // This is a bit simplistic (especially no error messages), and probably better handled by caller using custom option processing.
+ // No longer documented in README, but still present for backwards compatibility.
+ const regex = fn;
+ fn = (val, def) => {
+ const m = regex.exec(val);
+ return m ? m[0] : def;
+ };
+ } else {
+ defaultValue = fn;
+ fn = null;
+ }
+ }
+
+ // preassign default value for --no-*, [optional], <required>, or plain flag if boolean value
+ if (option.negate || option.optional || option.required || typeof defaultValue === 'boolean') {
+ // when --no-foo we make sure default is true, unless a --foo option is already defined
+ if (option.negate) {
+ const positiveLongFlag = option.long.replace(/^--no-/, '--');
+ defaultValue = this._findOption(positiveLongFlag) ? this._getOptionValue(name) : true;
+ }
+ // preassign only if we have a default
+ if (defaultValue !== undefined) {
+ this._setOptionValue(name, defaultValue);
+ option.defaultValue = defaultValue;
+ }
+ }
+
+ // register the option
+ this.options.push(option);
+
+ // when it's passed assign the value
+ // and conditionally invoke the callback
+ this.on('option:' + oname, (val) => {
+ const oldValue = this._getOptionValue(name);
+
+ // custom processing
+ if (val !== null && fn) {
+ val = fn(val, oldValue === undefined ? defaultValue : oldValue);
+ } else if (val !== null && option.variadic) {
+ if (oldValue === defaultValue || !Array.isArray(oldValue)) {
+ val = [val];
+ } else {
+ val = oldValue.concat(val);
+ }
+ }
+
+ // unassigned or boolean value
+ if (typeof oldValue === 'boolean' || typeof oldValue === 'undefined') {
+ // if no value, negate false, and we have a default, then use it!
+ if (val == null) {
+ this._setOptionValue(name, option.negate
+ ? false
+ : defaultValue || true);
+ } else {
+ this._setOptionValue(name, val);
+ }
+ } else if (val !== null) {
+ // reassign
+ this._setOptionValue(name, option.negate ? false : val);
+ }
+ });
+
+ return this;
+ };
+
+ /**
+ * Define option with `flags`, `description` and optional
+ * coercion `fn`.
+ *
+ * The `flags` string should contain both the short and long flags,
+ * separated by comma, a pipe or space. The following are all valid
+ * all will output this way when `--help` is used.
+ *
+ * "-p, --pepper"
+ * "-p|--pepper"
+ * "-p --pepper"
+ *
+ * Examples:
+ *
+ * // simple boolean defaulting to undefined
+ * program.option('-p, --pepper', 'add pepper');
+ *
+ * program.pepper
+ * // => undefined
+ *
+ * --pepper
+ * program.pepper
+ * // => true
+ *
+ * // simple boolean defaulting to true (unless non-negated option is also defined)
+ * program.option('-C, --no-cheese', 'remove cheese');
+ *
+ * program.cheese
+ * // => true
+ *
+ * --no-cheese
+ * program.cheese
+ * // => false
+ *
+ * // required argument
+ * program.option('-C, --chdir <path>', 'change the working directory');
+ *
+ * --chdir /tmp
+ * program.chdir
+ * // => "/tmp"
+ *
+ * // optional argument
+ * program.option('-c, --cheese [type]', 'add cheese [marble]');
+ *
+ * @param {string} flags
+ * @param {string} description
+ * @param {Function|*} [fn] - custom option processing function or default value
+ * @param {*} [defaultValue]
+ * @return {Command} `this` command for chaining
+ * @api public
+ */
+
+ option(flags, description, fn, defaultValue) {
+ return this._optionEx({}, flags, description, fn, defaultValue);
+ };
+
+ /**
+ * Add a required option which must have a value after parsing. This usually means
+ * the option must be specified on the command line. (Otherwise the same as .option().)
+ *
+ * The `flags` string should contain both the short and long flags, separated by comma, a pipe or space.
+ *
+ * @param {string} flags
+ * @param {string} description
+ * @param {Function|*} [fn] - custom option processing function or default value
+ * @param {*} [defaultValue]
+ * @return {Command} `this` command for chaining
+ * @api public
+ */
+
+ requiredOption(flags, description, fn, defaultValue) {
+ return this._optionEx({ mandatory: true }, flags, description, fn, defaultValue);
+ };
+
+ /**
+ * Alter parsing of short flags with optional values.
+ *
+ * Examples:
+ *
+ * // for `.option('-f,--flag [value]'):
+ * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
+ * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
+ *
+ * @param {Boolean} [arg] - if `true` or omitted, an optional value can be specified directly after the flag.
+ * @api public
+ */
+ combineFlagAndOptionalValue(arg) {
+ this._combineFlagAndOptionalValue = (arg === undefined) || arg;
+ return this;
+ };
+
+ /**
+ * Allow unknown options on the command line.
+ *
+ * @param {Boolean} [arg] - if `true` or omitted, no error will be thrown
+ * for unknown options.
+ * @api public
+ */
+ allowUnknownOption(arg) {
+ this._allowUnknownOption = (arg === undefined) || arg;
+ return this;
+ };
+
+ /**
+ * Whether to store option values as properties on command object,
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
+ *
+ * @param {boolean} value
+ * @return {Command} `this` command for chaining
+ * @api public
+ */
+
+ storeOptionsAsProperties(value) {
+ this._storeOptionsAsPropertiesCalled = true;
+ this._storeOptionsAsProperties = (value === undefined) || value;
+ if (this.options.length) {
+ throw new Error('call .storeOptionsAsProperties() before adding options');
+ }
+ return this;
+ };
+
+ /**
+ * Whether to pass command to action handler,
+ * or just the options (specify false).
+ *
+ * @param {boolean} value
+ * @return {Command} `this` command for chaining
+ * @api public
+ */
+
+ passCommandToAction(value) {
+ this._passCommandToAction = (value === undefined) || value;
+ return this;
+ };
+
+ /**
+ * Store option value
+ *
+ * @param {string} key
+ * @param {Object} value
+ * @api private
+ */
+
+ _setOptionValue(key, value) {
+ if (this._storeOptionsAsProperties) {
+ this[key] = value;
+ } else {
+ this._optionValues[key] = value;
+ }
+ };
+
+ /**
+ * Retrieve option value
+ *
+ * @param {string} key
+ * @return {Object} value
+ * @api private
+ */
+
+ _getOptionValue(key) {
+ if (this._storeOptionsAsProperties) {
+ return this[key];
+ }
+ return this._optionValues[key];
+ };
+
+ /**
+ * Parse `argv`, setting options and invoking commands when defined.
+ *
+ * The default expectation is that the arguments are from node and have the application as argv[0]
+ * and the script being run in argv[1], with user parameters after that.
+ *
+ * Examples:
+ *
+ * program.parse(process.argv);
+ * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
+ *
+ * @param {string[]} [argv] - optional, defaults to process.argv
+ * @param {Object} [parseOptions] - optionally specify style of options with from: node/user/electron
+ * @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
+ * @return {Command} `this` command for chaining
+ * @api public
+ */
+
+ parse(argv, parseOptions) {
+ if (argv !== undefined && !Array.isArray(argv)) {
+ throw new Error('first parameter to parse must be array or undefined');
+ }
+ parseOptions = parseOptions || {};
+
+ // Default to using process.argv
+ if (argv === undefined) {
+ argv = process.argv;
+ // @ts-ignore
+ if (process.versions && process.versions.electron) {
+ parseOptions.from = 'electron';
+ }
+ }
+ this.rawArgs = argv.slice();
+
+ // make it a little easier for callers by supporting various argv conventions
+ let userArgs;
+ switch (parseOptions.from) {
+ case undefined:
+ case 'node':
+ this._scriptPath = argv[1];
+ userArgs = argv.slice(2);
+ break;
+ case 'electron':
+ // @ts-ignore
+ if (process.defaultApp) {
+ this._scriptPath = argv[1];
+ userArgs = argv.slice(2);
+ } else {
+ userArgs = argv.slice(1);
+ }
+ break;
+ case 'user':
+ userArgs = argv.slice(0);
+ break;
+ default:
+ throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
+ }
+ if (!this._scriptPath && process.mainModule) {
+ this._scriptPath = process.mainModule.filename;
+ }
+
+ // Guess name, used in usage in help.
+ this._name = this._name || (this._scriptPath && path.basename(this._scriptPath, path.extname(this._scriptPath)));
+
+ // Let's go!
+ this._parseCommand([], userArgs);
+
+ return this;
+ };
+
+ /**
+ * Parse `argv`, setting options and invoking commands when defined.
+ *
+ * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
+ *
+ * The default expectation is that the arguments are from node and have the application as argv[0]
+ * and the script being run in argv[1], with user parameters after that.
+ *
+ * Examples:
+ *
+ * program.parseAsync(process.argv);
+ * program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
+ * program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
+ *
+ * @param {string[]} [argv]
+ * @param {Object} [parseOptions]
+ * @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
+ * @return {Promise}
+ * @api public
+ */
+
+ parseAsync(argv, parseOptions) {
+ this.parse(argv, parseOptions);
+ return Promise.all(this._actionResults).then(() => this);
+ };
+
+ /**
+ * Execute a sub-command executable.
+ *
+ * @api private
+ */
+
+ _executeSubCommand(subcommand, args) {
+ args = args.slice();
+ let launchWithNode = false; // Use node for source targets so do not need to get permissions correct, and on Windows.
+ const sourceExt = ['.js', '.ts', '.tsx', '.mjs'];
+
+ // Not checking for help first. Unlikely to have mandatory and executable, and can't robustly test for help flags in external command.
+ this._checkForMissingMandatoryOptions();
+
+ // Want the entry script as the reference for command name and directory for searching for other files.
+ let scriptPath = this._scriptPath;
+ // Fallback in case not set, due to how Command created or called.
+ if (!scriptPath && process.mainModule) {
+ scriptPath = process.mainModule.filename;
+ }
+
+ let baseDir;
+ try {
+ const resolvedLink = fs.realpathSync(scriptPath);
+ baseDir = path.dirname(resolvedLink);
+ } catch (e) {
+ baseDir = '.'; // dummy, probably not going to find executable!
+ }
+
+ // name of the subcommand, like `pm-install`
+ let bin = path.basename(scriptPath, path.extname(scriptPath)) + '-' + subcommand._name;
+ if (subcommand._executableFile) {
+ bin = subcommand._executableFile;
+ }
+
+ const localBin = path.join(baseDir, bin);
+ if (fs.existsSync(localBin)) {
+ // prefer local `./<bin>` to bin in the $PATH
+ bin = localBin;
+ } else {
+ // Look for source files.
+ sourceExt.forEach((ext) => {
+ if (fs.existsSync(`${localBin}${ext}`)) {
+ bin = `${localBin}${ext}`;
+ }
+ });
+ }
+ launchWithNode = sourceExt.includes(path.extname(bin));
+
+ let proc;
+ if (process.platform !== 'win32') {
+ if (launchWithNode) {
+ args.unshift(bin);
+ // add executable arguments to spawn
+ args = incrementNodeInspectorPort(process.execArgv).concat(args);
+
+ proc = spawn(process.argv[0], args, { stdio: 'inherit' });
+ } else {
+ proc = spawn(bin, args, { stdio: 'inherit' });
+ }
+ } else {
+ args.unshift(bin);
+ // add executable arguments to spawn
+ args = incrementNodeInspectorPort(process.execArgv).concat(args);
+ proc = spawn(process.execPath, args, { stdio: 'inherit' });
+ }
+
+ const signals = ['SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGINT', 'SIGHUP'];
+ signals.forEach((signal) => {
+ // @ts-ignore
+ process.on(signal, () => {
+ if (proc.killed === false && proc.exitCode === null) {
+ proc.kill(signal);
+ }
+ });
+ });
+
+ // By default terminate process when spawned process terminates.
+ // Suppressing the exit if exitCallback defined is a bit messy and of limited use, but does allow process to stay running!
+ const exitCallback = this._exitCallback;
+ if (!exitCallback) {
+ proc.on('close', process.exit.bind(process));
+ } else {
+ proc.on('close', () => {
+ exitCallback(new CommanderError(process.exitCode || 0, 'commander.executeSubCommandAsync', '(close)'));
+ });
+ }
+ proc.on('error', (err) => {
+ // @ts-ignore
+ if (err.code === 'ENOENT') {
+ const executableMissing = `'${bin}' does not exist
+ - if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
+ - if the default executable name is not suitable, use the executableFile option to supply a custom name`;
+ throw new Error(executableMissing);
+ // @ts-ignore
+ } else if (err.code === 'EACCES') {
+ throw new Error(`'${bin}' not executable`);
+ }
+ if (!exitCallback) {
+ process.exit(1);
+ } else {
+ const wrappedError = new CommanderError(1, 'commander.executeSubCommandAsync', '(error)');
+ wrappedError.nestedError = err;
+ exitCallback(wrappedError);
+ }
+ });
+
+ // Store the reference to the child process
+ this.runningCommand = proc;
+ };
+
+ /**
+ * @api private
+ */
+ _dispatchSubcommand(commandName, operands, unknown) {
+ const subCommand = this._findCommand(commandName);
+ if (!subCommand) this._helpAndError();
+
+ if (subCommand._executableHandler) {
+ this._executeSubCommand(subCommand, operands.concat(unknown));
+ } else {
+ subCommand._parseCommand(operands, unknown);
+ }
+ };
+
+ /**
+ * Process arguments in context of this command.
+ *
+ * @api private
+ */
+
+ _parseCommand(operands, unknown) {
+ const parsed = this.parseOptions(unknown);
+ operands = operands.concat(parsed.operands);
+ unknown = parsed.unknown;
+ this.args = operands.concat(unknown);
+
+ if (operands && this._findCommand(operands[0])) {
+ this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
+ } else if (this._lazyHasImplicitHelpCommand() && operands[0] === this._helpCommandName) {
+ if (operands.length === 1) {
+ this.help();
+ } else {
+ this._dispatchSubcommand(operands[1], [], [this._helpLongFlag]);
+ }
+ } else if (this._defaultCommandName) {
+ outputHelpIfRequested(this, unknown); // Run the help for default command from parent rather than passing to default command
+ this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
+ } else {
+ if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
+ // probably missing subcommand and no handler, user needs help
+ this._helpAndError();
+ }
+
+ outputHelpIfRequested(this, parsed.unknown);
+ this._checkForMissingMandatoryOptions();
+ if (parsed.unknown.length > 0) {
+ this.unknownOption(parsed.unknown[0]);
+ }
+
+ if (this._actionHandler) {
+ const args = this.args.slice();
+ this._args.forEach((arg, i) => {
+ if (arg.required && args[i] == null) {
+ this.missingArgument(arg.name);
+ } else if (arg.variadic) {
+ args[i] = args.splice(i);
+ }
+ });
+
+ this._actionHandler(args);
+ this.emit('command:' + this.name(), operands, unknown);
+ } else if (operands.length) {
+ if (this._findCommand('*')) {
+ this._dispatchSubcommand('*', operands, unknown);
+ } else if (this.listenerCount('command:*')) {
+ this.emit('command:*', operands, unknown);
+ } else if (this.commands.length) {
+ this.unknownCommand();
+ }
+ } else if (this.commands.length) {
+ // This command has subcommands and nothing hooked up at this level, so display help.
+ this._helpAndError();
+ } else {
+ // fall through for caller to handle after calling .parse()
+ }
+ }
+ };
+
+ /**
+ * Find matching command.
+ *
+ * @api private
+ */
+ _findCommand(name) {
+ if (!name) return undefined;
+ return this.commands.find(cmd => cmd._name === name || cmd._aliases.includes(name));
+ };
+
+ /**
+ * Return an option matching `arg` if any.
+ *
+ * @param {string} arg
+ * @return {Option}
+ * @api private
+ */
+
+ _findOption(arg) {
+ return this.options.find(option => option.is(arg));
+ };
+
+ /**
+ * Display an error message if a mandatory option does not have a value.
+ * Lazy calling after checking for help flags from leaf subcommand.
+ *
+ * @api private
+ */
+
+ _checkForMissingMandatoryOptions() {
+ // Walk up hierarchy so can call in subcommand after checking for displaying help.
+ for (let cmd = this; cmd; cmd = cmd.parent) {
+ cmd.options.forEach((anOption) => {
+ if (anOption.mandatory && (cmd._getOptionValue(anOption.attributeName()) === undefined)) {
+ cmd.missingMandatoryOptionValue(anOption);
+ }
+ });
+ }
+ };
+
+ /**
+ * Parse options from `argv` removing known options,
+ * and return argv split into operands and unknown arguments.
+ *
+ * Examples:
+ *
+ * argv => operands, unknown
+ * --known kkk op => [op], []
+ * op --known kkk => [op], []
+ * sub --unknown uuu op => [sub], [--unknown uuu op]
+ * sub -- --unknown uuu op => [sub --unknown uuu op], []
+ *
+ * @param {String[]} argv
+ * @return {{operands: String[], unknown: String[]}}
+ * @api public
+ */
+
+ parseOptions(argv) {
+ const operands = []; // operands, not options or values
+ const unknown = []; // first unknown option and remaining unknown args
+ let dest = operands;
+ const args = argv.slice();
+
+ function maybeOption(arg) {
+ return arg.length > 1 && arg[0] === '-';
+ }
+
+ // parse options
+ let activeVariadicOption = null;
+ while (args.length) {
+ const arg = args.shift();
+
+ // literal
+ if (arg === '--') {
+ if (dest === unknown) dest.push(arg);
+ dest.push(...args);
+ break;
+ }
+
+ if (activeVariadicOption && !maybeOption(arg)) {
+ this.emit(`option:${activeVariadicOption.name()}`, arg);
+ continue;
+ }
+ activeVariadicOption = null;
+
+ if (maybeOption(arg)) {
+ const option = this._findOption(arg);
+ // recognised option, call listener to assign value with possible custom processing
+ if (option) {
+ if (option.required) {
+ const value = args.shift();
+ if (value === undefined) this.optionMissingArgument(option);
+ this.emit(`option:${option.name()}`, value);
+ } else if (option.optional) {
+ let value = null;
+ // historical behaviour is optional value is following arg unless an option
+ if (args.length > 0 && !maybeOption(args[0])) {
+ value = args.shift();
+ }
+ this.emit(`option:${option.name()}`, value);
+ } else { // boolean flag
+ this.emit(`option:${option.name()}`);
+ }
+ activeVariadicOption = option.variadic ? option : null;
+ continue;
+ }
+ }
+
+ // Look for combo options following single dash, eat first one if known.
+ if (arg.length > 2 && arg[0] === '-' && arg[1] !== '-') {
+ const option = this._findOption(`-${arg[1]}`);
+ if (option) {
+ if (option.required || (option.optional && this._combineFlagAndOptionalValue)) {
+ // option with value following in same argument
+ this.emit(`option:${option.name()}`, arg.slice(2));
+ } else {
+ // boolean option, emit and put back remainder of arg for further processing
+ this.emit(`option:${option.name()}`);
+ args.unshift(`-${arg.slice(2)}`);
+ }
+ continue;
+ }
+ }
+
+ // Look for known long flag with value, like --foo=bar
+ if (/^--[^=]+=/.test(arg)) {
+ const index = arg.indexOf('=');
+ const option = this._findOption(arg.slice(0, index));
+ if (option && (option.required || option.optional)) {
+ this.emit(`option:${option.name()}`, arg.slice(index + 1));
+ continue;
+ }
+ }
+
+ // looks like an option but unknown, unknowns from here
+ if (arg.length > 1 && arg[0] === '-') {
+ dest = unknown;
+ }
+
+ // add arg
+ dest.push(arg);
+ }
+
+ return { operands, unknown };
+ };
+
+ /**
+ * Return an object containing options as key-value pairs
+ *
+ * @return {Object}
+ * @api public
+ */
+ opts() {
+ if (this._storeOptionsAsProperties) {
+ // Preserve original behaviour so backwards compatible when still using properties
+ const result = {};
+ const len = this.options.length;
+
+ for (let i = 0; i < len; i++) {
+ const key = this.options[i].attributeName();
+ result[key] = key === this._versionOptionName ? this._version : this[key];
+ }
+ return result;
+ }
+
+ return this._optionValues;
+ };
+
+ /**
+ * Argument `name` is missing.
+ *
+ * @param {string} name
+ * @api private
+ */
+
+ missingArgument(name) {
+ const message = `error: missing required argument '${name}'`;
+ console.error(message);
+ this._exit(1, 'commander.missingArgument', message);
+ };
+
+ /**
+ * `Option` is missing an argument, but received `flag` or nothing.
+ *
+ * @param {Option} option
+ * @param {string} [flag]
+ * @api private
+ */
+
+ optionMissingArgument(option, flag) {
+ let message;
+ if (flag) {
+ message = `error: option '${option.flags}' argument missing, got '${flag}'`;
+ } else {
+ message = `error: option '${option.flags}' argument missing`;
+ }
+ console.error(message);
+ this._exit(1, 'commander.optionMissingArgument', message);
+ };
+
+ /**
+ * `Option` does not have a value, and is a mandatory option.
+ *
+ * @param {Option} option
+ * @api private
+ */
+
+ missingMandatoryOptionValue(option) {
+ const message = `error: required option '${option.flags}' not specified`;
+ console.error(message);
+ this._exit(1, 'commander.missingMandatoryOptionValue', message);
+ };
+
+ /**
+ * Unknown option `flag`.
+ *
+ * @param {string} flag
+ * @api private
+ */
+
+ unknownOption(flag) {
+ if (this._allowUnknownOption) return;
+ const message = `error: unknown option '${flag}'`;
+ console.error(message);
+ this._exit(1, 'commander.unknownOption', message);
+ };
+
+ /**
+ * Unknown command.
+ *
+ * @api private
+ */
+
+ unknownCommand() {
+ const partCommands = [this.name()];
+ for (let parentCmd = this.parent; parentCmd; parentCmd = parentCmd.parent) {
+ partCommands.unshift(parentCmd.name());
+ }
+ const fullCommand = partCommands.join(' ');
+ const message = `error: unknown command '${this.args[0]}'.` +
+ (this._hasHelpOption ? ` See '${fullCommand} ${this._helpLongFlag}'.` : '');
+ console.error(message);
+ this._exit(1, 'commander.unknownCommand', message);
+ };
+
+ /**
+ * Set the program version to `str`.
+ *
+ * This method auto-registers the "-V, --version" flag
+ * which will print the version number when passed.
+ *
+ * You can optionally supply the flags and description to override the defaults.
+ *
+ * @param {string} str
+ * @param {string} [flags]
+ * @param {string} [description]
+ * @return {this | string} `this` command for chaining, or version string if no arguments
+ * @api public
+ */
+
+ version(str, flags, description) {
+ if (str === undefined) return this._version;
+ this._version = str;
+ flags = flags || '-V, --version';
+ description = description || 'output the version number';
+ const versionOption = new Option(flags, description);
+ this._versionOptionName = versionOption.attributeName();
+ this.options.push(versionOption);
+ this.on('option:' + versionOption.name(), () => {
+ process.stdout.write(str + '\n');
+ this._exit(0, 'commander.version', str);
+ });
+ return this;
+ };
+
+ /**
+ * Set the description to `str`.
+ *
+ * @param {string} str
+ * @param {Object} [argsDescription]
+ * @return {string|Command}
+ * @api public
+ */
+
+ description(str, argsDescription) {
+ if (str === undefined && argsDescription === undefined) return this._description;
+ this._description = str;
+ this._argsDescription = argsDescription;
+ return this;
+ };
+
+ /**
+ * Set an alias for the command.
+ *
+ * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
+ *
+ * @param {string} [alias]
+ * @return {string|Command}
+ * @api public
+ */
+
+ alias(alias) {
+ if (alias === undefined) return this._aliases[0]; // just return first, for backwards compatibility
+
+ let command = this;
+ if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
+ // assume adding alias for last added executable subcommand, rather than this
+ command = this.commands[this.commands.length - 1];
+ }
+
+ if (alias === command._name) throw new Error('Command alias can\'t be the same as its name');
+
+ command._aliases.push(alias);
+ return this;
+ };
+
+ /**
+ * Set aliases for the command.
+ *
+ * Only the first alias is shown in the auto-generated help.
+ *
+ * @param {string[]} [aliases]
+ * @return {string[]|Command}
+ * @api public
+ */
+
+ aliases(aliases) {
+ // Getter for the array of aliases is the main reason for having aliases() in addition to alias().
+ if (aliases === undefined) return this._aliases;
+
+ aliases.forEach((alias) => this.alias(alias));
+ return this;
+ };
+
+ /**
+ * Set / get the command usage `str`.
+ *
+ * @param {string} [str]
+ * @return {String|Command}
+ * @api public
+ */
+
+ usage(str) {
+ if (str === undefined) {
+ if (this._usage) return this._usage;
+
+ const args = this._args.map((arg) => {
+ return humanReadableArgName(arg);
+ });
+ return [].concat(
+ (this.options.length || this._hasHelpOption ? '[options]' : []),
+ (this.commands.length ? '[command]' : []),
+ (this._args.length ? args : [])
+ ).join(' ');
+ }
+
+ this._usage = str;
+ return this;
+ };
+
+ /**
+ * Get or set the name of the command
+ *
+ * @param {string} [str]
+ * @return {String|Command}
+ * @api public
+ */
+
+ name(str) {
+ if (str === undefined) return this._name;
+ this._name = str;
+ return this;
+ };
+
+ /**
+ * Return prepared commands.
+ *
+ * @return {Array}
+ * @api private
+ */
+
+ prepareCommands() {
+ const commandDetails = this.commands.filter((cmd) => {
+ return !cmd._hidden;
+ }).map((cmd) => {
+ const args = cmd._args.map((arg) => {
+ return humanReadableArgName(arg);
+ }).join(' ');
+
+ return [
+ cmd._name +
+ (cmd._aliases[0] ? '|' + cmd._aliases[0] : '') +
+ (cmd.options.length ? ' [options]' : '') +
+ (args ? ' ' + args : ''),
+ cmd._description
+ ];
+ });
+
+ if (this._lazyHasImplicitHelpCommand()) {
+ commandDetails.push([this._helpCommandnameAndArgs, this._helpCommandDescription]);
+ }
+ return commandDetails;
+ };
+
+ /**
+ * Return the largest command length.
+ *
+ * @return {number}
+ * @api private
+ */
+
+ largestCommandLength() {
+ const commands = this.prepareCommands();
+ return commands.reduce((max, command) => {
+ return Math.max(max, command[0].length);
+ }, 0);
+ };
+
+ /**
+ * Return the largest option length.
+ *
+ * @return {number}
+ * @api private
+ */
+
+ largestOptionLength() {
+ const options = [].slice.call(this.options);
+ options.push({
+ flags: this._helpFlags
+ });
+
+ return options.reduce((max, option) => {
+ return Math.max(max, option.flags.length);
+ }, 0);
+ };
+
+ /**
+ * Return the largest arg length.
+ *
+ * @return {number}
+ * @api private
+ */
+
+ largestArgLength() {
+ return this._args.reduce((max, arg) => {
+ return Math.max(max, arg.name.length);
+ }, 0);
+ };
+
+ /**
+ * Return the pad width.
+ *
+ * @return {number}
+ * @api private
+ */
+
+ padWidth() {
+ let width = this.largestOptionLength();
+ if (this._argsDescription && this._args.length) {
+ if (this.largestArgLength() > width) {
+ width = this.largestArgLength();
+ }
+ }
+
+ if (this.commands && this.commands.length) {
+ if (this.largestCommandLength() > width) {
+ width = this.largestCommandLength();
+ }
+ }
+
+ return width;
+ };
+
+ /**
+ * Return help for options.
+ *
+ * @return {string}
+ * @api private
+ */
+
+ optionHelp() {
+ const width = this.padWidth();
+ const columns = process.stdout.columns || 80;
+ const descriptionWidth = columns - width - 4;
+ function padOptionDetails(flags, description) {
+ return pad(flags, width) + ' ' + optionalWrap(description, descriptionWidth, width + 2);
+ };
+
+ // Explicit options (including version)
+ const help = this.options.map((option) => {
+ const fullDesc = option.description +
+ ((!option.negate && option.defaultValue !== undefined) ? ' (default: ' + JSON.stringify(option.defaultValue) + ')' : '');
+ return padOptionDetails(option.flags, fullDesc);
+ });
+
+ // Implicit help
+ const showShortHelpFlag = this._hasHelpOption && this._helpShortFlag && !this._findOption(this._helpShortFlag);
+ const showLongHelpFlag = this._hasHelpOption && !this._findOption(this._helpLongFlag);
+ if (showShortHelpFlag || showLongHelpFlag) {
+ let helpFlags = this._helpFlags;
+ if (!showShortHelpFlag) {
+ helpFlags = this._helpLongFlag;
+ } else if (!showLongHelpFlag) {
+ helpFlags = this._helpShortFlag;
+ }
+ help.push(padOptionDetails(helpFlags, this._helpDescription));
+ }
+
+ return help.join('\n');
+ };
+
+ /**
+ * Return command help documentation.
+ *
+ * @return {string}
+ * @api private
+ */
+
+ commandHelp() {
+ if (!this.commands.length && !this._lazyHasImplicitHelpCommand()) return '';
+
+ const commands = this.prepareCommands();
+ const width = this.padWidth();
+
+ const columns = process.stdout.columns || 80;
+ const descriptionWidth = columns - width - 4;
+
+ return [
+ 'Commands:',
+ commands.map((cmd) => {
+ const desc = cmd[1] ? ' ' + cmd[1] : '';
+ return (desc ? pad(cmd[0], width) : cmd[0]) + optionalWrap(desc, descriptionWidth, width + 2);
+ }).join('\n').replace(/^/gm, ' '),
+ ''
+ ].join('\n');
+ };
+
+ /**
+ * Return program help documentation.
+ *
+ * @return {string}
+ * @api public
+ */
+
+ helpInformation() {
+ let desc = [];
+ if (this._description) {
+ desc = [
+ this._description,
+ ''
+ ];
+
+ const argsDescription = this._argsDescription;
+ if (argsDescription && this._args.length) {
+ const width = this.padWidth();
+ const columns = process.stdout.columns || 80;
+ const descriptionWidth = columns - width - 5;
+ desc.push('Arguments:');
+ this._args.forEach((arg) => {
+ desc.push(' ' + pad(arg.name, width) + ' ' + wrap(argsDescription[arg.name] || '', descriptionWidth, width + 4));
+ });
+ desc.push('');
+ }
+ }
+
+ let cmdName = this._name;
+ if (this._aliases[0]) {
+ cmdName = cmdName + '|' + this._aliases[0];
+ }
+ let parentCmdNames = '';
+ for (let parentCmd = this.parent; parentCmd; parentCmd = parentCmd.parent) {
+ parentCmdNames = parentCmd.name() + ' ' + parentCmdNames;
+ }
+ const usage = [
+ 'Usage: ' + parentCmdNames + cmdName + ' ' + this.usage(),
+ ''
+ ];
+
+ let cmds = [];
+ const commandHelp = this.commandHelp();
+ if (commandHelp) cmds = [commandHelp];
+
+ let options = [];
+ if (this._hasHelpOption || this.options.length > 0) {
+ options = [
+ 'Options:',
+ '' + this.optionHelp().replace(/^/gm, ' '),
+ ''
+ ];
+ }
+
+ return usage
+ .concat(desc)
+ .concat(options)
+ .concat(cmds)
+ .join('\n');
+ };
+
+ /**
+ * Output help information for this command.
+ *
+ * When listener(s) are available for the helpLongFlag
+ * those callbacks are invoked.
+ *
+ * @api public
+ */
+
+ outputHelp(cb) {
+ if (!cb) {
+ cb = (passthru) => {
+ return passthru;
+ };
+ }
+ const cbOutput = cb(this.helpInformation());
+ if (typeof cbOutput !== 'string' && !Buffer.isBuffer(cbOutput)) {
+ throw new Error('outputHelp callback must return a string or a Buffer');
+ }
+ process.stdout.write(cbOutput);
+ this.emit(this._helpLongFlag);
+ };
+
+ /**
+ * You can pass in flags and a description to override the help
+ * flags and help description for your command. Pass in false to
+ * disable the built-in help option.
+ *
+ * @param {string | boolean} [flags]
+ * @param {string} [description]
+ * @return {Command} `this` command for chaining
+ * @api public
+ */
+
+ helpOption(flags, description) {
+ if (typeof flags === 'boolean') {
+ this._hasHelpOption = flags;
+ return this;
+ }
+ this._helpFlags = flags || this._helpFlags;
+ this._helpDescription = description || this._helpDescription;
+
+ const helpFlags = _parseOptionFlags(this._helpFlags);
+ this._helpShortFlag = helpFlags.shortFlag;
+ this._helpLongFlag = helpFlags.longFlag;
+
+ return this;
+ };
+
+ /**
+ * Output help information and exit.
+ *
+ * @param {Function} [cb]
+ * @api public
+ */
+
+ help(cb) {
+ this.outputHelp(cb);
+ // exitCode: preserving original behaviour which was calling process.exit()
+ // message: do not have all displayed text available so only passing placeholder.
+ this._exit(process.exitCode || 0, 'commander.help', '(outputHelp)');
+ };
+
+ /**
+ * Output help information and exit. Display for error situations.
+ *
+ * @api private
+ */
+
+ _helpAndError() {
+ this.outputHelp();
+ // message: do not have all displayed text available so only passing placeholder.
+ this._exit(1, 'commander.help', '(outputHelp)');
+ };
+};
+
+/**
+ * Expose the root command.
+ */
+
+exports = module.exports = new Command();
+exports.program = exports; // More explicit access to global command.
+
+/**
+ * Expose classes
+ */
+
+exports.Command = Command;
+exports.Option = Option;
+exports.CommanderError = CommanderError;
+
+/**
+ * Camel-case the given `flag`
+ *
+ * @param {string} flag
+ * @return {string}
+ * @api private
+ */
+
+function camelcase(flag) {
+ return flag.split('-').reduce((str, word) => {
+ return str + word[0].toUpperCase() + word.slice(1);
+ });
+}
+
+/**
+ * Pad `str` to `width`.
+ *
+ * @param {string} str
+ * @param {number} width
+ * @return {string}
+ * @api private
+ */
+
+function pad(str, width) {
+ const len = Math.max(0, width - str.length);
+ return str + Array(len + 1).join(' ');
+}
+
+/**
+ * Wraps the given string with line breaks at the specified width while breaking
+ * words and indenting every but the first line on the left.
+ *
+ * @param {string} str
+ * @param {number} width
+ * @param {number} indent
+ * @return {string}
+ * @api private
+ */
+function wrap(str, width, indent) {
+ const regex = new RegExp('.{1,' + (width - 1) + '}([\\s\u200B]|$)|[^\\s\u200B]+?([\\s\u200B]|$)', 'g');
+ const lines = str.match(regex) || [];
+ return lines.map((line, i) => {
+ if (line.slice(-1) === '\n') {
+ line = line.slice(0, line.length - 1);
+ }
+ return ((i > 0 && indent) ? Array(indent + 1).join(' ') : '') + line.trimRight();
+ }).join('\n');
+}
+
+/**
+ * Optionally wrap the given str to a max width of width characters per line
+ * while indenting with indent spaces. Do not wrap if insufficient width or
+ * string is manually formatted.
+ *
+ * @param {string} str
+ * @param {number} width
+ * @param {number} indent
+ * @return {string}
+ * @api private
+ */
+function optionalWrap(str, width, indent) {
+ // Detect manually wrapped and indented strings by searching for line breaks
+ // followed by multiple spaces/tabs.
+ if (str.match(/[\n]\s+/)) return str;
+ // Do not wrap to narrow columns (or can end up with a word per line).
+ const minWidth = 40;
+ if (width < minWidth) return str;
+
+ return wrap(str, width, indent);
+}
+
+/**
+ * Output help information if help flags specified
+ *
+ * @param {Command} cmd - command to output help for
+ * @param {Array} args - array of options to search for help flags
+ * @api private
+ */
+
+function outputHelpIfRequested(cmd, args) {
+ const helpOption = cmd._hasHelpOption && args.find(arg => arg === cmd._helpLongFlag || arg === cmd._helpShortFlag);
+ if (helpOption) {
+ cmd.outputHelp();
+ // (Do not have all displayed text available so only passing placeholder.)
+ cmd._exit(0, 'commander.helpDisplayed', '(outputHelp)');
+ }
+}
+
+/**
+ * Takes an argument and returns its human readable equivalent for help usage.
+ *
+ * @param {Object} arg
+ * @return {string}
+ * @api private
+ */
+
+function humanReadableArgName(arg) {
+ const nameOutput = arg.name + (arg.variadic === true ? '...' : '');
+
+ return arg.required
+ ? '<' + nameOutput + '>'
+ : '[' + nameOutput + ']';
+}
+
+/**
+ * Parse the short and long flag out of something like '-m,--mixed <value>'
+ *
+ * @api private
+ */
+
+function _parseOptionFlags(flags) {
+ let shortFlag;
+ let longFlag;
+ // Use original very loose parsing to maintain backwards compatibility for now,
+ // which allowed for example unintended `-sw, --short-word` [sic].
+ const flagParts = flags.split(/[ |,]+/);
+ if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1])) shortFlag = flagParts.shift();
+ longFlag = flagParts.shift();
+ // Add support for lone short flag without significantly changing parsing!
+ if (!shortFlag && /^-[^-]$/.test(longFlag)) {
+ shortFlag = longFlag;
+ longFlag = undefined;
+ }
+ return { shortFlag, longFlag };
+}
+
+/**
+ * Scan arguments and increment port number for inspect calls (to avoid conflicts when spawning new command).
+ *
+ * @param {string[]} args - array of arguments from node.execArgv
+ * @returns {string[]}
+ * @api private
+ */
+
+function incrementNodeInspectorPort(args) {
+ // Testing for these options:
+ // --inspect[=[host:]port]
+ // --inspect-brk[=[host:]port]
+ // --inspect-port=[host:]port
+ return args.map((arg) => {
+ if (!arg.startsWith('--inspect')) {
+ return arg;
+ }
+ let debugOption;
+ let debugHost = '127.0.0.1';
+ let debugPort = '9229';
+ let match;
+ if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
+ // e.g. --inspect
+ debugOption = match[1];
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
+ debugOption = match[1];
+ if (/^\d+$/.test(match[3])) {
+ // e.g. --inspect=1234
+ debugPort = match[3];
+ } else {
+ // e.g. --inspect=localhost
+ debugHost = match[3];
+ }
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
+ // e.g. --inspect=localhost:1234
+ debugOption = match[1];
+ debugHost = match[3];
+ debugPort = match[4];
+ }
+
+ if (debugOption && debugPort !== '0') {
+ return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
+ }
+ return arg;
+ });
+}
diff --git a/src/node_modules/commander/package.json b/src/node_modules/commander/package.json
new file mode 100644
index 0000000..c4f4f6c
--- /dev/null
+++ b/src/node_modules/commander/package.json
@@ -0,0 +1,51 @@
+{
+ "name": "commander",
+ "version": "6.2.0",
+ "description": "the complete solution for node.js command-line programs",
+ "keywords": [
+ "commander",
+ "command",
+ "option",
+ "parser",
+ "cli",
+ "argument",
+ "args",
+ "argv"
+ ],
+ "author": "TJ Holowaychuk <tj@vision-media.ca>",
+ "license": "MIT",
+ "repository": {
+ "type": "git",
+ "url": "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",
+ "files": [
+ "index.js",
+ "typings/index.d.ts"
+ ],
+ "dependencies": {},
+ "devDependencies": {
+ "@types/jest": "^26.0.15",
+ "@types/node": "^14.14.2",
+ "@typescript-eslint/eslint-plugin": "^4.5.0",
+ "eslint": "^7.11.0",
+ "eslint-config-standard-with-typescript": "^19.0.1",
+ "eslint-plugin-jest": "^24.1.0",
+ "jest": "^26.6.0",
+ "standard": "^15.0.0",
+ "typescript": "^4.0.3"
+ },
+ "typings": "typings/index.d.ts",
+ "jest": {
+ "collectCoverage": true
+ },
+ "engines": {
+ "node": ">= 6"
+ }
+}
diff --git a/src/node_modules/commander/typings/index.d.ts b/src/node_modules/commander/typings/index.d.ts
new file mode 100644
index 0000000..479446d
--- /dev/null
+++ b/src/node_modules/commander/typings/index.d.ts
@@ -0,0 +1,410 @@
+// Type definitions for commander
+// Original definitions by: Alan Agius <https://github.com/alan-agius4>, Marcelo Dezem <https://github.com/mdezem>, vvakame <https://github.com/vvakame>, Jules Randolph <https://github.com/sveinburne>
+
+declare namespace commander {
+
+ interface CommanderError extends Error {
+ code: string;
+ exitCode: number;
+ message: string;
+ nestedError?: string;
+ }
+ type CommanderErrorConstructor = new (exitCode: number, code: string, message: string) => CommanderError;
+
+ interface Option {
+ flags: string;
+ required: boolean; // A value must be supplied when the option is specified.
+ optional: boolean; // A value is optional when the option is specified.
+ mandatory: boolean; // The option must have a value after parsing, which usually means it must be specified on command line.
+ bool: boolean;
+ short?: string;
+ long: string;
+ description: string;
+ }
+ type OptionConstructor = new (flags: string, description?: string) => Option;
+
+ interface ParseOptions {
+ from: 'node' | 'electron' | 'user';
+ }
+
+ interface Command {
+ [key: string]: any; // options as properties
+
+ args: string[];
+
+ commands: Command[];
+
+ /**
+ * Set the program version to `str`.
+ *
+ * This method auto-registers the "-V, --version" flag
+ * which will print the version number when passed.
+ *
+ * You can optionally supply the flags and description to override the defaults.
+ */
+ version(str: string, flags?: string, description?: string): this;
+
+ /**
+ * Define a command, implemented using an action handler.
+ *
+ * @remarks
+ * The command description is supplied using `.description`, not as a parameter to `.command`.
+ *
+ * @example
+ * ```ts
+ * program
+ * .command('clone <source> [destination]')
+ * .description('clone a repository into a newly created directory')
+ * .action((source, destination) => {
+ * console.log('clone command called');
+ * });
+ * ```
+ *
+ * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
+ * @param opts - configuration options
+ * @returns new command
+ */
+ command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this['createCommand']>;
+ /**
+ * Define a command, implemented in a separate executable file.
+ *
+ * @remarks
+ * The command description is supplied as the second parameter to `.command`.
+ *
+ * @example
+ * ```ts
+ * program
+ * .command('start <service>', 'start named service')
+ * .command('stop [service]', 'stop named service, or all if no name supplied');
+ * ```
+ *
+ * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
+ * @param description - description of executable command
+ * @param opts - configuration options
+ * @returns `this` command for chaining
+ */
+ command(nameAndArgs: string, description: string, opts?: commander.ExecutableCommandOptions): this;
+
+ /**
+ * Factory routine to create a new unattached command.
+ *
+ * See .command() for creating an attached subcommand, which uses this routine to
+ * create the command. You can override createCommand to customise subcommands.
+ */
+ createCommand(name?: string): Command;
+
+ /**
+ * Add a prepared subcommand.
+ *
+ * See .command() for creating an attached subcommand which inherits settings from its parent.
+ *
+ * @returns `this` command for chaining
+ */
+ addCommand(cmd: Command, opts?: CommandOptions): this;
+
+ /**
+ * Define argument syntax for command.
+ *
+ * @returns `this` command for chaining
+ */
+ arguments(desc: string): this;
+
+ /**
+ * Override default decision whether to add implicit help command.
+ *
+ * addHelpCommand() // force on
+ * addHelpCommand(false); // force off
+ * addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
+ *
+ * @returns `this` command for chaining
+ */
+ addHelpCommand(enableOrNameAndArgs?: string | boolean, description?: string): this;
+
+ /**
+ * Register callback to use as replacement for calling process.exit.
+ */
+ exitOverride(callback?: (err: CommanderError) => never|void): this;
+
+ /**
+ * Register callback `fn` for the command.
+ *
+ * @example
+ * program
+ * .command('help')
+ * .description('display verbose help')
+ * .action(function() {
+ * // output help here
+ * });
+ *
+ * @returns `this` command for chaining
+ */
+ action(fn: (...args: any[]) => void | Promise<void>): this;
+
+ /**
+ * Define option with `flags`, `description` and optional
+ * coercion `fn`.
+ *
+ * The `flags` string should contain both the short and long flags,
+ * separated by comma, a pipe or space. The following are all valid
+ * all will output this way when `--help` is used.
+ *
+ * "-p, --pepper"
+ * "-p|--pepper"
+ * "-p --pepper"
+ *
+ * @example
+ * // simple boolean defaulting to false
+ * program.option('-p, --pepper', 'add pepper');
+ *
+ * --pepper
+ * program.pepper
+ * // => Boolean
+ *
+ * // simple boolean defaulting to true
+ * program.option('-C, --no-cheese', 'remove cheese');
+ *
+ * program.cheese
+ * // => true
+ *
+ * --no-cheese
+ * program.cheese
+ * // => false
+ *
+ * // required argument
+ * program.option('-C, --chdir <path>', 'change the working directory');
+ *
+ * --chdir /tmp
+ * program.chdir
+ * // => "/tmp"
+ *
+ * // optional argument
+ * program.option('-c, --cheese [type]', 'add cheese [marble]');
+ *
+ * @returns `this` command for chaining
+ */
+ option(flags: string, description?: string, defaultValue?: string | boolean): this;
+ option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
+ option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
+
+ /**
+ * Define a required option, which must have a value after parsing. This usually means
+ * the option must be specified on the command line. (Otherwise the same as .option().)
+ *
+ * The `flags` string should contain both the short and long flags, separated by comma, a pipe or space.
+ */
+ requiredOption(flags: string, description?: string, defaultValue?: string | boolean): this;
+ requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
+ requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
+
+ /**
+ * Whether to store option values as properties on command object,
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
+ *
+ * @returns `this` command for chaining
+ */
+ storeOptionsAsProperties(value?: boolean): this;
+
+ /**
+ * Whether to pass command to action handler,
+ * or just the options (specify false).
+ *
+ * @returns `this` command for chaining
+ */
+ passCommandToAction(value?: boolean): this;
+
+ /**
+ * Alter parsing of short flags with optional values.
+ *
+ * @example
+ * // for `.option('-f,--flag [value]'):
+ * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
+ * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
+ *
+ * @returns `this` command for chaining
+ */
+ combineFlagAndOptionalValue(arg?: boolean): this;
+
+ /**
+ * Allow unknown options on the command line.
+ *
+ * @param [arg] if `true` or omitted, no error will be thrown for unknown options.
+ * @returns `this` command for chaining
+ */
+ allowUnknownOption(arg?: boolean): this;
+
+ /**
+ * Parse `argv`, setting options and invoking commands when defined.
+ *
+ * The default expectation is that the arguments are from node and have the application as argv[0]
+ * and the script being run in argv[1], with user parameters after that.
+ *
+ * Examples:
+ *
+ * program.parse(process.argv);
+ * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
+ *
+ * @returns `this` command for chaining
+ */
+ parse(argv?: string[], options?: ParseOptions): this;
+
+ /**
+ * Parse `argv`, setting options and invoking commands when defined.
+ *
+ * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
+ *
+ * The default expectation is that the arguments are from node and have the application as argv[0]
+ * and the script being run in argv[1], with user parameters after that.
+ *
+ * Examples:
+ *
+ * program.parseAsync(process.argv);
+ * program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
+ * program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
+ *
+ * @returns Promise
+ */
+ parseAsync(argv?: string[], options?: ParseOptions): Promise<this>;
+
+ /**
+ * Parse options from `argv` removing known options,
+ * and return argv split into operands and unknown arguments.
+ *
+ * @example
+ * argv => operands, unknown
+ * --known kkk op => [op], []
+ * op --known kkk => [op], []
+ * sub --unknown uuu op => [sub], [--unknown uuu op]
+ * sub -- --unknown uuu op => [sub --unknown uuu op], []
+ */
+ parseOptions(argv: string[]): commander.ParseOptionsResult;
+
+ /**
+ * Return an object containing options as key-value pairs
+ */
+ opts(): { [key: string]: any };
+
+ /**
+ * Set the description.
+ *
+ * @returns `this` command for chaining
+ */
+ description(str: string, argsDescription?: {[argName: string]: string}): this;
+ /**
+ * Get the description.
+ */
+ description(): string;
+
+ /**
+ * Set an alias for the command.
+ *
+ * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
+ *
+ * @returns `this` command for chaining
+ */
+ alias(alias: string): this;
+ /**
+ * Get alias for the command.
+ */
+ alias(): string;
+
+ /**
+ * Set aliases for the command.
+ *
+ * Only the first alias is shown in the auto-generated help.
+ *
+ * @returns `this` command for chaining
+ */
+ aliases(aliases: string[]): this;
+ /**
+ * Get aliases for the command.
+ */
+ aliases(): string[];
+
+ /**
+ * Set the command usage.
+ *
+ * @returns `this` command for chaining
+ */
+ usage(str: string): this;
+ /**
+ * Get the command usage.
+ */
+ usage(): string;
+
+ /**
+ * Set the name of the command.
+ *
+ * @returns `this` command for chaining
+ */
+ name(str: string): this;
+ /**
+ * Get the name of the command.
+ */
+ name(): string;
+
+ /**
+ * Output help information for this command.
+ *
+ * When listener(s) are available for the helpLongFlag
+ * those callbacks are invoked.
+ */
+ outputHelp(cb?: (str: string) => string): void;
+
+ /**
+ * Return command help documentation.
+ */
+ helpInformation(): string;
+
+ /**
+ * You can pass in flags and a description to override the help
+ * flags and help description for your command. Pass in false
+ * to disable the built-in help option.
+ */
+ helpOption(flags?: string | boolean, description?: string): this;
+
+ /**
+ * Output help information and exit.
+ */
+ help(cb?: (str: string) => string): never;
+
+ /**
+ * Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
+ *
+ * @example
+ * program
+ * .on('--help', () -> {
+ * console.log('See web site for more information.');
+ * });
+ */
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
+ }
+ type CommandConstructor = new (name?: string) => Command;
+
+ interface CommandOptions {
+ noHelp?: boolean; // old name for hidden
+ hidden?: boolean;
+ isDefault?: boolean;
+ }
+ interface ExecutableCommandOptions extends CommandOptions {
+ executableFile?: string;
+ }
+
+ interface ParseOptionsResult {
+ operands: string[];
+ unknown: string[];
+ }
+
+ interface CommanderStatic extends Command {
+ program: Command;
+ Command: CommandConstructor;
+ Option: OptionConstructor;
+ CommanderError: CommanderErrorConstructor;
+ }
+
+}
+
+// Declaring namespace AND global
+// eslint-disable-next-line @typescript-eslint/no-redeclare
+declare const commander: commander.CommanderStatic;
+export = commander;