@trenskow/arguments-parser 0.2.21 → 0.3.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.
Files changed (2) hide show
  1. package/lib/index.js +21 -5
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -267,15 +267,13 @@ const argumentsParser = (
267
267
  checkHelp();
268
268
 
269
269
  let data = {};
270
- let rest = [];
271
270
 
272
271
  let idx;
273
272
 
274
273
  for (idx = 0 ; idx < args.length ; idx++) {
275
274
 
276
275
  if (args[idx].slice(0, 1) !== '-') {
277
- rest.push(args[idx]);
278
- continue;
276
+ break;
279
277
  }
280
278
 
281
279
  shortOptions = Object.fromEntries(
@@ -321,6 +319,13 @@ const argumentsParser = (
321
319
 
322
320
  }
323
321
 
322
+ if (idx < args.length) {
323
+ printHelp(
324
+ new Error(
325
+ (strings?.empty?.help?.errors?.unexpected || 'Unexpected argument: <argument>.')
326
+ .replace('<argument>', args[0])));
327
+ }
328
+
324
329
  try {
325
330
  data = await isvalid(data, schema, {
326
331
  aggregatedErrors: 'flatten'
@@ -338,10 +343,21 @@ const argumentsParser = (
338
343
  print.err(error.message);
339
344
  process.exit(1);
340
345
  },
341
- nonOptions,
342
- rest
346
+ nonOptions
343
347
  });
344
348
 
349
+ },
350
+ empty: async () => {
351
+
352
+ checkHelp();
353
+
354
+ if (args.length > 0) {
355
+ printHelp(
356
+ new Error(
357
+ (strings?.empty?.help?.errors?.unexpected || 'Unexpected argument: <argument>.')
358
+ .replace('<argument>', args[0])));
359
+ }
360
+
345
361
  },
346
362
  values: async (schema) => {
347
363
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/arguments-parser",
3
- "version": "0.2.21",
3
+ "version": "0.3.0",
4
4
  "description": "Yet another arguments parser.",
5
5
  "main": "index.js",
6
6
  "type": "module",