@trenskow/arguments-parser 0.3.89 → 0.3.91
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/lib/index.js +19 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -50,6 +50,7 @@ const argumentsParser = (
|
|
|
50
50
|
placeholder = '<>',
|
|
51
51
|
command,
|
|
52
52
|
onCommand,
|
|
53
|
+
onParameter,
|
|
53
54
|
strings = {},
|
|
54
55
|
help: {
|
|
55
56
|
usage: helpUsage,
|
|
@@ -153,14 +154,13 @@ const argumentsParser = (
|
|
|
153
154
|
|
|
154
155
|
try {
|
|
155
156
|
|
|
156
|
-
onCommand?.(identifier, args.slice(1));
|
|
157
|
-
|
|
158
157
|
return await command({
|
|
159
158
|
args: args.slice(1),
|
|
160
159
|
argumentsParser: argumentsParser({
|
|
161
160
|
args: args.slice(1),
|
|
162
161
|
argvLevel: argvLevel + 1,
|
|
163
162
|
onCommand,
|
|
163
|
+
onParameter,
|
|
164
164
|
placeholder,
|
|
165
165
|
command: command,
|
|
166
166
|
strings,
|
|
@@ -214,22 +214,25 @@ const argumentsParser = (
|
|
|
214
214
|
.replace('<command>', args[0])));
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
onCommand?.(tool, args.slice(1));
|
|
218
|
+
|
|
217
219
|
return await next(
|
|
218
220
|
tool,
|
|
219
221
|
commands[tool]);
|
|
220
222
|
|
|
221
223
|
},
|
|
222
|
-
parameter: async (
|
|
224
|
+
parameter: async ({
|
|
223
225
|
identifier,
|
|
224
226
|
description,
|
|
225
|
-
schema
|
|
226
|
-
|
|
227
|
-
) => {
|
|
227
|
+
schema
|
|
228
|
+
} = {}, command) => {
|
|
228
229
|
|
|
229
230
|
if (typeof identifier !== 'string') {
|
|
230
231
|
throw new Error('Identifier must be a string');
|
|
231
232
|
}
|
|
232
233
|
|
|
234
|
+
description = description || command.description || strings?.commands?.help?.noDescription || 'No description.';
|
|
235
|
+
|
|
233
236
|
helpUsage.push(`${opening}${caseit(identifier, 'kebab')}${closing}`);
|
|
234
237
|
|
|
235
238
|
helpOptions = () => {
|
|
@@ -248,14 +251,20 @@ const argumentsParser = (
|
|
|
248
251
|
|
|
249
252
|
checkHelp();
|
|
250
253
|
|
|
254
|
+
parameters[identifier] = args[0];
|
|
255
|
+
|
|
251
256
|
try {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
257
|
+
if (typeof schema !== 'undefined') {
|
|
258
|
+
parameters[identifier] = await isvalid(
|
|
259
|
+
parameters[identifier],
|
|
260
|
+
schema);
|
|
261
|
+
}
|
|
255
262
|
} catch (error) {
|
|
256
263
|
printHelp(error);
|
|
257
264
|
}
|
|
258
265
|
|
|
266
|
+
(onParameter || onCommand)?.(identifier, args.slice(1));
|
|
267
|
+
|
|
259
268
|
return await next(
|
|
260
269
|
identifier,
|
|
261
270
|
command);
|
|
@@ -341,7 +350,7 @@ const argumentsParser = (
|
|
|
341
350
|
const keyPathSchema = keyPaths(options.schema).get(keyPath);
|
|
342
351
|
|
|
343
352
|
let optionKeys = [`--${caseit(keyPath, 'kebab')}`];
|
|
344
|
-
let description = [keyPathSchema.description || 'No description'];
|
|
353
|
+
let description = [keyPathSchema.description || strings?.commands?.help?.noDescription || 'No description'];
|
|
345
354
|
|
|
346
355
|
if (shortOptions[keyPath]) {
|
|
347
356
|
optionKeys.push(`-${shortOptions[keyPath]}`);
|