@trenskow/arguments-parser 0.3.0 → 0.3.2

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 -6
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -183,6 +183,10 @@ const argumentsParser = (
183
183
 
184
184
  helpUsage.push(`${opening}${strings?.options?.help?.placeholder || 'options'}${closing}`);
185
185
 
186
+ if (typeof options.usage === 'string') {
187
+ helpUsage.push(options.usage);
188
+ }
189
+
186
190
  let shortOptions = {};
187
191
 
188
192
  allKeyPaths
@@ -267,13 +271,15 @@ const argumentsParser = (
267
271
  checkHelp();
268
272
 
269
273
  let data = {};
274
+ let rest = [];
270
275
 
271
276
  let idx;
272
277
 
273
278
  for (idx = 0 ; idx < args.length ; idx++) {
274
279
 
275
280
  if (args[idx].slice(0, 1) !== '-') {
276
- break;
281
+ rest.push(args[idx]);
282
+ continue;
277
283
  }
278
284
 
279
285
  shortOptions = Object.fromEntries(
@@ -319,11 +325,19 @@ const argumentsParser = (
319
325
 
320
326
  }
321
327
 
322
- if (idx < args.length) {
323
- printHelp(
324
- new Error(
325
- (strings?.empty?.help?.errors?.unexpected || 'Unexpected argument: <argument>.')
326
- .replace('<argument>', args[0])));
328
+ if (rest.length) {
329
+ switch (options.variadic || 'deny') {
330
+ case 'allow':
331
+ break;
332
+ case 'ignore':
333
+ rest = [];
334
+ break;
335
+ default:
336
+ printHelp(
337
+ new Error(
338
+ (strings?.empty?.help?.errors?.unexpected || 'Unexpected argument: <argument>.')
339
+ .replace('<argument>', args[0])));
340
+ }
327
341
  }
328
342
 
329
343
  try {
@@ -343,6 +357,7 @@ const argumentsParser = (
343
357
  print.err(error.message);
344
358
  process.exit(1);
345
359
  },
360
+ rest,
346
361
  nonOptions
347
362
  });
348
363
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/arguments-parser",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Yet another arguments parser.",
5
5
  "main": "index.js",
6
6
  "type": "module",