commander 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/index.js +16 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
7
7
|
|
|
8
8
|
<!-- markdownlint-disable MD024 -->
|
|
9
9
|
|
|
10
|
+
## [4.0.1] (2019-11-12)
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
* display help when requested, even if there are missing required options [(#1091)]
|
|
15
|
+
|
|
10
16
|
## [4.0.0] (2019-11-02)
|
|
11
17
|
|
|
12
18
|
### Added
|
|
@@ -32,6 +38,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
32
38
|
* removed deprecated `customFds` option from call to `child_process.spawn` ([#1052])
|
|
33
39
|
* rework TypeScript declarations to bring all types into imported namespace ([#1081])
|
|
34
40
|
|
|
41
|
+
### Migration Tips
|
|
42
|
+
|
|
43
|
+
#### Testing for no arguments
|
|
44
|
+
|
|
45
|
+
If you were previously using code like:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
if (!program.args.length) ...
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
a partial replacement is:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
if (program.rawArgs.length < 3) ...
|
|
55
|
+
```
|
|
56
|
+
|
|
35
57
|
## [4.0.0-1] Prerelease (2019-10-08)
|
|
36
58
|
|
|
37
59
|
(Released in 4.0.0)
|
|
@@ -503,8 +525,10 @@ program
|
|
|
503
525
|
[#1053]: https://github.com/tj/commander.js/pull/1053
|
|
504
526
|
[#1071]: https://github.com/tj/commander.js/pull/1071
|
|
505
527
|
[#1081]: https://github.com/tj/commander.js/pull/1081
|
|
528
|
+
[#1091]: https://github.com/tj/commander.js/pull/1091
|
|
506
529
|
|
|
507
530
|
[Unreleased]: https://github.com/tj/commander.js/compare/master...develop
|
|
531
|
+
[4.0.1]: https://github.com/tj/commander.js/compare/v4.0.0..v4.0.1
|
|
508
532
|
[4.0.0]: https://github.com/tj/commander.js/compare/v3.0.2..v4.0.0
|
|
509
533
|
[4.0.0-1]: https://github.com/tj/commander.js/compare/v4.0.0-0..v4.0.0-1
|
|
510
534
|
[4.0.0-0]: https://github.com/tj/commander.js/compare/v3.0.2...v4.0.0-0
|
package/index.js
CHANGED
|
@@ -324,6 +324,7 @@ Command.prototype.action = function(fn) {
|
|
|
324
324
|
|
|
325
325
|
// Output help if necessary
|
|
326
326
|
outputHelpIfNecessary(self, parsed.unknown);
|
|
327
|
+
self._checkForMissingMandatoryOptions();
|
|
327
328
|
|
|
328
329
|
// If there are still any unknown options, then we simply
|
|
329
330
|
// die, unless someone asked for help, in which case we give it
|
|
@@ -563,10 +564,17 @@ Command.prototype.parse = function(argv) {
|
|
|
563
564
|
|
|
564
565
|
if (args[0] === 'help' && args.length === 1) this.help();
|
|
565
566
|
|
|
567
|
+
// Note for future: we could return early if we found an action handler in parseArgs, as none of following code needed?
|
|
568
|
+
|
|
566
569
|
// <cmd> --help
|
|
567
570
|
if (args[0] === 'help') {
|
|
568
571
|
args[0] = args[1];
|
|
569
572
|
args[1] = this._helpLongFlag;
|
|
573
|
+
} else {
|
|
574
|
+
// If calling through to executable subcommand we could check for help flags before failing,
|
|
575
|
+
// but a somewhat unlikely case since program options not passed to executable subcommands.
|
|
576
|
+
// Wait for reports to see if check needed and what usage pattern is.
|
|
577
|
+
this._checkForMissingMandatoryOptions();
|
|
570
578
|
}
|
|
571
579
|
|
|
572
580
|
// executable sub-commands
|
|
@@ -832,12 +840,14 @@ Command.prototype.optionFor = function(arg) {
|
|
|
832
840
|
*/
|
|
833
841
|
|
|
834
842
|
Command.prototype._checkForMissingMandatoryOptions = function() {
|
|
835
|
-
|
|
836
|
-
this.
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
843
|
+
// Walk up hierarchy so can call from action handler after checking for displaying help.
|
|
844
|
+
for (var cmd = this; cmd; cmd = cmd.parent) {
|
|
845
|
+
cmd.options.forEach((anOption) => {
|
|
846
|
+
if (anOption.mandatory && (cmd[anOption.attributeName()] === undefined)) {
|
|
847
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
}
|
|
841
851
|
};
|
|
842
852
|
|
|
843
853
|
/**
|
|
@@ -916,8 +926,6 @@ Command.prototype.parseOptions = function(argv) {
|
|
|
916
926
|
args.push(arg);
|
|
917
927
|
}
|
|
918
928
|
|
|
919
|
-
this._checkForMissingMandatoryOptions();
|
|
920
|
-
|
|
921
929
|
return { args: args, unknown: unknownOptions };
|
|
922
930
|
};
|
|
923
931
|
|