@trenskow/arguments-parser 0.2.3 → 0.2.5

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 +32 -15
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -9,9 +9,20 @@
9
9
  import { basename } from 'path';
10
10
 
11
11
  import caseit from '@trenskow/caseit';
12
- import { default as isvalid, keyPaths, formalize } from 'isvalid';
12
+ import { default as isvalid, keyPaths, formalize, plugins } from 'isvalid';
13
13
  import print from '@trenskow/print';
14
14
 
15
+ plugins.use(() => ({
16
+ phase: 'pre',
17
+ supportsType: () => true,
18
+ validatorsForType: () => ({
19
+ description: ['string'],
20
+ defaultDescription: ['string']
21
+ }),
22
+ validate: (data) => data,
23
+ formalize: (schema) => schema
24
+ }));
25
+
15
26
  const argumentsParser = ({ args = process.argv.slice(2), argvLevel = 0, placeholder = '<>', command } = {}) => {
16
27
 
17
28
  const [ opening, closing ] = placeholder.split('');
@@ -95,18 +106,7 @@ const argumentsParser = ({ args = process.argv.slice(2), argvLevel = 0, placehol
95
106
 
96
107
  options.command = options.command || command;
97
108
 
98
- schema = formalize(schema, {
99
- plugins: [() => ({
100
- phase: 'pre',
101
- supportsType: () => true,
102
- validatorsForType: () => ({
103
- description: ['string'],
104
- defaultDescription: ['string']
105
- }),
106
- validate: (data) => data,
107
- formalize: (schema) => schema
108
- })]
109
- });
109
+ schema = formalize(schema);
110
110
 
111
111
  let nonOptions;
112
112
  let nonOptionsIndex = args.indexOf('--');
@@ -173,6 +173,23 @@ const argumentsParser = ({ args = process.argv.slice(2), argvLevel = 0, placehol
173
173
 
174
174
  print();
175
175
 
176
+ if (error) {
177
+
178
+ print();
179
+
180
+ (error.errors || [error])
181
+ .forEach((error) => {
182
+ if (error.keyPath) {
183
+ print.err(`--${caseit(error.keyPath.join('.'), 'kebab')}: ${error.message}`);
184
+ } else {
185
+ print.err(error.message);
186
+ }
187
+ });
188
+
189
+ print();
190
+
191
+ }
192
+
176
193
  process.exit(error ? 1 : 0);
177
194
 
178
195
  };
@@ -220,10 +237,10 @@ const argumentsParser = ({ args = process.argv.slice(2), argvLevel = 0, placehol
220
237
 
221
238
  try {
222
239
  data = await isvalid(data, schema, {
223
- stopAtFirstError: false
240
+ aggregatedErrors: 'flatten'
224
241
  });
225
242
  } catch (error) {
226
- printHelp(new Error(`--${caseit(error.keyPath.join('.'), 'kebab')}: ${error.message}`));
243
+ printHelp(error);
227
244
  }
228
245
 
229
246
  return Object.assign({}, data, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/arguments-parser",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Yet another arguments parser.",
5
5
  "main": "index.js",
6
6
  "type": "module",