@navios/commander 0.9.0 → 1.0.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.
Files changed (77) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +45 -18
  3. package/dist/src/commander.factory.d.mts +84 -10
  4. package/dist/src/commander.factory.d.mts.map +1 -1
  5. package/dist/src/commands/help.command.d.mts +18 -0
  6. package/dist/src/commands/help.command.d.mts.map +1 -0
  7. package/dist/src/commands/index.d.mts +2 -0
  8. package/dist/src/commands/index.d.mts.map +1 -0
  9. package/dist/src/decorators/cli-module.decorator.d.mts +36 -4
  10. package/dist/src/decorators/cli-module.decorator.d.mts.map +1 -1
  11. package/dist/src/decorators/command.decorator.d.mts +6 -1
  12. package/dist/src/decorators/command.decorator.d.mts.map +1 -1
  13. package/dist/src/define-environment.d.mts +31 -0
  14. package/dist/src/define-environment.d.mts.map +1 -0
  15. package/dist/src/index.d.mts +2 -1
  16. package/dist/src/index.d.mts.map +1 -1
  17. package/dist/src/interfaces/abstract-cli-adapter.interface.d.mts +53 -0
  18. package/dist/src/interfaces/abstract-cli-adapter.interface.d.mts.map +1 -0
  19. package/dist/src/interfaces/commander-execution-context.interface.d.mts +1 -1
  20. package/dist/src/interfaces/environment.interface.d.mts +30 -0
  21. package/dist/src/interfaces/environment.interface.d.mts.map +1 -0
  22. package/dist/src/interfaces/index.d.mts +2 -0
  23. package/dist/src/interfaces/index.d.mts.map +1 -1
  24. package/dist/src/metadata/cli-module.metadata.d.mts +4 -0
  25. package/dist/src/metadata/cli-module.metadata.d.mts.map +1 -1
  26. package/dist/src/metadata/command-entry.metadata.d.mts +31 -0
  27. package/dist/src/metadata/command-entry.metadata.d.mts.map +1 -0
  28. package/dist/src/metadata/command.metadata.d.mts +6 -1
  29. package/dist/src/metadata/command.metadata.d.mts.map +1 -1
  30. package/dist/src/metadata/index.d.mts +1 -1
  31. package/dist/src/metadata/index.d.mts.map +1 -1
  32. package/dist/src/services/cli-parser.service.d.mts +2 -12
  33. package/dist/src/services/cli-parser.service.d.mts.map +1 -1
  34. package/dist/src/services/command-registry.service.d.mts +89 -0
  35. package/dist/src/services/command-registry.service.d.mts.map +1 -0
  36. package/dist/src/services/commander-adapter.service.d.mts +56 -0
  37. package/dist/src/services/commander-adapter.service.d.mts.map +1 -0
  38. package/dist/src/services/index.d.mts +2 -1
  39. package/dist/src/services/index.d.mts.map +1 -1
  40. package/dist/src/services/module-loader.service.d.mts +2 -0
  41. package/dist/src/services/module-loader.service.d.mts.map +1 -1
  42. package/dist/src/tokens/execution-context.token.d.mts +1 -1
  43. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  44. package/dist/tsconfig.tsbuildinfo +1 -1
  45. package/lib/index.cjs +520 -6663
  46. package/lib/index.cjs.map +1 -1
  47. package/lib/index.d.cts +431 -293
  48. package/lib/index.d.cts.map +1 -1
  49. package/lib/index.d.mts +431 -293
  50. package/lib/index.d.mts.map +1 -1
  51. package/lib/index.mjs +507 -6493
  52. package/lib/index.mjs.map +1 -1
  53. package/package.json +2 -2
  54. package/src/__tests__/commander.factory.e2e.spec.mts +258 -68
  55. package/src/commander.factory.mts +109 -17
  56. package/src/commands/help.command.mts +37 -0
  57. package/src/commands/index.mts +1 -0
  58. package/src/decorators/cli-module.decorator.mts +73 -18
  59. package/src/decorators/command.decorator.mts +7 -1
  60. package/src/define-environment.mts +39 -0
  61. package/src/index.mts +2 -1
  62. package/src/interfaces/abstract-cli-adapter.interface.mts +52 -0
  63. package/src/interfaces/commander-execution-context.interface.mts +1 -1
  64. package/src/interfaces/environment.interface.mts +34 -0
  65. package/src/interfaces/index.mts +2 -0
  66. package/src/metadata/command-entry.metadata.mts +41 -0
  67. package/src/metadata/command.metadata.mts +7 -0
  68. package/src/metadata/index.mts +1 -1
  69. package/src/services/cli-parser.service.mts +14 -28
  70. package/src/services/command-registry.service.mts +217 -0
  71. package/src/services/commander-adapter.service.mts +209 -0
  72. package/src/services/index.mts +2 -1
  73. package/src/tokens/execution-context.token.mts +1 -1
  74. package/tsconfig.json +1 -1
  75. package/src/commander.application.mts +0 -303
  76. package/src/metadata/cli-module.metadata.mts +0 -95
  77. package/src/services/module-loader.service.mts +0 -160
