@trenskow/arguments-parser 0.3.87 → 0.3.89
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 +68 -17
- 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,28 +214,52 @@ 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
|
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
if (args.length === 0) printHelp();
|
|
248
|
+
|
|
249
|
+
checkHelp();
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
parameters[identifier] = await isvalid(
|
|
253
|
+
args[0],
|
|
254
|
+
schema);
|
|
207
255
|
} catch (error) {
|
|
208
|
-
|
|
209
|
-
process.exit(1);
|
|
256
|
+
printHelp(error);
|
|
210
257
|
}
|
|
211
258
|
|
|
259
|
+
return await next(
|
|
260
|
+
identifier,
|
|
261
|
+
command);
|
|
262
|
+
|
|
212
263
|
},
|
|
213
264
|
options: (schema, validationOptions = { }) => {
|
|
214
265
|
|
|
@@ -424,7 +475,7 @@ const argumentsParser = (
|
|
|
424
475
|
printHelp(error);
|
|
425
476
|
}
|
|
426
477
|
|
|
427
|
-
return Object.assign({}, data, {
|
|
478
|
+
return Object.assign({}, parameters, data, {
|
|
428
479
|
onError: (error) => {
|
|
429
480
|
print.err(error.message);
|
|
430
481
|
process.exit(1);
|