commander
Advanced tools
Comparing version 5.0.0-2 to 5.0.0-3
@@ -10,2 +10,9 @@ # Changelog | ||
## [5.0.0-3] (2020-02-20) | ||
### Added | ||
- TypeScript definition for `commands` property of `Command` ([#1184]) | ||
- export `program` property ([#1195]) | ||
## [5.0.0-2] (2020-02-10) | ||
@@ -15,7 +22,8 @@ | ||
- suggest help option along with unknown command error ([#1179]) | ||
* suggest help option along with unknown command error ([#1179]) | ||
### Changed | ||
- TypeScript fluent return types changed to be more subclass friendly, return `this` rather than `Command` ([#1180]) | ||
* 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]) | ||
@@ -329,4 +337,7 @@ ## [5.0.0-1] (2020-02-08) | ||
[#1180]: https://github.com/tj/commander.js/pull/1180 | ||
[#1184]: https://github.com/tj/commander.js/pull/1184 | ||
[#1195]: https://github.com/tj/commander.js/pull/1195 | ||
[Unreleased]: https://github.com/tj/commander.js/compare/master...develop | ||
[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 | ||
@@ -333,0 +344,0 @@ [5.0.0-1]: https://github.com/tj/commander.js/compare/v5.0.0-0..v5.0.0-1 |
23
index.js
@@ -10,2 +10,4 @@ /** | ||
// @ts-check | ||
class Option { | ||
@@ -26,6 +28,7 @@ /** | ||
this.negate = flags.indexOf('-no-') !== -1; | ||
flags = flags.split(/[ ,|]+/); | ||
if (flags.length > 1 && !/^[[<]/.test(flags[1])) this.short = flags.shift(); | ||
this.long = flags.shift(); | ||
const flagParts = flags.split(/[ ,|]+/); | ||
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1])) this.short = flagParts.shift(); | ||
this.long = flagParts.shift(); | ||
this.description = description || ''; | ||
this.defaultValue = undefined; | ||
} | ||
@@ -88,2 +91,3 @@ | ||
this.exitCode = exitCode; | ||
this.nestedError = undefined; | ||
} | ||
@@ -104,2 +108,3 @@ } | ||
this.options = []; | ||
this.parent = null; | ||
this._allowUnknownOption = false; | ||
@@ -119,2 +124,3 @@ this._args = []; | ||
this._exitCallback = null; | ||
this._alias = null; | ||
@@ -642,3 +648,3 @@ this._noHelp = false; | ||
* @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' | ||
* @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron' | ||
* @return {Command} for chaining | ||
@@ -657,2 +663,3 @@ * @api public | ||
argv = process.argv; | ||
// @ts-ignore | ||
if (process.versions && process.versions.electron) { | ||
@@ -673,2 +680,3 @@ parseOptions.from = 'electron'; | ||
case 'electron': | ||
// @ts-ignore | ||
if (process.defaultApp) { | ||
@@ -791,2 +799,3 @@ this._scriptPath = argv[1]; | ||
signals.forEach((signal) => { | ||
// @ts-ignore | ||
process.on(signal, () => { | ||
@@ -810,2 +819,3 @@ if (proc.killed === false && proc.exitCode === null) { | ||
proc.on('error', (err) => { | ||
// @ts-ignore | ||
if (err.code === 'ENOENT') { | ||
@@ -816,2 +826,3 @@ const executableMissing = `'${bin}' does not exist | ||
throw new Error(executableMissing); | ||
// @ts-ignore | ||
} else if (err.code === 'EACCES') { | ||
@@ -1133,3 +1144,2 @@ throw new Error(`'${bin}' not executable`); | ||
* | ||
* @param {string} flag | ||
* @api private | ||
@@ -1160,3 +1170,3 @@ */ | ||
* @param {string} [description] | ||
* @return {Command} for chaining | ||
* @return {Command | string} this for chaining | ||
* @api public | ||
@@ -1539,2 +1549,3 @@ */ | ||
exports = module.exports = new Command(); | ||
exports.program = exports; // More explicit access to global command. | ||
@@ -1541,0 +1552,0 @@ /** |
{ | ||
"name": "commander", | ||
"version": "5.0.0-2", | ||
"version": "5.0.0-3", | ||
"description": "the complete solution for node.js command-line programs", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -59,3 +59,3 @@ # Commander.js | ||
```js | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
program.version('0.0.1'); | ||
@@ -67,4 +67,4 @@ ``` | ||
```js | ||
const commander = require('commander'); | ||
const program = new commander.Command(); | ||
const { Command } = require('commander'); | ||
const program = new Command(); | ||
program.version('0.0.1'); | ||
@@ -93,3 +93,3 @@ ``` | ||
```js | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
@@ -132,3 +132,3 @@ program | ||
```js | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
@@ -159,3 +159,3 @@ program | ||
```js | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
@@ -187,3 +187,3 @@ program | ||
```js | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
@@ -219,3 +219,3 @@ program | ||
```js | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
@@ -274,3 +274,3 @@ function myParseInt(value, dummyPrevious) { | ||
```js | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
@@ -347,3 +347,3 @@ program | ||
```js | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
@@ -372,3 +372,3 @@ program | ||
```js | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
@@ -399,3 +399,3 @@ program | ||
```js | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
@@ -437,3 +437,3 @@ program | ||
// file: ./examples/pm | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
@@ -572,5 +572,3 @@ program | ||
const availableCommands = program.commands.map(cmd => cmd.name()); | ||
const suggestion = didYouMean(operands[0], availableCommands); | ||
if (suggestion) | ||
console.error(`Did you mean '${suggestion}'?`); | ||
mySuggestBestMatch(operands[0], availableCommands); | ||
process.exitCode = 1; | ||
@@ -685,3 +683,3 @@ }); | ||
```js | ||
const program = require('commander'); | ||
const { program } = require('commander'); | ||
@@ -688,0 +686,0 @@ program |
@@ -35,2 +35,4 @@ // Type definitions for commander | ||
commands: Command[]; | ||
/** | ||
@@ -37,0 +39,0 @@ * Set the program version to `str`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101041
1816
724