package/lib/index.d.cts CHANGED
@@ -1,156 +1,204 @@
1
- import { ClassType, ClassTypeWithInstance, Container, InjectionToken, NaviosModule, Registry } from "@navios/core";
2
- import { ZodObject } from "zod";
1
+ import { AbstractAdapterInterface, AdapterEnvironment, AnyInjectableType, ClassType, ClassTypeWithInstance, InjectionToken, LogLevel, ModuleMetadata, NaviosApplication, NaviosModule, Registry } from "@navios/core";
2
+ import { ZodObject, z } from "zod";
3
3
  export * from "@navios/core";
4
4
 
5
- //#region src/commander.application.d.mts
5
+ //#region src/interfaces/command-handler.interface.d.mts
6
6
 
7
7
  /**
8
- * Configuration options for CommanderApplication.
8
+ * Interface that all command classes must implement.
9
9
  *
10
- * @public
11
- */
12
- interface CommanderApplicationOptions {}
13
- /**
14
- * Main application class for managing CLI command execution.
10
+ * Commands decorated with `@Command` must implement this interface.
11
+ * The `execute` method is called when the command is invoked.
15
12
  *
16
- * This class handles module loading, command registration, and command execution.
17
- * It provides both programmatic and CLI-based command execution capabilities.
13
+ * @template TOptions - The type of options that the command accepts
18
14
  *
19
15
  * @example
20
16
  * ```typescript
21
- * const app = await CommanderFactory.create(AppModule)
22
- * await app.init()
23
- * await app.run(process.argv)
17
+ * import { Command, CommandHandler } from '@navios/commander'
18
+ * import { z } from 'zod'
19
+ *
20
+ * const optionsSchema = z.object({
21
+ * name: z.string()
22
+ * })
23
+ *
24
+ * type Options = z.infer<typeof optionsSchema>
25
+ *
26
+ * @Command({ path: 'greet', optionsSchema })
27
+ * export class GreetCommand implements CommandHandler<Options> {
28
+ * async execute(options: Options) {
29
+ * console.log(`Hello, ${options.name}!`)
30
+ * }
31
+ * }
24
32
  * ```
25
33
  */
