@trenskow/arguments-parser 0.3.87 → 0.3.88
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/lib/index.js +66 -19
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -59,7 +59,8 @@ const argumentsParser = (
|
|
|
59
59
|
schema: {},
|
|
60
60
|
data: {},
|
|
61
61
|
validationOptions: {}
|
|
62
|
-
}
|
|
62
|
+
},
|
|
63
|
+
parameters = {}
|
|
63
64
|
} = {}
|
|
64
65
|
) => {
|
|
65
66
|
|
|
@@ -148,6 +149,32 @@ const argumentsParser = (
|
|
|
148
149
|
if (args[0] === '--help') printHelp();
|
|
149
150
|
};
|
|
150
151
|
|
|
152
|
+
const next = async (identifier, command) => {
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
|
|
156
|
+
onCommand?.(identifier, args.slice(1));
|
|
157
|
+
|
|
158
|
+
return await command({
|
|
159
|
+
args: args.slice(1),
|
|
160
|
+
argumentsParser: argumentsParser({
|
|
161
|
+
args: args.slice(1),
|
|
162
|
+
argvLevel: argvLevel + 1,
|
|
163
|
+
onCommand,
|
|
164
|
+
placeholder,
|
|
165
|
+
command: command,
|
|
166
|
+
strings,
|
|
167
|
+
options,
|
|
168
|
+
parameters
|
|
169
|
+
})
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
} catch (error) {
|
|
173
|
+
print.err(`${error.stack}`);
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
151
178
|
const result = {
|
|
152
179
|
get base() {
|
|
153
180
|
return base;
|
|
@@ -187,27 +214,47 @@ const argumentsParser = (
|
|
|
187
214
|
.replace('<command>', args[0])));
|
|
188
215
|
}
|
|
189
216
|
|
|
190
|
-
|
|
217
|
+
return await next(
|
|
218
|
+
tool,
|
|
219
|
+
commands[tool]);
|
|
191
220
|
|
|
192
|
-
|
|
221
|
+
},
|
|
222
|
+
parameter: async (
|
|
223
|
+
identifier,
|
|
224
|
+
description,
|
|
225
|
+
schema,
|
|
226
|
+
command
|
|
227
|
+
) => {
|
|
228
|
+
|
|
229
|
+
if (typeof identifier !== 'string') {
|
|
230
|
+
throw new Error('Identifier must be a string');
|
|
231
|
+
}
|
|
193
232
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
})
|
|
233
|
+
helpUsage.push(`${opening}${caseit(identifier, 'kebab')}${closing}`);
|
|
234
|
+
|
|
235
|
+
helpOptions = () => {
|
|
236
|
+
|
|
237
|
+
print();
|
|
238
|
+
print(strings?.commands?.help?.available || 'Available commands:');
|
|
239
|
+
print();
|
|
240
|
+
|
|
241
|
+
list(print, {
|
|
242
|
+
[`${opening}${caseit(identifier, 'kebab')}${closing}`]: description
|
|
205
243
|
});
|
|
206
244
|
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
if (args.length === 0) printHelp();
|
|
248
|
+
|
|
249
|
+
checkHelp();
|
|
250
|
+
|
|
251
|
+
parameters[identifier] = await isvalid(
|
|
252
|
+
args[0],
|
|
253
|
+
schema);
|
|
254
|
+
|
|
255
|
+
return await next(
|
|
256
|
+
identifier,
|
|
257
|
+
command);
|
|
211
258
|
|
|
212
259
|
},
|
|
213
260
|
options: (schema, validationOptions = { }) => {
|
|
@@ -424,7 +471,7 @@ const argumentsParser = (
|
|
|
424
471
|
printHelp(error);
|
|
425
472
|
}
|
|
426
473
|
|
|
427
|
-
return Object.assign({}, data, {
|
|
474
|
+
return Object.assign({}, parameters, data, {
|
|
428
475
|
onError: (error) => {
|
|
429
476
|
print.err(error.message);
|
|
430
477
|
process.exit(1);
|