@h3ravel/musket 0.1.10 → 0.2.0

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 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
- * Init Commander
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
- * Init Commander
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/musket",
3
- "version": "0.1.10",
3
+ "version": "0.2.0",
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
  "exports": {