@trenskow/arguments-parser 0.3.91 → 0.3.93

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 +23 -11
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -166,7 +166,8 @@ const argumentsParser = (
166
166
  strings,
167
167
  options,
168
168
  parameters
169
- })
169
+ }),
170
+ parameters
170
171
  });
171
172
 
172
173
  } catch (error) {
@@ -189,8 +190,16 @@ const argumentsParser = (
189
190
  print(strings?.commands?.help?.available || 'Available commands:');
190
191
  print();
191
192
 
192
- const tools = Object.keys(commands).map((key) => ({
193
- name: caseit(key, 'kebab'),
193
+ const tools = Object.entries(commands).map(([key, command]) => ({
194
+ name: `${
195
+ caseit(key, 'kebab')
196
+ }${
197
+ Array.isArray(command.parameters) ? ` ${
198
+ command.parameters
199
+ .map((parameter) => `${opening}${caseit(parameter, 'kebab')}${closing}`)
200
+ .join(' ')
201
+ }` : ''
202
+ }`,
194
203
  description: commands[key].description
195
204
  }));
196
205
 
@@ -279,8 +288,8 @@ const argumentsParser = (
279
288
  validationOptions);
280
289
 
281
290
  options.schema = merge(
282
- options.schema)
283
- .with(schema);
291
+ schema)
292
+ .with(options.schema);
284
293
 
285
294
  return result;
286
295
 
@@ -291,8 +300,6 @@ const argumentsParser = (
291
300
  then: (...resultArguments) => {
292
301
  return (async () => {
293
302
 
294
- checkHelp();
295
-
296
303
  let nonOptions;
297
304
  let nonOptionsIndex = args.indexOf('--');
298
305
 
@@ -350,10 +357,11 @@ const argumentsParser = (
350
357
  const keyPathSchema = keyPaths(options.schema).get(keyPath);
351
358
 
352
359
  let optionKeys = [`--${caseit(keyPath, 'kebab')}`];
360
+
353
361
  let description = [keyPathSchema.description || strings?.commands?.help?.noDescription || 'No description'];
354
362
 
355
- if (shortOptions[keyPath]) {
356
- optionKeys.push(`-${shortOptions[keyPath]}`);
363
+ if (keyPathSchema.short) {
364
+ optionKeys.push(`-${keyPathSchema.short}`);
357
365
  }
358
366
 
359
367
  if (typeof keyPathSchema.enum !== 'undefined') {
@@ -402,10 +410,14 @@ const argumentsParser = (
402
410
  };
403
411
  }
404
412
 
413
+ checkHelp();
414
+
405
415
  let rest = [];
406
416
 
407
417
  let idx;
408
418
 
419
+ checkHelp();
420
+
409
421
  for (idx = 0 ; idx < args.length ; idx++) {
410
422
 
411
423
  if (args[idx].slice(0, 1) !== '-') {
@@ -467,7 +479,7 @@ const argumentsParser = (
467
479
  }
468
480
  }
469
481
 
470
- if (args.length > 0) {
482
+ if (args.length - idx > 0) {
471
483
  printHelp(
472
484
  new Error(
473
485
  (strings?.empty?.help?.errors?.unexpected || 'Unexpected argument: <argument>.')
@@ -484,7 +496,7 @@ const argumentsParser = (
484
496
  printHelp(error);
485
497
  }
486
498
 
487
- return Object.assign({}, parameters, data, {
499
+ return Object.assign({}, data, {
488
500
  onError: (error) => {
489
501
  print.err(error.message);
490
502
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/arguments-parser",
3
- "version": "0.3.91",
3
+ "version": "0.3.93",
4
4
  "description": "Yet another arguments parser.",
5
5
  "main": "index.js",
6
6
  "type": "module",