@trenskow/arguments-parser 0.3.79 → 0.3.81

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 -1
  2. package/package.json +4 -4
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),
@@ -270,6 +288,10 @@ const argumentsParser = (
270
288
 
271
289
  }
272
290
 
291
+ if (keyPathSchema.hints?.length) {
292
+ description = description.concat(keyPathSchema.hints);
293
+ }
294
+
273
295
  let option = optionKeys.reverse().join(', ');
274
296
 
275
297
  if (keyPathSchema.type !== Boolean) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/arguments-parser",
3
- "version": "0.3.79",
3
+ "version": "0.3.81",
4
4
  "description": "Yet another arguments parser.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,13 +25,13 @@
25
25
  "homepage": "https://github.com/trenskow/arguments-parser#readme",
26
26
  "dependencies": {
27
27
  "@trenskow/caseit": "^1.4.23",
28
- "@trenskow/print": "^0.1.53",
29
- "isvalid": "^5.0.0"
28
+ "@trenskow/print": "^0.1.54",
29
+ "isvalid": "^5.0.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@eslint/eslintrc": "^3.3.5",
33
33
  "@eslint/js": "^10.0.1",
34
- "eslint": "^10.3.0",
34
+ "eslint": "^10.4.0",
35
35
  "globals": "^17.6.0"
36
36
  }
37
37
  }