@trenskow/arguments-parser 0.3.123 → 0.3.124

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.
package/index.js CHANGED
@@ -51,20 +51,15 @@ plugins.use('argumentsParser.autocomplete', () => ({
51
51
  phase: 'pre',
52
52
  supportsType: () => true,
53
53
  validatorsForType: () => ({
54
- autocomplete: ['array', 'string']
54
+ autocomplete: ['array', 'function']
55
55
  }),
56
56
  validate: (data) => data,
57
- formalize: (data, _, schema) => {
58
-
59
- if (!Array.isArray(data)) data = [data];
57
+ formalize: (data) => {
60
58
 
61
- if (schema.errors.autocomplete) {
62
- data.push(schema.errors.autocomplete);
63
- delete schema.errors.autocomplete;
59
+ if (!(Array.isArray(data) && data.every((data) => typeof data === 'string')) && typeof data !== 'function') {
60
+ throw new Error('Must be a string or a function.');
64
61
  }
65
62
 
66
- if (data.some((data) => typeof data !== 'string')) throw new Error('Must be a string.');
67
-
68
63
  return data;
69
64
 
70
65
  }
@@ -50,7 +50,7 @@ const argumentsParser = (shell) => {
50
50
 
51
51
  });
52
52
 
53
- const filter = (items, current) => {
53
+ const filter = (items, current = '') => {
54
54
  return normalize(items)
55
55
  .filter((item) => {
56
56
  switch (item.type) {
@@ -153,7 +153,7 @@ const argumentsParser = (shell) => {
153
153
  autocomplete
154
154
  }, command) => {
155
155
 
156
- const available = filter(await autocomplete?.(args[0] || '') || []);
156
+ const available = filter(await autocomplete?.(args[0] || '') || [], args[0]);
157
157
 
158
158
  if (available.length) {
159
159
  return output(available);
@@ -238,7 +238,7 @@ const argumentsParser = (shell) => {
238
238
  }];
239
239
  }
240
240
 
241
- return filter(await schemas[idx].autocomplete?.(current) || []);
241
+ return filter(await schemas[idx].autocomplete?.(current) || [], current);
242
242
 
243
243
  } else {
244
244
 
@@ -249,7 +249,7 @@ const argumentsParser = (shell) => {
249
249
  if (!current.startsWith('-')) {
250
250
  if (variadic === 'allow') {
251
251
  items = items.concat(
252
- filter(await autocomplete?.(current) || []));
252
+ filter(await autocomplete?.(current) || [], current));
253
253
  }
254
254
  }
255
255
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/arguments-parser",
3
- "version": "0.3.123",
3
+ "version": "0.3.124",
4
4
  "description": "Yet another arguments parser.",
5
5
  "main": "index.js",
6
6
  "type": "module",