@h3ravel/musket 0.8.0-alpha.2 → 0.8.0-alpha.4
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/dist/index.cjs +174 -19
- package/dist/index.d.ts +144 -53
- package/dist/index.js +174 -19
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -71,11 +71,28 @@ var Command = class {
|
|
|
71
71
|
};
|
|
72
72
|
/**
|
|
73
73
|
* Execute the console command.
|
|
74
|
+
*
|
|
75
|
+
* @param _args The command arguments
|
|
74
76
|
*/
|
|
75
77
|
async handle(..._args) {}
|
|
78
|
+
/**
|
|
79
|
+
* Set the application instance
|
|
80
|
+
*
|
|
81
|
+
* @param app The application instance
|
|
82
|
+
*/
|
|
76
83
|
setApplication(app) {
|
|
77
84
|
this.app = app;
|
|
78
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Set the command input
|
|
88
|
+
*
|
|
89
|
+
* @param options The command options
|
|
90
|
+
* @param args The command arguments
|
|
91
|
+
* @param regArgs The registered arguments
|
|
92
|
+
* @param dictionary The dictionary of signatures or what not
|
|
93
|
+
* @param program The underlying commander program
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
79
96
|
setInput(options, args, regArgs, dictionary, program) {
|
|
80
97
|
this.program = program;
|
|
81
98
|
this.dictionary = dictionary;
|
|
@@ -89,34 +106,84 @@ var Command = class {
|
|
|
89
106
|
});
|
|
90
107
|
return this;
|
|
91
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Set a specific option
|
|
111
|
+
*
|
|
112
|
+
* @param key The option key
|
|
113
|
+
* @param value The option value
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
92
116
|
setOption(key, value) {
|
|
93
117
|
this.program.setOptionValue(key, value);
|
|
94
118
|
return this;
|
|
95
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Set the underlying commander program
|
|
122
|
+
*
|
|
123
|
+
* @param program The underlying commander program
|
|
124
|
+
* @returns
|
|
125
|
+
*/
|
|
96
126
|
setProgram(program) {
|
|
97
127
|
this.program = program;
|
|
98
128
|
return this;
|
|
99
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Get the command signature
|
|
132
|
+
*
|
|
133
|
+
* @returns
|
|
134
|
+
*/
|
|
100
135
|
getSignature() {
|
|
101
136
|
return this.signature;
|
|
102
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Get the command description
|
|
140
|
+
*
|
|
141
|
+
* @returns
|
|
142
|
+
*/
|
|
103
143
|
getDescription() {
|
|
104
144
|
return this.description;
|
|
105
145
|
}
|
|
106
|
-
|
|
107
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Get a specific option
|
|
148
|
+
*
|
|
149
|
+
* @param key The option key
|
|
150
|
+
* @param defaultValue The default value
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
option(key, defaultValue) {
|
|
154
|
+
const option = this.input.options[key] ?? defaultValue;
|
|
108
155
|
return option === "null" || option === "undefined" ? void 0 : option;
|
|
109
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Get all options
|
|
159
|
+
*
|
|
160
|
+
* @param key The option key
|
|
161
|
+
* @returns
|
|
162
|
+
*/
|
|
110
163
|
options(key) {
|
|
111
164
|
if (key) return this.input.options[key];
|
|
112
165
|
return this.input.options;
|
|
113
166
|
}
|
|
114
|
-
|
|
115
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Get a specific argument
|
|
169
|
+
*
|
|
170
|
+
* @param key The argument key
|
|
171
|
+
* @param defaultValue The default value
|
|
172
|
+
* @returns
|
|
173
|
+
*/
|
|
174
|
+
argument(key, defaultValue) {
|
|
175
|
+
return this.input.arguments[key] ?? defaultValue;
|
|
116
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Get all arguments
|
|
179
|
+
* @returns
|
|
180
|
+
*/
|
|
117
181
|
arguments() {
|
|
118
182
|
return this.input.arguments;
|
|
119
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Load base flags into the command input
|
|
186
|
+
*/
|
|
120
187
|
loadBaseFlags() {
|
|
121
188
|
let verbose = 0;
|
|
122
189
|
if (this.program.getOptionValue("verbose") == "v") verbose = 2;
|
|
@@ -161,6 +228,9 @@ var Command = class {
|
|
|
161
228
|
}
|
|
162
229
|
/**
|
|
163
230
|
* Log an info message
|
|
231
|
+
*
|
|
232
|
+
* @param message The message to log
|
|
233
|
+
* @returns
|
|
164
234
|
*/
|
|
165
235
|
info(message) {
|
|
166
236
|
__h3ravel_shared.Logger.info(message);
|
|
@@ -168,6 +238,9 @@ var Command = class {
|
|
|
168
238
|
}
|
|
169
239
|
/**
|
|
170
240
|
* Log a warning message
|
|
241
|
+
*
|
|
242
|
+
* @param message The message to log
|
|
243
|
+
* @returns
|
|
171
244
|
*/
|
|
172
245
|
warn(message) {
|
|
173
246
|
__h3ravel_shared.Logger.warn(message);
|
|
@@ -175,6 +248,9 @@ var Command = class {
|
|
|
175
248
|
}
|
|
176
249
|
/**
|
|
177
250
|
* Log a line message
|
|
251
|
+
*
|
|
252
|
+
* @param message The message to log
|
|
253
|
+
* @returns
|
|
178
254
|
*/
|
|
179
255
|
line(message) {
|
|
180
256
|
__h3ravel_shared.Logger.log(message, "white");
|
|
@@ -182,6 +258,9 @@ var Command = class {
|
|
|
182
258
|
}
|
|
183
259
|
/**
|
|
184
260
|
* Log a new line
|
|
261
|
+
*
|
|
262
|
+
* @param count Number of new lines to log
|
|
263
|
+
* @returns
|
|
185
264
|
*/
|
|
186
265
|
newLine(count = 1) {
|
|
187
266
|
if (Number(this.getVerbosity()) >= 3 || !this.isSilent() && !this.isQuiet()) for (let i = 0; i < count; i++) console.log("");
|
|
@@ -189,6 +268,9 @@ var Command = class {
|
|
|
189
268
|
}
|
|
190
269
|
/**
|
|
191
270
|
* Log a success message
|
|
271
|
+
*
|
|
272
|
+
* @param message The message to log
|
|
273
|
+
* @returns
|
|
192
274
|
*/
|
|
193
275
|
success(message) {
|
|
194
276
|
__h3ravel_shared.Logger.success(message);
|
|
@@ -196,6 +278,9 @@ var Command = class {
|
|
|
196
278
|
}
|
|
197
279
|
/**
|
|
198
280
|
* Log an error message
|
|
281
|
+
*
|
|
282
|
+
* @param message The message to log
|
|
283
|
+
* @returns
|
|
199
284
|
*/
|
|
200
285
|
error(message) {
|
|
201
286
|
__h3ravel_shared.Logger.error(message, false);
|
|
@@ -206,6 +291,9 @@ var Command = class {
|
|
|
206
291
|
* return an exit code of 1
|
|
207
292
|
*
|
|
208
293
|
* This method is not chainable
|
|
294
|
+
*
|
|
295
|
+
* @param message The message to log
|
|
296
|
+
* @returns
|
|
209
297
|
*/
|
|
210
298
|
fail(message) {
|
|
211
299
|
this.error(message);
|
|
@@ -213,6 +301,9 @@ var Command = class {
|
|
|
213
301
|
}
|
|
214
302
|
/**
|
|
215
303
|
* Log a debug message
|
|
304
|
+
*
|
|
305
|
+
* @param message The message to log
|
|
306
|
+
* @returns
|
|
216
307
|
*/
|
|
217
308
|
debug(message) {
|
|
218
309
|
__h3ravel_shared.Logger.debug(message);
|
|
@@ -221,36 +312,92 @@ var Command = class {
|
|
|
221
312
|
/**
|
|
222
313
|
* Prompt the user with the given question, accept their input, and
|
|
223
314
|
* then return the user's input back to your command.
|
|
315
|
+
*
|
|
316
|
+
* @param message Message to display
|
|
317
|
+
* @param defaultValue The default value
|
|
318
|
+
* @returns
|
|
224
319
|
*/
|
|
225
|
-
ask(message,
|
|
226
|
-
return __h3ravel_shared.Prompts.ask(message,
|
|
320
|
+
ask(message, defaultValue) {
|
|
321
|
+
return __h3ravel_shared.Prompts.ask(message, defaultValue);
|
|
227
322
|
}
|
|
228
323
|
/**
|
|
229
324
|
* Allows users to pick from a predefined set of choices when asked a question.
|
|
325
|
+
*
|
|
326
|
+
* @param message Message to display
|
|
327
|
+
* @param choices The choices available to the user
|
|
328
|
+
* @param defaultIndex Item index front of which the cursor will initially appear
|
|
329
|
+
* @returns
|
|
230
330
|
*/
|
|
231
|
-
choice(message, choices, defaultIndex) {
|
|
232
|
-
return __h3ravel_shared.Prompts.choice(message, choices, defaultIndex);
|
|
331
|
+
choice(message, choices, defaultIndex, pageSize) {
|
|
332
|
+
return __h3ravel_shared.Prompts.choice(message, choices, defaultIndex, pageSize);
|
|
233
333
|
}
|
|
234
334
|
/**
|
|
235
335
|
* Ask the user for a simple "yes or no" confirmation. By default, this method returns `false`.
|
|
236
336
|
* However, if the user enters y or yes in response to the prompt, the method would return `true`.
|
|
337
|
+
*
|
|
338
|
+
* @param message Message to display
|
|
339
|
+
* @param defaultValue The default value
|
|
340
|
+
* @returns
|
|
237
341
|
*/
|
|
238
|
-
confirm(message,
|
|
239
|
-
return __h3ravel_shared.Prompts.confirm(message,
|
|
342
|
+
confirm(message, defaultValue) {
|
|
343
|
+
return __h3ravel_shared.Prompts.confirm(message, defaultValue);
|
|
240
344
|
}
|
|
241
345
|
/**
|
|
242
|
-
* Prompt the user with the given question, accept their input which will
|
|
243
|
-
*
|
|
346
|
+
* Prompt the user with the given question, accept their input which will be visible
|
|
347
|
+
* to them as they type in the console, and then return the user's input back to your command.
|
|
348
|
+
*
|
|
349
|
+
* @param message Message to display
|
|
350
|
+
* @param mask Mask the user input
|
|
351
|
+
* @returns
|
|
244
352
|
*/
|
|
245
353
|
secret(message, mask) {
|
|
246
354
|
return __h3ravel_shared.Prompts.secret(message, mask);
|
|
247
355
|
}
|
|
248
356
|
/**
|
|
357
|
+
* Display a spinner while performing a long task
|
|
358
|
+
*
|
|
359
|
+
* @param options The spinner options
|
|
360
|
+
* @returns
|
|
361
|
+
*/
|
|
362
|
+
spinner(options) {
|
|
363
|
+
return __h3ravel_shared.Prompts.spinner(options);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
249
366
|
* Provide auto-completion for possible choices. The user can still provide any
|
|
250
367
|
* answer, regardless of the auto-completion hints.
|
|
368
|
+
*
|
|
369
|
+
* @param message Message to dislpay
|
|
370
|
+
* @param source The source of completions
|
|
371
|
+
* @param defaultValue Set a default value
|
|
372
|
+
* @returns
|
|
251
373
|
*/
|
|
252
|
-
anticipate(message, source,
|
|
253
|
-
return __h3ravel_shared.Prompts.anticipate(message, source,
|
|
374
|
+
anticipate(message, source, defaultValue, pageSize) {
|
|
375
|
+
return __h3ravel_shared.Prompts.anticipate(message, source, defaultValue, pageSize);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Allows users to select multiple options from a predefined list of choices.
|
|
379
|
+
*
|
|
380
|
+
* @param message Message to display
|
|
381
|
+
* @param choices The choices available to the user
|
|
382
|
+
* @param required Whether at least one choice is required
|
|
383
|
+
* @param prefix Prefix to display before the message
|
|
384
|
+
* @param pageSize The number of items to show per page
|
|
385
|
+
* @returns
|
|
386
|
+
*/
|
|
387
|
+
checkbox(message, choices, required, prefix, pageSize) {
|
|
388
|
+
return __h3ravel_shared.Prompts.checkbox(message, choices, required, prefix, pageSize);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Open the user's default text editor to accept multi-line input.
|
|
392
|
+
*
|
|
393
|
+
* @param message Message to display
|
|
394
|
+
* @param postfix The postfix of the file being edited [e.g., '.txt', '.md']
|
|
395
|
+
* @param defaultValue The default value to pre-fill in the editor
|
|
396
|
+
* @param validate A function to validate the input text
|
|
397
|
+
* @returns
|
|
398
|
+
*/
|
|
399
|
+
editor(message, postfix, defaultValue, validate) {
|
|
400
|
+
return __h3ravel_shared.Prompts.editor(message, postfix, defaultValue, validate);
|
|
254
401
|
}
|
|
255
402
|
};
|
|
256
403
|
|
|
@@ -510,10 +657,18 @@ var Signature = class Signature {
|
|
|
510
657
|
} else flags.push(part);
|
|
511
658
|
}
|
|
512
659
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
660
|
+
/**
|
|
661
|
+
* Extract choices from the descriptions.
|
|
662
|
+
*
|
|
663
|
+
* Choices can be in the format:
|
|
664
|
+
* [choice1, choice2, choice3]
|
|
665
|
+
* choice1, choice2, choice3
|
|
666
|
+
* choices can have dots as well: [opt1.val, opt2.val]
|
|
667
|
+
*/
|
|
668
|
+
const desc = description.match(/\[([^\]]+)\]/) || description.match(/: ([^:\[\]]+(?:,[^:\[\]]+)*)$/);
|
|
669
|
+
if (desc) {
|
|
670
|
+
description = description.replace(desc[0], "").trim();
|
|
671
|
+
choices = desc[1].split(",").map((c) => c.trim());
|
|
517
672
|
}
|
|
518
673
|
options.push({
|
|
519
674
|
name: isFlag ? flags[flags.length - 1] : name,
|
|
@@ -636,7 +791,7 @@ var Musket = class Musket {
|
|
|
636
791
|
}
|
|
637
792
|
async loadDiscoveredCommands() {
|
|
638
793
|
const commands = [...(this.app.registeredCommands ?? []).map((cmd) => new cmd(this.app, this.kernel))];
|
|
639
|
-
const paths = Array.isArray(this.config.discoveryPaths) ? this.config.discoveryPaths : [this.config.discoveryPaths];
|
|
794
|
+
const paths = (Array.isArray(this.config.discoveryPaths) ? this.config.discoveryPaths : [this.config.discoveryPaths]).filter((e) => typeof e === "string");
|
|
640
795
|
/**
|
|
641
796
|
* CLI Commands auto registration
|
|
642
797
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as commander0 from "commander";
|
|
2
2
|
import { Argument, Command as Command$1 } from "commander";
|
|
3
|
-
import { ChoiceOrSeparatorArray, Choices } from "@h3ravel/shared";
|
|
3
|
+
import { ChoiceOrSeparatorArray, Choices, Spinner } from "@h3ravel/shared";
|
|
4
4
|
import { UserConfig } from "tsdown";
|
|
5
5
|
|
|
6
6
|
//#region src/Contracts/ICommand.d.ts
|
|
@@ -264,18 +264,85 @@ declare class Command<A extends Application = Application> {
|
|
|
264
264
|
private input;
|
|
265
265
|
/**
|
|
266
266
|
* Execute the console command.
|
|
267
|
+
*
|
|
268
|
+
* @param _args The command arguments
|
|
267
269
|
*/
|
|
268
270
|
handle(..._args: any[]): Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Set the application instance
|
|
273
|
+
*
|
|
274
|
+
* @param app The application instance
|
|
275
|
+
*/
|
|
269
276
|
setApplication(app: A): void;
|
|
277
|
+
/**
|
|
278
|
+
* Set the command input
|
|
279
|
+
*
|
|
280
|
+
* @param options The command options
|
|
281
|
+
* @param args The command arguments
|
|
282
|
+
* @param regArgs The registered arguments
|
|
283
|
+
* @param dictionary The dictionary of signatures or what not
|
|
284
|
+
* @param program The underlying commander program
|
|
285
|
+
* @returns
|
|
286
|
+
*/
|
|
270
287
|
setInput(options: XGeneric, args: string[], regArgs: readonly Argument[], dictionary: Record<string, any>, program: Command$1): this;
|
|
288
|
+
/**
|
|
289
|
+
* Set a specific option
|
|
290
|
+
*
|
|
291
|
+
* @param key The option key
|
|
292
|
+
* @param value The option value
|
|
293
|
+
* @returns
|
|
294
|
+
*/
|
|
271
295
|
setOption(key: string, value: unknown): this;
|
|
296
|
+
/**
|
|
297
|
+
* Set the underlying commander program
|
|
298
|
+
*
|
|
299
|
+
* @param program The underlying commander program
|
|
300
|
+
* @returns
|
|
301
|
+
*/
|
|
272
302
|
setProgram(program: Command$1): this;
|
|
303
|
+
/**
|
|
304
|
+
* Get the command signature
|
|
305
|
+
*
|
|
306
|
+
* @returns
|
|
307
|
+
*/
|
|
273
308
|
getSignature(): string;
|
|
309
|
+
/**
|
|
310
|
+
* Get the command description
|
|
311
|
+
*
|
|
312
|
+
* @returns
|
|
313
|
+
*/
|
|
274
314
|
getDescription(): string | undefined;
|
|
275
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Get a specific option
|
|
317
|
+
*
|
|
318
|
+
* @param key The option key
|
|
319
|
+
* @param defaultValue The default value
|
|
320
|
+
* @returns
|
|
321
|
+
*/
|
|
322
|
+
option(key: string, defaultValue?: any): any;
|
|
323
|
+
/**
|
|
324
|
+
* Get all options
|
|
325
|
+
*
|
|
326
|
+
* @param key The option key
|
|
327
|
+
* @returns
|
|
328
|
+
*/
|
|
276
329
|
options(key?: string): any;
|
|
277
|
-
|
|
330
|
+
/**
|
|
331
|
+
* Get a specific argument
|
|
332
|
+
*
|
|
333
|
+
* @param key The argument key
|
|
334
|
+
* @param defaultValue The default value
|
|
335
|
+
* @returns
|
|
336
|
+
*/
|
|
337
|
+
argument(key: string, defaultValue?: any): any;
|
|
338
|
+
/**
|
|
339
|
+
* Get all arguments
|
|
340
|
+
* @returns
|
|
341
|
+
*/
|
|
278
342
|
arguments(): Record<string, any>;
|
|
343
|
+
/**
|
|
344
|
+
* Load base flags into the command input
|
|
345
|
+
*/
|
|
279
346
|
loadBaseFlags(): void;
|
|
280
347
|
/**
|
|
281
348
|
* Check if the command is quiet
|
|
@@ -303,26 +370,44 @@ declare class Command<A extends Application = Application> {
|
|
|
303
370
|
getVerbosity(): number;
|
|
304
371
|
/**
|
|
305
372
|
* Log an info message
|
|
373
|
+
*
|
|
374
|
+
* @param message The message to log
|
|
375
|
+
* @returns
|
|
306
376
|
*/
|
|
307
377
|
info(message: string): this;
|
|
308
378
|
/**
|
|
309
379
|
* Log a warning message
|
|
380
|
+
*
|
|
381
|
+
* @param message The message to log
|
|
382
|
+
* @returns
|
|
310
383
|
*/
|
|
311
384
|
warn(message: string): this;
|
|
312
385
|
/**
|
|
313
386
|
* Log a line message
|
|
387
|
+
*
|
|
388
|
+
* @param message The message to log
|
|
389
|
+
* @returns
|
|
314
390
|
*/
|
|
315
391
|
line(message: string): this;
|
|
316
392
|
/**
|
|
317
393
|
* Log a new line
|
|
394
|
+
*
|
|
395
|
+
* @param count Number of new lines to log
|
|
396
|
+
* @returns
|
|
318
397
|
*/
|
|
319
398
|
newLine(count?: number): this;
|
|
320
399
|
/**
|
|
321
400
|
* Log a success message
|
|
401
|
+
*
|
|
402
|
+
* @param message The message to log
|
|
403
|
+
* @returns
|
|
322
404
|
*/
|
|
323
405
|
success(message: string): this;
|
|
324
406
|
/**
|
|
325
407
|
* Log an error message
|
|
408
|
+
*
|
|
409
|
+
* @param message The message to log
|
|
410
|
+
* @returns
|
|
326
411
|
*/
|
|
327
412
|
error(message: string): this;
|
|
328
413
|
/**
|
|
@@ -330,86 +415,92 @@ declare class Command<A extends Application = Application> {
|
|
|
330
415
|
* return an exit code of 1
|
|
331
416
|
*
|
|
332
417
|
* This method is not chainable
|
|
418
|
+
*
|
|
419
|
+
* @param message The message to log
|
|
420
|
+
* @returns
|
|
333
421
|
*/
|
|
334
422
|
fail(message: string): void;
|
|
335
423
|
/**
|
|
336
424
|
* Log a debug message
|
|
425
|
+
*
|
|
426
|
+
* @param message The message to log
|
|
427
|
+
* @returns
|
|
337
428
|
*/
|
|
338
429
|
debug(message: string | string[]): this;
|
|
339
430
|
/**
|
|
340
431
|
* Prompt the user with the given question, accept their input, and
|
|
341
432
|
* then return the user's input back to your command.
|
|
433
|
+
*
|
|
434
|
+
* @param message Message to display
|
|
435
|
+
* @param defaultValue The default value
|
|
436
|
+
* @returns
|
|
342
437
|
*/
|
|
343
|
-
ask(
|
|
344
|
-
/**
|
|
345
|
-
* Message to dislpay
|
|
346
|
-
*/
|
|
347
|
-
message: string,
|
|
348
|
-
/**
|
|
349
|
-
* The default value
|
|
350
|
-
*/
|
|
351
|
-
def?: string | undefined): Promise<string>;
|
|
438
|
+
ask(message: string, defaultValue?: string | undefined): Promise<string>;
|
|
352
439
|
/**
|
|
353
440
|
* Allows users to pick from a predefined set of choices when asked a question.
|
|
441
|
+
*
|
|
442
|
+
* @param message Message to display
|
|
443
|
+
* @param choices The choices available to the user
|
|
444
|
+
* @param defaultIndex Item index front of which the cursor will initially appear
|
|
445
|
+
* @returns
|
|
354
446
|
*/
|
|
355
|
-
choice(
|
|
356
|
-
/**
|
|
357
|
-
* Message to dislpay
|
|
358
|
-
*/
|
|
359
|
-
message: string,
|
|
360
|
-
/**
|
|
361
|
-
* The choices available to the user
|
|
362
|
-
*/
|
|
363
|
-
choices: Choices,
|
|
364
|
-
/**
|
|
365
|
-
* Item index front of which the cursor will initially appear
|
|
366
|
-
*/
|
|
367
|
-
defaultIndex?: number): Promise<string>;
|
|
447
|
+
choice(message: string, choices: Choices, defaultIndex?: number, pageSize?: number): Promise<string>;
|
|
368
448
|
/**
|
|
369
449
|
* Ask the user for a simple "yes or no" confirmation. By default, this method returns `false`.
|
|
370
450
|
* However, if the user enters y or yes in response to the prompt, the method would return `true`.
|
|
451
|
+
*
|
|
452
|
+
* @param message Message to display
|
|
453
|
+
* @param defaultValue The default value
|
|
454
|
+
* @returns
|
|
371
455
|
*/
|
|
372
|
-
confirm(
|
|
373
|
-
/**
|
|
374
|
-
* Message to dislpay
|
|
375
|
-
*/
|
|
376
|
-
message: string,
|
|
377
|
-
/**
|
|
378
|
-
* The default value
|
|
379
|
-
*/
|
|
380
|
-
def?: boolean | undefined): Promise<boolean>;
|
|
456
|
+
confirm(message: string, defaultValue?: boolean | undefined): Promise<boolean>;
|
|
381
457
|
/**
|
|
382
|
-
* Prompt the user with the given question, accept their input which will
|
|
383
|
-
*
|
|
458
|
+
* Prompt the user with the given question, accept their input which will be visible
|
|
459
|
+
* to them as they type in the console, and then return the user's input back to your command.
|
|
460
|
+
*
|
|
461
|
+
* @param message Message to display
|
|
462
|
+
* @param mask Mask the user input
|
|
463
|
+
* @returns
|
|
384
464
|
*/
|
|
385
|
-
secret(
|
|
386
|
-
/**
|
|
387
|
-
* Message to dislpay
|
|
388
|
-
*/
|
|
389
|
-
message: string,
|
|
465
|
+
secret(message: string, mask?: string | boolean): Promise<string>;
|
|
390
466
|
/**
|
|
391
|
-
*
|
|
467
|
+
* Display a spinner while performing a long task
|
|
392
468
|
*
|
|
393
|
-
* @
|
|
469
|
+
* @param options The spinner options
|
|
470
|
+
* @returns
|
|
394
471
|
*/
|
|
395
|
-
|
|
472
|
+
spinner(options?: string): Spinner;
|
|
396
473
|
/**
|
|
397
474
|
* Provide auto-completion for possible choices. The user can still provide any
|
|
398
475
|
* answer, regardless of the auto-completion hints.
|
|
476
|
+
*
|
|
477
|
+
* @param message Message to dislpay
|
|
478
|
+
* @param source The source of completions
|
|
479
|
+
* @param defaultValue Set a default value
|
|
480
|
+
* @returns
|
|
399
481
|
*/
|
|
400
|
-
anticipate(
|
|
401
|
-
/**
|
|
402
|
-
* Message to dislpay
|
|
403
|
-
*/
|
|
404
|
-
message: string,
|
|
482
|
+
anticipate(message: string, source: string[] | ((input?: string | undefined) => Promise<ChoiceOrSeparatorArray<any>>), defaultValue?: string, pageSize?: number): Promise<any>;
|
|
405
483
|
/**
|
|
406
|
-
*
|
|
484
|
+
* Allows users to select multiple options from a predefined list of choices.
|
|
485
|
+
*
|
|
486
|
+
* @param message Message to display
|
|
487
|
+
* @param choices The choices available to the user
|
|
488
|
+
* @param required Whether at least one choice is required
|
|
489
|
+
* @param prefix Prefix to display before the message
|
|
490
|
+
* @param pageSize The number of items to show per page
|
|
491
|
+
* @returns
|
|
407
492
|
*/
|
|
408
|
-
|
|
493
|
+
checkbox(message: string, choices: Choices, required?: boolean, prefix?: string, pageSize?: number): Promise<string[]>;
|
|
409
494
|
/**
|
|
410
|
-
*
|
|
495
|
+
* Open the user's default text editor to accept multi-line input.
|
|
496
|
+
*
|
|
497
|
+
* @param message Message to display
|
|
498
|
+
* @param postfix The postfix of the file being edited [e.g., '.txt', '.md']
|
|
499
|
+
* @param defaultValue The default value to pre-fill in the editor
|
|
500
|
+
* @param validate A function to validate the input text
|
|
501
|
+
* @returns
|
|
411
502
|
*/
|
|
412
|
-
|
|
503
|
+
editor(message?: string, postfix?: string, defaultValue?: string, validate?: (text: string) => boolean | string): Promise<string>;
|
|
413
504
|
}
|
|
414
505
|
//#endregion
|
|
415
506
|
//#region src/Musket.d.ts
|
package/dist/index.js
CHANGED
|
@@ -47,11 +47,28 @@ var Command = class {
|
|
|
47
47
|
};
|
|
48
48
|
/**
|
|
49
49
|
* Execute the console command.
|
|
50
|
+
*
|
|
51
|
+
* @param _args The command arguments
|
|
50
52
|
*/
|
|
51
53
|
async handle(..._args) {}
|
|
54
|
+
/**
|
|
55
|
+
* Set the application instance
|
|
56
|
+
*
|
|
57
|
+
* @param app The application instance
|
|
58
|
+
*/
|
|
52
59
|
setApplication(app) {
|
|
53
60
|
this.app = app;
|
|
54
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Set the command input
|
|
64
|
+
*
|
|
65
|
+
* @param options The command options
|
|
66
|
+
* @param args The command arguments
|
|
67
|
+
* @param regArgs The registered arguments
|
|
68
|
+
* @param dictionary The dictionary of signatures or what not
|
|
69
|
+
* @param program The underlying commander program
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
55
72
|
setInput(options, args, regArgs, dictionary, program) {
|
|
56
73
|
this.program = program;
|
|
57
74
|
this.dictionary = dictionary;
|
|
@@ -65,34 +82,84 @@ var Command = class {
|
|
|
65
82
|
});
|
|
66
83
|
return this;
|
|
67
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Set a specific option
|
|
87
|
+
*
|
|
88
|
+
* @param key The option key
|
|
89
|
+
* @param value The option value
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
68
92
|
setOption(key, value) {
|
|
69
93
|
this.program.setOptionValue(key, value);
|
|
70
94
|
return this;
|
|
71
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Set the underlying commander program
|
|
98
|
+
*
|
|
99
|
+
* @param program The underlying commander program
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
72
102
|
setProgram(program) {
|
|
73
103
|
this.program = program;
|
|
74
104
|
return this;
|
|
75
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the command signature
|
|
108
|
+
*
|
|
109
|
+
* @returns
|
|
110
|
+
*/
|
|
76
111
|
getSignature() {
|
|
77
112
|
return this.signature;
|
|
78
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Get the command description
|
|
116
|
+
*
|
|
117
|
+
* @returns
|
|
118
|
+
*/
|
|
79
119
|
getDescription() {
|
|
80
120
|
return this.description;
|
|
81
121
|
}
|
|
82
|
-
|
|
83
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Get a specific option
|
|
124
|
+
*
|
|
125
|
+
* @param key The option key
|
|
126
|
+
* @param defaultValue The default value
|
|
127
|
+
* @returns
|
|
128
|
+
*/
|
|
129
|
+
option(key, defaultValue) {
|
|
130
|
+
const option = this.input.options[key] ?? defaultValue;
|
|
84
131
|
return option === "null" || option === "undefined" ? void 0 : option;
|
|
85
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Get all options
|
|
135
|
+
*
|
|
136
|
+
* @param key The option key
|
|
137
|
+
* @returns
|
|
138
|
+
*/
|
|
86
139
|
options(key) {
|
|
87
140
|
if (key) return this.input.options[key];
|
|
88
141
|
return this.input.options;
|
|
89
142
|
}
|
|
90
|
-
|
|
91
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Get a specific argument
|
|
145
|
+
*
|
|
146
|
+
* @param key The argument key
|
|
147
|
+
* @param defaultValue The default value
|
|
148
|
+
* @returns
|
|
149
|
+
*/
|
|
150
|
+
argument(key, defaultValue) {
|
|
151
|
+
return this.input.arguments[key] ?? defaultValue;
|
|
92
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Get all arguments
|
|
155
|
+
* @returns
|
|
156
|
+
*/
|
|
93
157
|
arguments() {
|
|
94
158
|
return this.input.arguments;
|
|
95
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Load base flags into the command input
|
|
162
|
+
*/
|
|
96
163
|
loadBaseFlags() {
|
|
97
164
|
let verbose = 0;
|
|
98
165
|
if (this.program.getOptionValue("verbose") == "v") verbose = 2;
|
|
@@ -137,6 +204,9 @@ var Command = class {
|
|
|
137
204
|
}
|
|
138
205
|
/**
|
|
139
206
|
* Log an info message
|
|
207
|
+
*
|
|
208
|
+
* @param message The message to log
|
|
209
|
+
* @returns
|
|
140
210
|
*/
|
|
141
211
|
info(message) {
|
|
142
212
|
Logger.info(message);
|
|
@@ -144,6 +214,9 @@ var Command = class {
|
|
|
144
214
|
}
|
|
145
215
|
/**
|
|
146
216
|
* Log a warning message
|
|
217
|
+
*
|
|
218
|
+
* @param message The message to log
|
|
219
|
+
* @returns
|
|
147
220
|
*/
|
|
148
221
|
warn(message) {
|
|
149
222
|
Logger.warn(message);
|
|
@@ -151,6 +224,9 @@ var Command = class {
|
|
|
151
224
|
}
|
|
152
225
|
/**
|
|
153
226
|
* Log a line message
|
|
227
|
+
*
|
|
228
|
+
* @param message The message to log
|
|
229
|
+
* @returns
|
|
154
230
|
*/
|
|
155
231
|
line(message) {
|
|
156
232
|
Logger.log(message, "white");
|
|
@@ -158,6 +234,9 @@ var Command = class {
|
|
|
158
234
|
}
|
|
159
235
|
/**
|
|
160
236
|
* Log a new line
|
|
237
|
+
*
|
|
238
|
+
* @param count Number of new lines to log
|
|
239
|
+
* @returns
|
|
161
240
|
*/
|
|
162
241
|
newLine(count = 1) {
|
|
163
242
|
if (Number(this.getVerbosity()) >= 3 || !this.isSilent() && !this.isQuiet()) for (let i = 0; i < count; i++) console.log("");
|
|
@@ -165,6 +244,9 @@ var Command = class {
|
|
|
165
244
|
}
|
|
166
245
|
/**
|
|
167
246
|
* Log a success message
|
|
247
|
+
*
|
|
248
|
+
* @param message The message to log
|
|
249
|
+
* @returns
|
|
168
250
|
*/
|
|
169
251
|
success(message) {
|
|
170
252
|
Logger.success(message);
|
|
@@ -172,6 +254,9 @@ var Command = class {
|
|
|
172
254
|
}
|
|
173
255
|
/**
|
|
174
256
|
* Log an error message
|
|
257
|
+
*
|
|
258
|
+
* @param message The message to log
|
|
259
|
+
* @returns
|
|
175
260
|
*/
|
|
176
261
|
error(message) {
|
|
177
262
|
Logger.error(message, false);
|
|
@@ -182,6 +267,9 @@ var Command = class {
|
|
|
182
267
|
* return an exit code of 1
|
|
183
268
|
*
|
|
184
269
|
* This method is not chainable
|
|
270
|
+
*
|
|
271
|
+
* @param message The message to log
|
|
272
|
+
* @returns
|
|
185
273
|
*/
|
|
186
274
|
fail(message) {
|
|
187
275
|
this.error(message);
|
|
@@ -189,6 +277,9 @@ var Command = class {
|
|
|
189
277
|
}
|
|
190
278
|
/**
|
|
191
279
|
* Log a debug message
|
|
280
|
+
*
|
|
281
|
+
* @param message The message to log
|
|
282
|
+
* @returns
|
|
192
283
|
*/
|
|
193
284
|
debug(message) {
|
|
194
285
|
Logger.debug(message);
|
|
@@ -197,36 +288,92 @@ var Command = class {
|
|
|
197
288
|
/**
|
|
198
289
|
* Prompt the user with the given question, accept their input, and
|
|
199
290
|
* then return the user's input back to your command.
|
|
291
|
+
*
|
|
292
|
+
* @param message Message to display
|
|
293
|
+
* @param defaultValue The default value
|
|
294
|
+
* @returns
|
|
200
295
|
*/
|
|
201
|
-
ask(message,
|
|
202
|
-
return Prompts.ask(message,
|
|
296
|
+
ask(message, defaultValue) {
|
|
297
|
+
return Prompts.ask(message, defaultValue);
|
|
203
298
|
}
|
|
204
299
|
/**
|
|
205
300
|
* Allows users to pick from a predefined set of choices when asked a question.
|
|
301
|
+
*
|
|
302
|
+
* @param message Message to display
|
|
303
|
+
* @param choices The choices available to the user
|
|
304
|
+
* @param defaultIndex Item index front of which the cursor will initially appear
|
|
305
|
+
* @returns
|
|
206
306
|
*/
|
|
207
|
-
choice(message, choices, defaultIndex) {
|
|
208
|
-
return Prompts.choice(message, choices, defaultIndex);
|
|
307
|
+
choice(message, choices, defaultIndex, pageSize) {
|
|
308
|
+
return Prompts.choice(message, choices, defaultIndex, pageSize);
|
|
209
309
|
}
|
|
210
310
|
/**
|
|
211
311
|
* Ask the user for a simple "yes or no" confirmation. By default, this method returns `false`.
|
|
212
312
|
* However, if the user enters y or yes in response to the prompt, the method would return `true`.
|
|
313
|
+
*
|
|
314
|
+
* @param message Message to display
|
|
315
|
+
* @param defaultValue The default value
|
|
316
|
+
* @returns
|
|
213
317
|
*/
|
|
214
|
-
confirm(message,
|
|
215
|
-
return Prompts.confirm(message,
|
|
318
|
+
confirm(message, defaultValue) {
|
|
319
|
+
return Prompts.confirm(message, defaultValue);
|
|
216
320
|
}
|
|
217
321
|
/**
|
|
218
|
-
* Prompt the user with the given question, accept their input which will
|
|
219
|
-
*
|
|
322
|
+
* Prompt the user with the given question, accept their input which will be visible
|
|
323
|
+
* to them as they type in the console, and then return the user's input back to your command.
|
|
324
|
+
*
|
|
325
|
+
* @param message Message to display
|
|
326
|
+
* @param mask Mask the user input
|
|
327
|
+
* @returns
|
|
220
328
|
*/
|
|
221
329
|
secret(message, mask) {
|
|
222
330
|
return Prompts.secret(message, mask);
|
|
223
331
|
}
|
|
224
332
|
/**
|
|
333
|
+
* Display a spinner while performing a long task
|
|
334
|
+
*
|
|
335
|
+
* @param options The spinner options
|
|
336
|
+
* @returns
|
|
337
|
+
*/
|
|
338
|
+
spinner(options) {
|
|
339
|
+
return Prompts.spinner(options);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
225
342
|
* Provide auto-completion for possible choices. The user can still provide any
|
|
226
343
|
* answer, regardless of the auto-completion hints.
|
|
344
|
+
*
|
|
345
|
+
* @param message Message to dislpay
|
|
346
|
+
* @param source The source of completions
|
|
347
|
+
* @param defaultValue Set a default value
|
|
348
|
+
* @returns
|
|
227
349
|
*/
|
|
228
|
-
anticipate(message, source,
|
|
229
|
-
return Prompts.anticipate(message, source,
|
|
350
|
+
anticipate(message, source, defaultValue, pageSize) {
|
|
351
|
+
return Prompts.anticipate(message, source, defaultValue, pageSize);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Allows users to select multiple options from a predefined list of choices.
|
|
355
|
+
*
|
|
356
|
+
* @param message Message to display
|
|
357
|
+
* @param choices The choices available to the user
|
|
358
|
+
* @param required Whether at least one choice is required
|
|
359
|
+
* @param prefix Prefix to display before the message
|
|
360
|
+
* @param pageSize The number of items to show per page
|
|
361
|
+
* @returns
|
|
362
|
+
*/
|
|
363
|
+
checkbox(message, choices, required, prefix, pageSize) {
|
|
364
|
+
return Prompts.checkbox(message, choices, required, prefix, pageSize);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Open the user's default text editor to accept multi-line input.
|
|
368
|
+
*
|
|
369
|
+
* @param message Message to display
|
|
370
|
+
* @param postfix The postfix of the file being edited [e.g., '.txt', '.md']
|
|
371
|
+
* @param defaultValue The default value to pre-fill in the editor
|
|
372
|
+
* @param validate A function to validate the input text
|
|
373
|
+
* @returns
|
|
374
|
+
*/
|
|
375
|
+
editor(message, postfix, defaultValue, validate) {
|
|
376
|
+
return Prompts.editor(message, postfix, defaultValue, validate);
|
|
230
377
|
}
|
|
231
378
|
};
|
|
232
379
|
|
|
@@ -486,10 +633,18 @@ var Signature = class Signature {
|
|
|
486
633
|
} else flags.push(part);
|
|
487
634
|
}
|
|
488
635
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
636
|
+
/**
|
|
637
|
+
* Extract choices from the descriptions.
|
|
638
|
+
*
|
|
639
|
+
* Choices can be in the format:
|
|
640
|
+
* [choice1, choice2, choice3]
|
|
641
|
+
* choice1, choice2, choice3
|
|
642
|
+
* choices can have dots as well: [opt1.val, opt2.val]
|
|
643
|
+
*/
|
|
644
|
+
const desc = description.match(/\[([^\]]+)\]/) || description.match(/: ([^:\[\]]+(?:,[^:\[\]]+)*)$/);
|
|
645
|
+
if (desc) {
|
|
646
|
+
description = description.replace(desc[0], "").trim();
|
|
647
|
+
choices = desc[1].split(",").map((c) => c.trim());
|
|
493
648
|
}
|
|
494
649
|
options.push({
|
|
495
650
|
name: isFlag ? flags[flags.length - 1] : name,
|
|
@@ -612,7 +767,7 @@ var Musket = class Musket {
|
|
|
612
767
|
}
|
|
613
768
|
async loadDiscoveredCommands() {
|
|
614
769
|
const commands = [...(this.app.registeredCommands ?? []).map((cmd) => new cmd(this.app, this.kernel))];
|
|
615
|
-
const paths = Array.isArray(this.config.discoveryPaths) ? this.config.discoveryPaths : [this.config.discoveryPaths];
|
|
770
|
+
const paths = (Array.isArray(this.config.discoveryPaths) ? this.config.discoveryPaths : [this.config.discoveryPaths]).filter((e) => typeof e === "string");
|
|
616
771
|
/**
|
|
617
772
|
* CLI Commands auto registration
|
|
618
773
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/musket",
|
|
3
|
-
"version": "0.8.0-alpha.
|
|
3
|
+
"version": "0.8.0-alpha.4",
|
|
4
4
|
"description": "Musket CLI is a framework-agnostic CLI framework designed to allow you build artisan-like CLI apps and for use in the H3ravel framework.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"vitest": "^3.2.4"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@h3ravel/shared": "^0.29.0-alpha.
|
|
66
|
+
"@h3ravel/shared": "^0.29.0-alpha.9",
|
|
67
67
|
"chalk": "^5.6.2",
|
|
68
68
|
"commander": "^14.0.1",
|
|
69
69
|
"dayjs": "^1.11.18",
|