@h3ravel/musket 0.1.10 → 0.2.1
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/README.md +54 -0
- package/dist/index.cjs +17 -2
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +17 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,6 +73,60 @@ Kernel.init(app, {
|
|
|
73
73
|
});
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
## Creating Commands
|
|
77
|
+
|
|
78
|
+
Commands in Musket extend the base `Command` class and define a **signature** and **handle()** method.
|
|
79
|
+
|
|
80
|
+
Example:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { Command } from '@h3ravel/musket';
|
|
84
|
+
|
|
85
|
+
export default class GreetCommand extends Command {
|
|
86
|
+
protected signature = 'greet {name}';
|
|
87
|
+
protected description = 'Display a personalized greeting.';
|
|
88
|
+
|
|
89
|
+
async handle() {
|
|
90
|
+
const name = this.argument('name');
|
|
91
|
+
|
|
92
|
+
this.info(`Hello, ${name}!`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
If your project uses discovery paths (via `discoveryPaths`),
|
|
98
|
+
this command will be automatically registered.
|
|
99
|
+
|
|
100
|
+
Otherwise, you can manually register it in your application:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
class Application {
|
|
104
|
+
registeredCommands = [GreetCommand];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
await Kernel.init(app);
|
|
108
|
+
|
|
109
|
+
// OR
|
|
110
|
+
|
|
111
|
+
await Kernel.init(app, {
|
|
112
|
+
baseCommands: [BuildCommand],
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Running Commands
|
|
117
|
+
|
|
118
|
+
Once your CLI is compiled or built, you can run commands via:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
node dist/cli.js greet Legacy
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Output:
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
Hello, Legacy!
|
|
128
|
+
```
|
|
129
|
+
|
|
76
130
|
## Documentation
|
|
77
131
|
|
|
78
132
|
The full musket documentation is available [Here](https://h3ravel.toneflix.net/musket)
|
package/dist/index.cjs
CHANGED
|
@@ -635,8 +635,9 @@ var Musket = class Musket {
|
|
|
635
635
|
verbose: ["-v, --verbose [level]", "Increase the verbosity of messages: 1 for normal output, 2 and v for more verbose output and 3 and vv for debug"],
|
|
636
636
|
noInteraction: ["-n, --no-interaction", "Do not ask any interactive question"]
|
|
637
637
|
};
|
|
638
|
-
|
|
639
|
-
|
|
638
|
+
if (!this.config.rootCommand)
|
|
639
|
+
/**
|
|
640
|
+
* Run the base Command if a root command was not defined
|
|
640
641
|
*/
|
|
641
642
|
commander.program.name(this.cliName).version(moduleVersions).description(this.config.logo ?? altLogo).configureHelp({ showGlobalOptions: true }).addOption(new commander.Option(additional.quiet[0], additional.quiet[1])).addOption(new commander.Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).addOption(new commander.Option(additional.verbose[0], additional.verbose[1]).choices([
|
|
642
643
|
"1",
|
|
@@ -649,6 +650,20 @@ var Musket = class Musket {
|
|
|
649
650
|
instance.setInput(commander.program.opts(), commander.program.args, commander.program.registeredArguments, {}, commander.program);
|
|
650
651
|
await this.handle(instance);
|
|
651
652
|
});
|
|
653
|
+
else {
|
|
654
|
+
/**
|
|
655
|
+
* Load the root command here
|
|
656
|
+
*/
|
|
657
|
+
const root = new this.config.rootCommand(this.app, this.kernel);
|
|
658
|
+
const sign = Signature.parseSignature(root.getSignature(), root);
|
|
659
|
+
const cmd = commander.program.name(sign.baseCommand).description(sign.description ?? sign.baseCommand).configureHelp({ showGlobalOptions: true }).action(async () => {
|
|
660
|
+
root.setInput(commander.program.opts(), commander.program.args, commander.program.registeredArguments, {}, commander.program);
|
|
661
|
+
await this.handle(root);
|
|
662
|
+
});
|
|
663
|
+
if ((sign.options?.length ?? 0) > 0) sign.options?.filter((v, i, a) => a.findIndex((t) => t.name === v.name) === i).forEach((opt) => {
|
|
664
|
+
this.makeOption(opt, cmd);
|
|
665
|
+
});
|
|
666
|
+
}
|
|
652
667
|
/**
|
|
653
668
|
* Format the help command display
|
|
654
669
|
*/
|
package/dist/index.d.cts
CHANGED
|
@@ -99,6 +99,10 @@ interface InitConfig {
|
|
|
99
99
|
* Commands that should be autoloaded by default
|
|
100
100
|
*/
|
|
101
101
|
baseCommands?: typeof Command[];
|
|
102
|
+
/**
|
|
103
|
+
* A command that will be run when the script is run without arguments
|
|
104
|
+
*/
|
|
105
|
+
rootCommand?: typeof Command;
|
|
102
106
|
/**
|
|
103
107
|
* Paths where musket can search and auto discover commands
|
|
104
108
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -99,6 +99,10 @@ interface InitConfig {
|
|
|
99
99
|
* Commands that should be autoloaded by default
|
|
100
100
|
*/
|
|
101
101
|
baseCommands?: typeof Command[];
|
|
102
|
+
/**
|
|
103
|
+
* A command that will be run when the script is run without arguments
|
|
104
|
+
*/
|
|
105
|
+
rootCommand?: typeof Command;
|
|
102
106
|
/**
|
|
103
107
|
* Paths where musket can search and auto discover commands
|
|
104
108
|
*
|
package/dist/index.js
CHANGED
|
@@ -605,8 +605,9 @@ var Musket = class Musket {
|
|
|
605
605
|
verbose: ["-v, --verbose [level]", "Increase the verbosity of messages: 1 for normal output, 2 and v for more verbose output and 3 and vv for debug"],
|
|
606
606
|
noInteraction: ["-n, --no-interaction", "Do not ask any interactive question"]
|
|
607
607
|
};
|
|
608
|
-
|
|
609
|
-
|
|
608
|
+
if (!this.config.rootCommand)
|
|
609
|
+
/**
|
|
610
|
+
* Run the base Command if a root command was not defined
|
|
610
611
|
*/
|
|
611
612
|
program.name(this.cliName).version(moduleVersions).description(this.config.logo ?? altLogo).configureHelp({ showGlobalOptions: true }).addOption(new Option(additional.quiet[0], additional.quiet[1])).addOption(new Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).addOption(new Option(additional.verbose[0], additional.verbose[1]).choices([
|
|
612
613
|
"1",
|
|
@@ -619,6 +620,20 @@ var Musket = class Musket {
|
|
|
619
620
|
instance.setInput(program.opts(), program.args, program.registeredArguments, {}, program);
|
|
620
621
|
await this.handle(instance);
|
|
621
622
|
});
|
|
623
|
+
else {
|
|
624
|
+
/**
|
|
625
|
+
* Load the root command here
|
|
626
|
+
*/
|
|
627
|
+
const root = new this.config.rootCommand(this.app, this.kernel);
|
|
628
|
+
const sign = Signature.parseSignature(root.getSignature(), root);
|
|
629
|
+
const cmd = program.name(sign.baseCommand).description(sign.description ?? sign.baseCommand).configureHelp({ showGlobalOptions: true }).action(async () => {
|
|
630
|
+
root.setInput(program.opts(), program.args, program.registeredArguments, {}, program);
|
|
631
|
+
await this.handle(root);
|
|
632
|
+
});
|
|
633
|
+
if ((sign.options?.length ?? 0) > 0) sign.options?.filter((v, i, a) => a.findIndex((t) => t.name === v.name) === i).forEach((opt) => {
|
|
634
|
+
this.makeOption(opt, cmd);
|
|
635
|
+
});
|
|
636
|
+
}
|
|
622
637
|
/**
|
|
623
638
|
* Format the help command display
|
|
624
639
|
*/
|
package/package.json
CHANGED