yargs 17.0.1 → 17.1.0
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 +16 -0
- package/build/index.cjs +1 -1
- package/build/lib/command.js +21 -27
- package/build/lib/completion.js +3 -2
- package/build/lib/middleware.js +9 -3
- package/build/lib/usage.js +17 -17
- package/build/lib/utils/levenshtein.js +9 -1
- package/build/lib/validation.js +21 -6
- package/build/lib/yargs-factory.js +358 -362
- package/locales/zh_TW.json +50 -46
- package/package.json +3 -3
package/build/lib/validation.js
CHANGED
|
@@ -66,6 +66,7 @@ export function validation(yargs, usage, shim) {
|
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
self.unknownArguments = function unknownArguments(argv, aliases, positionalMap, isDefaultCommand, checkPositionals = true) {
|
|
69
|
+
var _a;
|
|
69
70
|
const commandKeys = yargs
|
|
70
71
|
.getInternalMethods()
|
|
71
72
|
.getCommandInstance()
|
|
@@ -73,7 +74,7 @@ export function validation(yargs, usage, shim) {
|
|
|
73
74
|
const unknown = [];
|
|
74
75
|
const currentContext = yargs.getInternalMethods().getContext();
|
|
75
76
|
Object.keys(argv).forEach(key => {
|
|
76
|
-
if (specialKeys.
|
|
77
|
+
if (!specialKeys.includes(key) &&
|
|
77
78
|
!Object.prototype.hasOwnProperty.call(positionalMap, key) &&
|
|
78
79
|
!Object.prototype.hasOwnProperty.call(yargs.getInternalMethods().getParseContext(), key) &&
|
|
79
80
|
!self.isValidAndSomeAliasIsNotNew(key, aliases)) {
|
|
@@ -85,12 +86,26 @@ export function validation(yargs, usage, shim) {
|
|
|
85
86
|
commandKeys.length > 0 ||
|
|
86
87
|
isDefaultCommand)) {
|
|
87
88
|
argv._.slice(currentContext.commands.length).forEach(key => {
|
|
88
|
-
if (commandKeys.
|
|
89
|
+
if (!commandKeys.includes('' + key)) {
|
|
89
90
|
unknown.push('' + key);
|
|
90
91
|
}
|
|
91
92
|
});
|
|
92
93
|
}
|
|
93
|
-
if (
|
|
94
|
+
if (checkPositionals) {
|
|
95
|
+
const demandedCommands = yargs.getDemandedCommands();
|
|
96
|
+
const maxNonOptDemanded = ((_a = demandedCommands._) === null || _a === void 0 ? void 0 : _a.max) || 0;
|
|
97
|
+
const expected = currentContext.commands.length + maxNonOptDemanded;
|
|
98
|
+
if (expected < argv._.length) {
|
|
99
|
+
argv._.slice(expected).forEach(key => {
|
|
100
|
+
key = String(key);
|
|
101
|
+
if (!currentContext.commands.includes(key) &&
|
|
102
|
+
!unknown.includes(key)) {
|
|
103
|
+
unknown.push(key);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (unknown.length) {
|
|
94
109
|
usage.fail(__n('Unknown argument: %s', 'Unknown arguments: %s', unknown.length, unknown.join(', ')));
|
|
95
110
|
}
|
|
96
111
|
};
|
|
@@ -103,7 +118,7 @@ export function validation(yargs, usage, shim) {
|
|
|
103
118
|
const currentContext = yargs.getInternalMethods().getContext();
|
|
104
119
|
if (currentContext.commands.length > 0 || commandKeys.length > 0) {
|
|
105
120
|
argv._.slice(currentContext.commands.length).forEach(key => {
|
|
106
|
-
if (commandKeys.
|
|
121
|
+
if (!commandKeys.includes('' + key)) {
|
|
107
122
|
unknown.push('' + key);
|
|
108
123
|
}
|
|
109
124
|
});
|
|
@@ -181,10 +196,10 @@ export function validation(yargs, usage, shim) {
|
|
|
181
196
|
}
|
|
182
197
|
else if (val.match(/^--no-.+/)) {
|
|
183
198
|
val = val.match(/^--no-(.+)/)[1];
|
|
184
|
-
val = !argv
|
|
199
|
+
val = !Object.prototype.hasOwnProperty.call(argv, val);
|
|
185
200
|
}
|
|
186
201
|
else {
|
|
187
|
-
val = argv
|
|
202
|
+
val = Object.prototype.hasOwnProperty.call(argv, val);
|
|
188
203
|
}
|
|
189
204
|
return val;
|
|
190
205
|
}
|