@trenskow/arguments-parser 0.3.78 → 0.3.80

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 +27 -5
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -12,7 +12,7 @@ import caseit from '@trenskow/caseit';
12
12
  import { default as isvalid, keyPaths, formalize, plugins } from 'isvalid';
13
13
  import print from '@trenskow/print';
14
14
 
15
- plugins.use('argumentsParser', () => ({
15
+ plugins.use('argumentsParser.default', () => ({
16
16
  phase: 'pre',
17
17
  supportsType: () => true,
18
18
  validatorsForType: () => ({
@@ -25,6 +25,24 @@ plugins.use('argumentsParser', () => ({
25
25
  formalize: (schema) => schema
26
26
  }));
27
27
 
28
+ plugins.use('argumentsParser.hints', () => ({
29
+ phase: 'pre',
30
+ supportsType: () => true,
31
+ validatorsForType: () => ({
32
+ hints: ['array', 'string']
33
+ }),
34
+ validate: (data) => data,
35
+ formalize: (data, _, schema) => {
36
+ if (!Array.isArray(data)) data = [data];
37
+ if (schema.errors.hints) {
38
+ data.push(schema.errors.hints);
39
+ delete schema.errors.hints;
40
+ }
41
+ if (data.some((data) => typeof data !== 'string')) throw new Error('Must be a string.');
42
+ return data;
43
+ }
44
+ }));
45
+
28
46
  const argumentsParser = (
29
47
  {
30
48
  args = process.argv.slice(2),
@@ -217,6 +235,10 @@ const argumentsParser = (
217
235
 
218
236
  });
219
237
 
238
+ shortOptions = Object.fromEntries(
239
+ Object.entries(shortOptions)
240
+ .map(([key, value]) => [value, key]));
241
+
220
242
  if (allKeyPaths.length) {
221
243
 
222
244
  helpOptions = () => {
@@ -266,6 +288,10 @@ const argumentsParser = (
266
288
 
267
289
  }
268
290
 
291
+ if (keyPathSchema.hints?.length) {
292
+ description = description.concat(keyPathSchema.hints);
293
+ }
294
+
269
295
  let option = optionKeys.reverse().join(', ');
270
296
 
271
297
  if (keyPathSchema.type !== Boolean) {
@@ -293,10 +319,6 @@ const argumentsParser = (
293
319
  continue;
294
320
  }
295
321
 
296
- shortOptions = Object.fromEntries(
297
- Object.entries(shortOptions)
298
- .map(([key, value]) => [value, key]));
299
-
300
322
  let key = args[idx].slice(1);
301
323
 
302
324
  if (args[idx].slice(1, 2) === '-') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/arguments-parser",
3
- "version": "0.3.78",
3
+ "version": "0.3.80",
4
4
  "description": "Yet another arguments parser.",
5
5
  "main": "index.js",
6
6
  "type": "module",