@trenskow/arguments-parser 0.3.90 → 0.3.92

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.
Files changed (2) hide show
  1. package/lib/index.js +21 -7
  2. 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,
@@ -189,8 +189,16 @@ const argumentsParser = (
189
189
  print(strings?.commands?.help?.available || 'Available commands:');
190
190
  print();
191
191
 
192
- const tools = Object.keys(commands).map((key) => ({
193
- name: caseit(key, 'kebab'),
192
+ const tools = Object.entries(commands).map(([key, command]) => ({
193
+ name: `${
194
+ caseit(key, 'kebab')
195
+ }${
196
+ Array.isArray(command.parameters) ? ` ${
197
+ command.parameters
198
+ .map((parameter) => `${opening}${parameter}${closing}`)
199
+ .join(' ')
200
+ }` : ''
201
+ }`,
194
202
  description: commands[key].description
195
203
  }));
196
204
 
@@ -214,6 +222,8 @@ const argumentsParser = (
214
222
  .replace('<command>', args[0])));
215
223
  }
216
224
 
225
+ onCommand?.(tool, args.slice(1));
226
+
217
227
  return await next(
218
228
  tool,
219
229
  commands[tool]);
@@ -261,6 +271,8 @@ const argumentsParser = (
261
271
  printHelp(error);
262
272
  }
263
273
 
274
+ (onParameter || onCommand)?.(identifier, args.slice(1));
275
+
264
276
  return await next(
265
277
  identifier,
266
278
  command);
@@ -287,8 +299,6 @@ const argumentsParser = (
287
299
  then: (...resultArguments) => {
288
300
  return (async () => {
289
301
 
290
- checkHelp();
291
-
292
302
  let nonOptions;
293
303
  let nonOptionsIndex = args.indexOf('--');
294
304
 
@@ -398,10 +408,14 @@ const argumentsParser = (
398
408
  };
399
409
  }
400
410
 
411
+ checkHelp();
412
+
401
413
  let rest = [];
402
414
 
403
415
  let idx;
404
416
 
417
+ checkHelp();
418
+
405
419
  for (idx = 0 ; idx < args.length ; idx++) {
406
420
 
407
421
  if (args[idx].slice(0, 1) !== '-') {
@@ -463,7 +477,7 @@ const argumentsParser = (
463
477
  }
464
478
  }
465
479
 
466
- if (args.length > 0) {
480
+ if (args.length - idx > 0) {
467
481
  printHelp(
468
482
  new Error(
469
483
  (strings?.empty?.help?.errors?.unexpected || 'Unexpected argument: <argument>.')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/arguments-parser",
3
- "version": "0.3.90",
3
+ "version": "0.3.92",
4
4
  "description": "Yet another arguments parser.",
5
5
  "main": "index.js",
6
6
  "type": "module",