26
- declare class CommanderApplication {
27
- private moduleLoader;
28
- private cliParser;
29
- protected container: Container;
30
- private appModule;
31
- private options;
32
- /**
33
- * Indicates whether the application has been initialized.
34
- * Set to `true` after `init()` is called successfully.
35
- */
36
- isInitialized: boolean;
37
- /**
38
- * @internal
39
- * Sets up the application with the provided module and options.
40
- * This is called automatically by CommanderFactory.create().
41
- */
42
- setup(appModule: ClassTypeWithInstance<NaviosModule>, options?: CommanderApplicationOptions): Promise<void>;
34
+ interface CommandHandler<TOptions = any> {
43
35
  /**
44
- * Gets the dependency injection container used by this application.
45
- *
46
- * @returns The Container instance
36
+ * Executes the command with the provided options.
47
37
  *
48
- * @example
49
- * ```typescript
50
- * const container = app.getContainer()
51
- * const service = await container.get(MyService)
52
- * ```
38
+ * @param options - The validated command options (validated against the command's schema if provided)
39
+ * @returns A promise or void
53
40
  */
54
- getContainer(): Container;
41
+ execute(options: TOptions): void | Promise<void>;
42
+ }
43
+ //#endregion
44
+ //#region src/commands/help.command.d.mts
45
+ declare const helpOptionsSchema: z.ZodObject<{
46
+ command: z.ZodOptional<z.ZodString>;
47
+ }, z.core.$strip>;
48
+ type HelpOptions = z.infer<typeof helpOptionsSchema>;
49
+ /**
50
+ * Built-in help command that lists all available commands or shows help for a specific command.
51
+ *
52
+ * @public
53
+ */
54
+ declare class HelpCommand implements CommandHandler<HelpOptions> {
55
+ private logger;
56
+ private commandRegistry;
57
+ execute(options: HelpOptions): Promise<void>;
58
+ }
59
+ //#endregion
60
+ //#region src/interfaces/abstract-cli-adapter.interface.d.mts
61
+ /**
62
+ * Interface for CLI adapters.
63
+ * Extends the base adapter interface with CLI-specific methods.
64
+ *
65
+ * @public
66
+ */
67
+ interface AbstractCliAdapterInterface extends AbstractAdapterInterface {
55
68
  /**
56
- * Initializes the application by loading all modules and registering commands.
69
+ * Run the CLI application with the given arguments.
70
+ * Parses arguments and executes the matching command.
57
71
  *
58
- * This method must be called before executing commands or running the CLI.
59
- * It traverses the module tree, loads all imported modules, and collects command metadata.
60
- *
61
- * @throws {Error} If the app module is not set (setup() was not called)
72
+ * @param argv - Command-line arguments array (defaults to `process.argv`)
62
73
  *
63
74
  * @example
64
75
  * ```typescript
65
- * const app = await CommanderFactory.create(AppModule)
66
- * await app.init() // Must be called before run() or executeCommand()
76
+ * const adapter = app.getAdapter() as AbstractCliAdapterInterface
77
+ * await adapter.run(process.argv)
67
78
  * ```
68
79
  */
69
- init(): Promise<void>;
80
+ run(argv?: string[]): Promise<void>;
70
81
  /**
71
- * Executes a command programmatically with the provided options.
72
- *
73
- * This method is useful for testing, automation, or programmatic workflows.
74
- * The options will be validated against the command's Zod schema if one is provided.
82
+ * Execute a command programmatically with the provided options.
75
83
  *
76
- * @param commandPath - The command path (e.g., 'greet', 'user:create')
77
- * @param options - The command options object (will be validated if schema exists)
78
- * @throws {Error} If the application is not initialized
79
- * @throws {Error} If the command is not found
80
- * @throws {Error} If the command does not implement the execute method
81
- * @throws {ZodError} If options validation fails
84
+ * @param path - The command path (e.g., 'greet', 'user:create')
85
+ * @param options - The command options object
82
86
  *
83
87
  * @example
84
88
  * ```typescript
85
- * await app.executeCommand('greet', {
86
- * name: 'World',
87
- * greeting: 'Hi'
89
+ * await adapter.executeCommand('user:create', {
90
+ * name: 'John',
91
+ * email: 'john@example.com',
88
92
  * })
89
93
  * ```
90
94
  */
91
- executeCommand(commandPath: string, options?: any): Promise<void>;
95
+ executeCommand(path: string, options: Record<string, unknown>): Promise<void>;
92
96
  /**
93
- * Gets all registered commands with their paths and class references.
97
+ * Get all registered command paths and their class references.
94
98
  *
95
- * @returns An array of objects containing the command path and class
99
+ * @returns Array of objects containing path and class
96
100
  *
97
101
  * @example
98
102
  * ```typescript
99
- * const commands = app.getAllCommands()
100
- * commands.forEach(({ path }) => {
101
- * console.log(`Available: ${path}`)
102
- * })
103
+ * const commands = adapter.getAllCommands()
104
+ * commands.forEach(({ path }) => console.log(path))
103
105
  * ```
104
106
  */
105
- getAllCommands(): {
107
+ getAllCommands(): Array<{
106
108
  path: string;
107
- class: ClassTypeWithInstance<any>;
108
- }[];
109
+ class: unknown;
110
+ }>;
111
+ }
112
+ //#endregion
113
+ //#region src/interfaces/environment.interface.d.mts
114
+ /**
115
+ * Options for configuring the CLI adapter.
116
+ *
117
+ * @public
118
+ */
119
+ interface CliAdapterOptions {}
120
+ /**
121
+ * Environment type definition for CLI adapters.
122
+ * Used with NaviosFactory.create<CliEnvironment>() for type-safe CLI applications.
123
+ *
124
+ * @public
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { NaviosFactory } from '@navios/core'
129
+ * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'
130
+ *
131
+ * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {
132
+ * adapter: defineCliEnvironment(),
133
+ * })
134
+ * ```
135
+ */
136
+ interface CliEnvironment extends AdapterEnvironment {
137
+ options: CliAdapterOptions;
138
+ adapter: AbstractCliAdapterInterface;
139
+ }
140
+ //#endregion
141
+ //#region src/commander.factory.d.mts
142
+ /**
143
+ * Logger display options for CLI applications.
144
+ * All options default to false for cleaner CLI output.
145
+ *
146
+ * @public
147
+ */
148
+ interface CommanderLoggerOptions {
109
149
  /**
110
- * Runs the CLI application by parsing command-line arguments and executing the appropriate command.
111
- *
112
- * This is the main entry point for CLI usage. It parses `argv`, validates options,
113
- * and executes the matching command. Supports help command (`help`, `--help`, `-h`)
114
- * which displays all available commands.
115
- *
116
- * @param argv - Command-line arguments array (defaults to `process.argv`)
117
- * @throws {Error} If the application is not initialized
118
- * @throws {Error} If no command is provided
119
- * @throws {Error} If the command is not found
120
- * @throws {ZodError} If options validation fails
121
- *
122
- * @example
123
- * ```typescript
124
- * // Parse and execute from process.argv
125
- * await app.run()
126
- *
127
- * // Or provide custom arguments
128
- * await app.run(['node', 'cli.js', 'greet', '--name', 'World'])
129
- * ```
150
+ * Enabled log levels.
151
+ * @default ['log', 'error', 'warn', 'debug', 'verbose', 'fatal']
130
152
  */
131
- run(argv?: string[]): Promise<void>;
153
+ logLevels?: LogLevel[];
132
154
  /**
133
- * @internal
134
- * Disposes of resources used by the application.
155
+ * If true, will print the process ID in the log message.
156
+ * @default false
135
157
  */
136
- dispose(): Promise<void>;
158
+ showPid?: boolean;
137
159
  /**
138
- * Closes the application and cleans up resources.
139
- *
140
- * This should be called when the application is no longer needed to free up resources.
141
- *
142
- * @example
143
- * ```typescript
144
- * await app.run(process.argv)
145
- * await app.close()
146
- * ```
160
+ * If true, will print the log level in the log message.
161
+ * @default true
147
162
  */
148
- close(): Promise<void>;
163
+ showLogLevel?: boolean;
164
+ /**
165
+ * If true, will print the prefix/app name in the log message.
166
+ * @default false
167
+ */
168
+ showPrefix?: boolean;
169
+ /**
170
+ * If true, will print the context in the log message.
171
+ * @default true
172
+ */
173
+ showContext?: boolean;
174
+ /**
175
+ * If true, will print the absolute timestamp in the log message.
176
+ * @default false
177
+ */
178
+ showTimestamp?: boolean;
179
+ /**
180
+ * If enabled, will print timestamp difference between current and previous log message.
181
+ * @default false
182
+ */
183
+ showTimeDiff?: boolean;
149
184
  }
150
- //#endregion
151
- //#region src/commander.factory.d.mts
152
185
  /**
153
- * Factory class for creating and configuring CLI applications.
186
+ * Configuration options for CommanderFactory.
187
+ *
188
+ * @public
189
+ */
190
+ interface CommanderFactoryOptions {
191
+ /**
192
+ * Logger display options. These override the default CLI-friendly logger settings.
193
+ */
194
+ logger?: CommanderLoggerOptions;
195
+ }
196
+ /**
197
+ * Factory class for creating CLI applications.
198
+ *
199
+ * This is a convenience wrapper around `NaviosFactory.create()` that
200
+ * configures everything needed for CLI usage. It sets up the CLI adapter
201
+ * and returns a typed `NaviosApplication<CliEnvironment>`.
154
202
  *
155
203
  * @example
156
204
  * ```typescript
@@ -160,26 +208,43 @@ declare class CommanderApplication {
160
208
  * async function bootstrap() {
161
209
  * const app = await CommanderFactory.create(AppModule)
162
210
  * await app.init()
163
- * await app.run(process.argv)
211
+ *
212
+ * const adapter = app.getAdapter()
213
+ * await adapter.run(process.argv)
214
+ *
164
215
  * await app.close()
165
216
  * }
166
217
  * ```
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * // Alternative: use NaviosFactory directly
222
+ * import { NaviosFactory } from '@navios/core'
223
+ * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'
224
+ *
225
+ * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {
226
+ * adapter: defineCliEnvironment(),
227
+ * })
228
+ * ```
167
229
  */
168
230
  declare class CommanderFactory {
169
231
  /**
170
- * Creates a new CommanderApplication instance and configures it with the provided module.
232
+ * Creates a new CLI application instance configured with the provided module.
171
233
  *
172
- * @param appModule - The root CLI module class that contains commands and/or imports other modules
173
- * @param options - Optional configuration options for the application
174
- * @returns A promise that resolves to a configured CommanderApplication instance
234
+ * @param appModule - The root CLI module class decorated with `@CliModule`
235
+ * @param options - Optional configuration options for the CLI application
236
+ * @returns A promise that resolves to a configured NaviosApplication instance
175
237
  *
176
238
  * @example
177
239
  * ```typescript
178
240
  * const app = await CommanderFactory.create(AppModule)
179
241
  * await app.init()
242
+ *
243
+ * const adapter = app.getAdapter()
244
+ * await adapter.run(process.argv)
180
245
  * ```
181
246
  */
182
- static create(appModule: ClassTypeWithInstance<NaviosModule>, options?: CommanderApplicationOptions): Promise<CommanderApplication>;
247
+ static create<TModule extends NaviosModule = NaviosModule>(appModule: ClassTypeWithInstance<TModule>, options?: CommanderFactoryOptions): Promise<NaviosApplication<CliEnvironment>>;
183
248
  }
184
249
  //#endregion
185
250
  //#region src/decorators/command.decorator.d.mts
@@ -194,6 +259,11 @@ interface CommandOptions {
194
259
  * Can be a single word (e.g., 'greet') or multi-word with colons (e.g., 'user:create', 'db:migrate').
195
260
  */
196
261
  path: string;
262
+ /**
263
+ * Optional description of the command for help text.
264
+ * Displayed when users run `help` or `--help`.
265
+ */
266
+ description?: string;
197
267
  /**
198
268
  * Optional Zod schema for validating command options.
199
269
  * If provided, options will be validated and parsed according to this schema.
@@ -242,6 +312,7 @@ interface CommandOptions {
242
312
  */
243
313
  declare function Command({
244
314
  path,
315
+ description,
245
316
  optionsSchema,
246
317
  priority,
247
318
  registry
@@ -260,10 +331,27 @@ interface CliModuleOptions {
260
331
  */
261
332
  commands?: ClassType[] | Set<ClassType>;
262
333
  /**
263
- * Array or Set of other CLI modules to import.
264
- * Imported modules' commands will be available in this module.
334
+ * Array or Set of controller classes for HTTP endpoints.
335
+ * Allows mixing HTTP and CLI functionality in the same module.
336
+ */
337
+ controllers?: ClassType[] | Set<ClassType>;
338
+ /**
339
+ * Array or Set of other modules to import.
340
+ * Imported modules' commands and controllers will be available.
265
341
  */
266
342
  imports?: ClassType[] | Set<ClassType>;
343
+ /**
344
+ * Guards to apply to all controllers in this module.
345
+ * Guards are executed in reverse order (last guard first).
346
+ */
347
+ guards?: ClassType[] | Set<ClassType>;
348
+ /**
349
+ * Service override classes to import for side effects.
350
+ * These classes are imported to ensure their @Injectable decorators execute,
351
+ * allowing them to register with the DI system. Overrides should use the same
352
+ * InjectionToken as the original service with a higher priority.
353
+ */
354
+ overrides?: ClassType[] | Set<ClassType>;
267
355
  /**
268
356
  * Priority level for the module.
269
357
  * Higher priority modules will be loaded first.
@@ -278,7 +366,11 @@ interface CliModuleOptions {
278
366
  /**
279
367
  * Decorator that marks a class as a CLI module.
280
368
  *
281
- * Modules organize commands and can import other modules to compose larger CLI applications.
369
+ * This decorator extends the standard @Module decorator, adding support for
370
+ * CLI commands while maintaining full compatibility with HTTP controllers.
371
+ * Modules organize commands and can import other modules to compose larger
372
+ * CLI applications.
373
+ *
282
374
  * The module can optionally implement `NaviosModule` interface for lifecycle hooks.
283
375
  *
284
376
  * @param options - Configuration options for the module
@@ -296,50 +388,80 @@ interface CliModuleOptions {
296
388
  * })
297
389
  * export class AppModule {}
298
390
  * ```
391
+ *
392
+ * @example
393
+ * ```typescript
394
+ * // Mixed HTTP and CLI module
395
+ * @CliModule({
396
+ * controllers: [HealthController],
397
+ * commands: [MigrateCommand],
398
+ * imports: [DatabaseModule],
399
+ * })
400
+ * export class AppModule {}
401
+ * ```
299
402
  */
300
403
  declare function CliModule({
301
404
  commands,
405
+ controllers,
302
406
  imports,
407
+ guards,
408
+ overrides,
303
409
  priority,
304
410
  registry
305
411
  }?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
306
412
  //#endregion
307
- //#region src/interfaces/command-handler.interface.d.mts
413
+ //#region src/services/commander-adapter.service.d.mts
308
414
  /**
309
- * Interface that all command classes must implement.
310
- *
311
- * Commands decorated with `@Command` must implement this interface.
312
- * The `execute` method is called when the command is invoked.
415
+ * CLI adapter service that implements the AbstractCliAdapterInterface.
416
+ * Handles command discovery, registration, parsing, and execution.
313
417
  *
314
- * @template TOptions - The type of options that the command accepts
315
- *
316
- * @example
317
- * ```typescript
318
- * import { Command, CommandHandler } from '@navios/commander'
319
- * import { z } from 'zod'
320
- *
321
- * const optionsSchema = z.object({
322
- * name: z.string()
323
- * })
324
- *
325
- * type Options = z.infer<typeof optionsSchema>
326
- *
327
- * @Command({ path: 'greet', optionsSchema })
328
- * export class GreetCommand implements CommandHandler<Options> {
329
- * async execute(options: Options) {
330
- * console.log(`Hello, ${options.name}!`)
331
- * }
332
- * }
333
- * ```
418
+ * @public
334
419
  */
335
- interface CommandHandler<TOptions = any> {
420
+ declare class CommanderAdapterService implements AbstractCliAdapterInterface {
421
+ private container;
422
+ private commandRegistry;
423
+ private cliParser;
424
+ private logger;
425
+ private options;
426
+ private isReady;
336
427
  /**
337
- * Executes the command with the provided options.
338
- *
339
- * @param options - The validated command options (validated against the command's schema if provided)
340
- * @returns A promise or void
428
+ * Sets up the adapter with the provided options.
429
+ * Called during application initialization.
341
430
  */
342
- execute(options: TOptions): void | Promise<void>;
431
+ setupAdapter(options: CliAdapterOptions): Promise<void>;
432
+ /**
433
+ * Called after all modules are loaded.
434
+ * Iterates through modules and extracts commands from customEntries.
435
+ */
436
+ onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>;
437
+ /**
438
+ * Registers built-in commands like help.
439
+ */
440
+ private registerBuiltInCommands;
441
+ /**
442
+ * Signals that the adapter is ready to handle commands.
443
+ */
444
+ ready(): Promise<void>;
445
+ /**
446
+ * Disposes of the adapter and cleans up resources.
447
+ */
448
+ dispose(): Promise<void>;
449
+ /**
450
+ * Run the CLI application with the given arguments.
451
+ * Parses arguments and executes the matching command.
452
+ */
453
+ run(argv?: string[]): Promise<void>;
454
+ /**
455
+ * Execute a command programmatically with the provided options.
456
+ */
457
+ executeCommand(path: string, options?: Record<string, unknown>): Promise<void>;
458
+ /**
459
+ * Get all registered command paths and their class references.
460
+ */
461
+ getAllCommands(): Array<{
462
+ path: string;
463
+ class: ClassType;
464
+ }>;
343
465
  }
344
466
  //#endregion
345
467
  //#region src/metadata/command.metadata.d.mts
@@ -358,6 +480,10 @@ interface CommandMetadata {
358
480
  * The command path (e.g., 'greet', 'user:create').
359
481
  */
360
482
  path: string;
483
+ /**
484
+ * Optional description of the command for help text.
485
+ */
486
+ description?: string;
361
487
  /**
362
488
  * Optional Zod schema for validating command options.
363
489
  */
@@ -374,10 +500,11 @@ interface CommandMetadata {
374
500
  * @param target - The command class
375
501
  * @param context - The decorator context
376
502
  * @param path - The command path
503
+ * @param description - Optional description for help text
377
504
  * @param optionsSchema - Optional Zod schema
378
505
  * @returns The command metadata
379
506
  */
380
- declare function getCommandMetadata(target: ClassType, context: ClassDecoratorContext, path: string, optionsSchema?: ZodObject): CommandMetadata;
507
+ declare function getCommandMetadata(target: ClassType, context: ClassDecoratorContext, path: string, description?: string, optionsSchema?: ZodObject): CommandMetadata;
381
508
  /**
382
509
  * Extracts command metadata from a class.
383
510
  *
@@ -400,183 +527,123 @@ declare function extractCommandMetadata(target: ClassType): CommandMetadata;
400
527
  */
401
528
  declare function hasCommandMetadata(target: ClassType): boolean;
402
529
  //#endregion
403
- //#region src/interfaces/commander-execution-context.interface.d.mts
404
- /**
405
- * Execution context for a command execution.
406
- *
407
- * Provides access to command metadata, path, and validated options during command execution.
408
- * This context is automatically injected and available via the `CommandExecutionContext` token.
409
- *
410
- * @example
411
- * ```typescript
412
- * import { inject, Injectable } from '@navios/di'
413
- * import { CommandExecutionContext } from '@navios/commander'
414
- *
415
- * @Injectable()
416
- * class CommandLogger {
417
- * private ctx = inject(CommandExecutionContext)
418
- *
419
- * log() {
420
- * console.log('Command:', this.ctx.getCommandPath())
421
- * console.log('Options:', this.ctx.getOptions())
422
- * }
423
- * }
424
- * ```
425
- */
426
- declare class CommanderExecutionContext {
427
- private readonly command;
428
- private readonly commandPath;
429
- private readonly options;
430
- /**
431
- * @internal
432
- * Creates a new execution context.
433
- */
434
- constructor(command: CommandMetadata, commandPath: string, options: any);
435
- /**
436
- * Gets the command metadata.
437
- *
438
- * @returns The command metadata including path and options schema
439
- */
440
- getCommand(): CommandMetadata;
441
- /**
442
- * Gets the command path that was invoked.
443
- *
444
- * @returns The command path (e.g., 'greet', 'user:create')
445
- */
446
- getCommandPath(): string;
447
- /**
448
- * Gets the validated command options.
449
- *
450
- * Options are validated against the command's Zod schema if one was provided.
451
- *
452
- * @returns The validated options object
453
- */
454
- getOptions(): any;
455
- }
456
- //#endregion
457
- //#region src/metadata/cli-module.metadata.d.mts
530
+ //#region src/metadata/command-entry.metadata.d.mts
458
531
  /**
459
- * @internal
460
- * Symbol key used to store CLI module metadata on classes.
461
- */
462
- declare const CliModuleMetadataKey: unique symbol;
463
- /**
464
- * Metadata associated with a CLI module.
532
+ * Symbol key for storing commands in ModuleMetadata.customEntries.
533
+ * Used by @CliModule to store command classes.
465
534
  *
466
535
  * @public
467
536
  */
468
- interface CliModuleMetadata {
469
- /**
470
- * Set of command classes registered in this module.
471
- */
472
- commands: Set<ClassType>;
473
- /**
474
- * Set of other modules imported by this module.
475
- */
476
- imports: Set<ClassType>;
477
- /**
478
- * Map of custom attributes that can be attached to the module.
479
- */
480
- customAttributes: Map<string | symbol, any>;
481
- }
537
+ declare const CommandEntryKey: unique symbol;
482
538
  /**
483
- * Gets or creates CLI module metadata for a class.
539
+ * Type for the command entry value stored in customEntries.
484
540
  *
485
- * @internal
486
- * @param target - The module class
487
- * @param context - The decorator context
488
- * @returns The module metadata
541
+ * @public
489
542
  */
490
- declare function getCliModuleMetadata(target: ClassType, context: ClassDecoratorContext): CliModuleMetadata;
543
+ type CommandEntryValue = Set<ClassType>;
491
544
  /**
492
- * Extracts CLI module metadata from a class.
545
+ * Extracts commands from a module's metadata.
546
+ * Returns empty set if no commands are defined.
493
547
  *
494
- * @param target - The module class
495
- * @returns The module metadata
496
- * @throws {Error} If the class is not decorated with @CliModule
548
+ * @param moduleClass - The module class decorated with @CliModule or @Module
549
+ * @returns Set of command classes registered in the module
497
550
  *
498
551
  * @example
499
552
  * ```typescript
500
- * const metadata = extractCliModuleMetadata(AppModule)
501
- * console.log(metadata.commands.size) // Number of commands
553
+ * const commands = extractModuleCommands(AppModule)
554
+ * for (const command of commands) {
555
+ * console.log(command.name)
556
+ * }
502
557
  * ```
503
558
  */
504
- declare function extractCliModuleMetadata(target: ClassType): CliModuleMetadata;
505
- /**
506
- * Checks if a class has CLI module metadata.
507
- *
508
- * @param target - The class to check
509
- * @returns `true` if the class is decorated with @CliModule, `false` otherwise
510
- */
511
- declare function hasCliModuleMetadata(target: ClassType): boolean;
559
+ declare function extractModuleCommands(moduleClass: ClassType): Set<ClassType>;
512
560
  //#endregion
513
- //#region src/services/module-loader.service.d.mts
561
+ //#region src/services/command-registry.service.d.mts
514
562
  /**
515
- * Command class with its associated metadata.
563
+ * Represents a registered command with its metadata and module information.
516
564
  *
517
565
  * @public
518
566
  */
519
- interface CommandWithMetadata {
567
+ interface RegisteredCommand {
520
568
  /**
521
- * The command class constructor.
569
+ * The command class
522
570
  */
523
- class: ClassTypeWithInstance<CommandHandler>;
571
+ class: ClassType;
524
572
  /**
525
- * The command metadata including path and options schema.
573
+ * The command metadata from @Command decorator
526
574
  */
527
575
  metadata: CommandMetadata;
576
+ /**
577
+ * Name of the module this command belongs to
578
+ */
579
+ moduleName: string;
528
580
  }
529
581
  /**
530
- * Service for loading and managing CLI modules and commands.
531
- *
532
- * Handles module traversal, command registration, and metadata collection.
533
- * This service is used internally by CommanderApplication.
582
+ * Service for registering and looking up CLI commands.
583
+ * Used internally by the CLI adapter to manage discovered commands.
534
584
  *
535
585
  * @public
536
586
  */
537
- declare class CliModuleLoaderService {
538
- protected container: Container;
539
- private modulesMetadata;
540
- private loadedModules;
541
- private commandsMetadata;
542
- private initialized;
543
- /**
544
- * Loads all modules starting from the root app module.
587
+ declare class CommandRegistryService {
588
+ private commands;
589
+ /**
590
+ * Register a command with its metadata.
545
591
  *
546
- * Traverses the module tree, loads imported modules, and collects command metadata.
592
+ * @param path - The command path (e.g., 'greet', 'user:create')
593
+ * @param command - The registered command data
594
+ * @throws Error if a command with the same path is already registered
595
+ */
596
+ register(path: string, command: RegisteredCommand): void;
597
+ /**
598
+ * Get a command by its path.
547
599
  *
548
- * @param appModule - The root CLI module
600
+ * @param path - The command path
601
+ * @returns The registered command or undefined if not found
549
602
  */
550
- loadModules(appModule: ClassTypeWithInstance<NaviosModule>): Promise<void>;
551
- private traverseModules;
552
- private mergeMetadata;
603
+ getByPath(path: string): RegisteredCommand | undefined;
553
604
  /**
554
- * Gets all loaded module metadata.
605
+ * Get all registered commands.
555
606
  *
556
- * @returns Map of module names to their metadata
607
+ * @returns Map of path to registered command
557
608
  */
558
- getAllModules(): Map<string, CliModuleMetadata>;
609
+ getAll(): Map<string, RegisteredCommand>;
559
610
  /**
560
- * Gets all command classes indexed by command class name.
611
+ * Get all registered commands as an array of path and class pairs.
612
+ * Useful for listing available commands.
561
613
  *
562
- * @returns Map of command class names to command classes
614
+ * @returns Array of objects containing path and class
563
615
  */
564
- getAllCommands(): Map<string, ClassTypeWithInstance<any>>;
616
+ getAllAsArray(): Array<{
617
+ path: string;
618
+ class: ClassType;
619
+ }>;
565
620
  /**
566
- * Get all commands with their metadata, indexed by command path.
567
- * This is populated during loadModules, so path information is available
568
- * before parsing CLI argv.
621
+ * Formats help text listing all available commands with descriptions.
622
+ *
623
+ * @returns Formatted string listing all commands
569
624
  */
570
- getAllCommandsWithMetadata(): Map<string, CommandWithMetadata>;
625
+ formatCommandList(): string;
571
626
  /**
572
- * Get a command by its path, with metadata already extracted.
573
- * Returns undefined if command is not found.
627
+ * Formats help text for a specific command.
628
+ *
629
+ * @param commandPath - The command path to show help for
630
+ * @returns Formatted string with command help
574
631
  */
575
- getCommandByPath(path: string): CommandWithMetadata | undefined;
632
+ formatCommandHelp(commandPath: string): string;
576
633
  /**
577
- * Disposes of all loaded modules and commands, clearing internal state.
634
+ * Gets a human-readable type name from a Zod schema.
578
635
  */
579
- dispose(): void;
636
+ private getSchemaTypeName;
637
+ /**
638
+ * Gets metadata from a Zod schema, traversing innerType if needed.
639
+ * Zod v4 stores meta at the outermost layer when .meta() is called last,
640
+ * or in innerType when .meta() is called before .optional()/.default().
641
+ */
642
+ private getSchemaMeta;
643
+ /**
644
+ * Clear all registered commands.
645
+ */
646
+ clear(): void;
580
647
  }
581
648
  //#endregion
582
649
  //#region src/services/cli-parser.service.d.mts
@@ -644,24 +711,95 @@ declare class CliParserService {
644
711
  private extractArrayFields;
645
712
  /**
646
713
  * Checks if a Zod schema represents a boolean type
647
- * Unwraps ZodOptional and ZodDefault
714
+ * Unwraps ZodOptional and ZodDefault using Zod v4 API
648
715
  */
649
716
  private isSchemaBoolean;
650
717
  /**
651
718
  * Checks if a Zod schema represents an array type
652
- * Unwraps ZodOptional and ZodDefault
719
+ * Unwraps ZodOptional and ZodDefault using Zod v4 API
653
720
  */
654
721
  private isSchemaArray;
722
+ }
723
+ //#endregion
724
+ //#region src/define-environment.d.mts
725
+ /**
726
+ * Defines the CLI environment configuration for use with NaviosFactory.
727
+ *
728
+ * This function returns the token mappings needed to configure a CLI application.
729
+ * Use it with `NaviosFactory.create()` to create a CLI application.
730
+ *
731
+ * @returns Environment configuration with token mappings
732
+ *
733
+ * @example
734
+ * ```typescript
735
+ * import { NaviosFactory } from '@navios/core'
736
+ * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'
737
+ *
738
+ * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {
739
+ * adapter: defineCliEnvironment(),
740
+ * })
741
+ * await app.init()
742
+ *
743
+ * const adapter = app.getAdapter() as AbstractCliAdapterInterface
744
+ * await adapter.run(process.argv)
745
+ * ```
746
+ */
747
+ declare function defineCliEnvironment(): {
748
+ tokens: Map<InjectionToken<any, undefined, false>, AnyInjectableType>;
749
+ };
750
+ //#endregion
751
+ //#region src/interfaces/commander-execution-context.interface.d.mts
752
+ /**
753
+ * Execution context for a command execution.
754
+ *
755
+ * Provides access to command metadata, path, and validated options during command execution.
756
+ * This context is automatically injected and available via the `CommandExecutionContext` token.
757
+ *
758
+ * @example
759
+ * ```typescript
760
+ * import { inject, Injectable } from '@navios/core'
761
+ * import { CommandExecutionContext } from '@navios/commander'
762
+ *
763
+ * @Injectable()
764
+ * class CommandLogger {
765
+ * private ctx = inject(CommandExecutionContext)
766
+ *
767
+ * log() {
768
+ * console.log('Command:', this.ctx.getCommandPath())
769
+ * console.log('Options:', this.ctx.getOptions())
770
+ * }
771
+ * }
772
+ * ```
773
+ */
774
+ declare class CommanderExecutionContext {
775
+ private readonly command;
776
+ private readonly commandPath;
777
+ private readonly options;
655
778
  /**
656
- * Formats help text listing all available commands.
779
+ * @internal
780
+ * Creates a new execution context.
781
+ */
782
+ constructor(command: CommandMetadata, commandPath: string, options: any);
783
+ /**
784
+ * Gets the command metadata.
657
785
  *
658
- * @param commands - Array of command objects with path and class
659
- * @returns Formatted string listing all commands
786
+ * @returns The command metadata including path and options schema
660
787
  */
661
- formatCommandList(commands: Array<{
662
- path: string;
663
- class: any;
664
- }>): string;
788
+ getCommand(): CommandMetadata;
789
+ /**
790
+ * Gets the command path that was invoked.
791
+ *
792
+ * @returns The command path (e.g., 'greet', 'user:create')
793
+ */
794
+ getCommandPath(): string;
795
+ /**
796
+ * Gets the validated command options.
797
+ *
798
+ * Options are validated against the command's Zod schema if one was provided.
799
+ *
800
+ * @returns The validated options object
801
+ */
802
+ getOptions(): any;
665
803
  }
666
804
  //#endregion
667
805
  //#region src/tokens/execution-context.token.d.mts
@@ -673,7 +811,7 @@ declare class CliParserService {
673
811
  *
674
812
  * @example
675
813
  * ```typescript
676
- * import { inject, Injectable } from '@navios/di'
814
+ * import { inject, Injectable } from '@navios/core'
677
815
  * import { CommandExecutionContext } from '@navios/commander'
678
816
  *
679
817
  * @Injectable()
@@ -690,5 +828,5 @@ declare class CliParserService {
690
828
  */
691
829
  declare const CommandExecutionContext: InjectionToken<CommanderExecutionContext, undefined, false>;
692
830
  //#endregion
693
- export { CliModule, CliModuleLoaderService, CliModuleMetadata, CliModuleMetadataKey, CliModuleOptions, CliParserService, Command, CommandExecutionContext, CommandHandler, CommandMetadata, CommandMetadataKey, CommandOptions, CommandWithMetadata, CommanderApplication, CommanderApplicationOptions, CommanderExecutionContext, CommanderFactory, ParsedCliArgs, extractCliModuleMetadata, extractCommandMetadata, getCliModuleMetadata, getCommandMetadata, hasCliModuleMetadata, hasCommandMetadata };
831
+ export { AbstractCliAdapterInterface, CliAdapterOptions, CliEnvironment, CliModule, CliModuleOptions, CliParserService, Command, CommandEntryKey, CommandEntryValue, CommandExecutionContext, CommandHandler, CommandMetadata, CommandMetadataKey, CommandOptions, CommandRegistryService, CommanderAdapterService, CommanderExecutionContext, CommanderFactory, CommanderFactoryOptions, CommanderLoggerOptions, HelpCommand, ParsedCliArgs, RegisteredCommand, defineCliEnvironment, extractCommandMetadata, extractModuleCommands, getCommandMetadata, hasCommandMetadata };
694
832
  //# sourceMappingURL=index.d.cts.map