@crustjs/core 0.0.7 → 0.0.8

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.d.ts CHANGED
@@ -375,8 +375,8 @@ interface Command<
375
375
  readonly args?: A;
376
376
  /** Flag definitions */
377
377
  readonly flags?: F;
378
- /** Named subcommands */
379
- readonly subCommands?: Record<string, AnyCommand>;
378
+ /** Named subcommands (always initialized, may be empty) */
379
+ readonly subCommands: Record<string, AnyCommand>;
380
380
  /** Called before `run()` — useful for initialization */
381
381
  preRun?(context: CommandContext<A, F>): void | Promise<void>;
382
382
  /** The main command handler */
@@ -567,6 +567,19 @@ interface SetupActions {
567
567
  * @param def - The flag definition
568
568
  */
569
569
  addFlag(command: AnyCommand, name: string, def: FlagDef): void;
570
+ /**
571
+ * Inject a subcommand into a command's `subCommands` record.
572
+ *
573
+ * Use this in plugin `setup()` hooks to register plugin-provided commands
574
+ * (e.g. a "skill" management command). If the parent already has a
575
+ * subcommand with the same name (user-defined), the call is silently
576
+ * skipped — user definitions always take priority over plugin injections.
577
+ *
578
+ * @param parent - The parent command to add the subcommand to
579
+ * @param name - The subcommand name (used for routing)
580
+ * @param command - The subcommand to register
581
+ */
582
+ addSubCommand(parent: AnyCommand, name: string, command: AnyCommand): void;
570
583
  }
571
584
  /** Shared context fields available in both setup and middleware phases. */
572
585
  interface BaseContext {
@@ -594,4 +607,4 @@ interface RunOptions {
594
607
  }
595
608
  declare function runCommand(command: AnyCommand, options?: RunOptions): Promise<void>;
596
609
  declare function runMain(command: AnyCommand, options?: RunOptions): Promise<void>;
597
- export { runMain, runCommand, resolveCommand, parseArgs, defineCommand, ValueType, ValidateVariadicArgs, ValidateNoPrefixedFlags, ValidateFlagAliases, SetupContext, RunOptions, PluginMiddleware, ParseResult, MiddlewareContext, InferFlags, InferArgs, FlagsDef, FlagDef, CrustPlugin, CrustErrorCode, CrustError, CommandRoute, CommandMeta, CommandDef, CommandContext, Command, ArgsDef, ArgDef, AnyCommand };
610
+ export { runMain, runCommand, resolveCommand, parseArgs, defineCommand, ValueType, ValidateVariadicArgs, ValidateNoPrefixedFlags, ValidateFlagAliases, SetupContext, SetupActions, RunOptions, PluginMiddleware, ParseResult, MiddlewareContext, InferFlags, InferArgs, FlagsDef, FlagDef, CrustPlugin, CrustErrorCode, CrustError, CommandRoute, CommandMeta, CommandDef, CommandContext, Command, ArgsDef, ArgDef, AnyCommand };
package/dist/index.js CHANGED
@@ -47,9 +47,7 @@ function defineCommand(config) {
47
47
  args: config.args.map((def) => ({ ...def }))
48
48
  },
49
49
  flags: config.flags ? Object.fromEntries(Object.entries(config.flags).map(([k, v]) => [k, { ...v }])) : {},
50
- ...config.subCommands && {
51
- subCommands: { ...config.subCommands }
52
- }
50
+ subCommands: config.subCommands ? { ...config.subCommands } : {}
53
51
  };
54
52
  return Object.freeze(copy);
55
53
  }
@@ -392,6 +390,14 @@ async function runCommand(command, options) {
392
390
  throw new CrustError("DEFINITION", `Cannot add flag "${name}": command "${target.meta.name}" has no flags object.`);
393
391
  }
394
392
  target.flags[name] = def;
393
+ },
394
+ addSubCommand(parent, name, subCommand) {
395
+ if (!name.trim()) {
396
+ throw new CrustError("DEFINITION", "addSubCommand: name is required and must be a non-empty string");
397
+ }
398
+ if (parent.subCommands[name])
399
+ return;
400
+ parent.subCommands[name] = subCommand;
395
401
  }
396
402
  };
397
403
  const middlewareContext = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crustjs/core",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Core library for the Crust CLI framework",
5
5
  "type": "module",
6
6
  "license": "MIT",