@navios/commander 1.0.0-alpha.2 → 1.0.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +42 -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 +29 -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/command-entry.metadata.d.mts +31 -0
  25. package/dist/src/metadata/command-entry.metadata.d.mts.map +1 -0
  26. package/dist/src/metadata/command.metadata.d.mts +6 -1
  27. package/dist/src/metadata/command.metadata.d.mts.map +1 -1
  28. package/dist/src/metadata/index.d.mts +1 -1
  29. package/dist/src/metadata/index.d.mts.map +1 -1
  30. package/dist/src/services/cli-parser.service.d.mts +2 -12
  31. package/dist/src/services/cli-parser.service.d.mts.map +1 -1
  32. package/dist/src/services/command-registry.service.d.mts +89 -0
  33. package/dist/src/services/command-registry.service.d.mts.map +1 -0
  34. package/dist/src/services/commander-adapter.service.d.mts +56 -0
  35. package/dist/src/services/commander-adapter.service.d.mts.map +1 -0
  36. package/dist/src/services/index.d.mts +2 -1
  37. package/dist/src/services/index.d.mts.map +1 -1
  38. package/dist/src/tokens/execution-context.token.d.mts +1 -1
  39. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  40. package/dist/tsconfig.tsbuildinfo +1 -1
  41. package/lib/index.cjs +536 -8513
  42. package/lib/index.cjs.map +1 -1
  43. package/lib/index.d.cts +422 -298
  44. package/lib/index.d.cts.map +1 -1
  45. package/lib/index.d.mts +422 -298
  46. package/lib/index.d.mts.map +1 -1
  47. package/lib/index.mjs +502 -8284
  48. package/lib/index.mjs.map +1 -1
  49. package/package.json +2 -2
  50. package/src/__tests__/commander.factory.e2e.spec.mts +258 -68
  51. package/src/commander.factory.mts +109 -17
  52. package/src/commands/help.command.mts +37 -0
  53. package/src/commands/index.mts +1 -0
  54. package/src/decorators/cli-module.decorator.mts +58 -20
  55. package/src/decorators/command.decorator.mts +7 -1
  56. package/src/define-environment.mts +39 -0
  57. package/src/index.mts +2 -1
  58. package/src/interfaces/abstract-cli-adapter.interface.mts +52 -0
  59. package/src/interfaces/commander-execution-context.interface.mts +1 -1
  60. package/src/interfaces/environment.interface.mts +34 -0
  61. package/src/interfaces/index.mts +2 -0
  62. package/src/metadata/command-entry.metadata.mts +41 -0
  63. package/src/metadata/command.metadata.mts +7 -0
  64. package/src/metadata/index.mts +1 -1
  65. package/src/services/cli-parser.service.mts +14 -28
  66. package/src/services/command-registry.service.mts +217 -0
  67. package/src/services/commander-adapter.service.mts +209 -0
  68. package/src/services/index.mts +2 -1
  69. package/src/tokens/execution-context.token.mts +1 -1
  70. package/tsconfig.json +1 -1
  71. package/src/commander.application.mts +0 -303
  72. package/src/metadata/cli-module.metadata.mts +0 -100
  73. package/src/services/module-loader.service.mts +0 -231
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,20 @@ 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>;
267
348
  /**
268
349
  * Service override classes to import for side effects.
269
350
  * These classes are imported to ensure their @Injectable decorators execute,
@@ -285,7 +366,11 @@ interface CliModuleOptions {
285
366
  /**
286
367
  * Decorator that marks a class as a CLI module.
287
368
  *
288
- * 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
+ *
289
374
  * The module can optionally implement `NaviosModule` interface for lifecycle hooks.
290
375
  *
291
376
  * @param options - Configuration options for the module
@@ -303,51 +388,80 @@ interface CliModuleOptions {
303
388
  * })
304
389
  * export class AppModule {}
305
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
+ * ```
306
402
  */
307
403
  declare function CliModule({
308
404
  commands,
405
+ controllers,
309
406
  imports,
407
+ guards,
310
408
  overrides,
311
409
  priority,
312
410
  registry
313
411
  }?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
314
412
  //#endregion
315
- //#region src/interfaces/command-handler.interface.d.mts
413
+ //#region src/services/commander-adapter.service.d.mts
316
414
  /**
317
- * Interface that all command classes must implement.
415
+ * CLI adapter service that implements the AbstractCliAdapterInterface.
416
+ * Handles command discovery, registration, parsing, and execution.
318
417
  *
319
- * Commands decorated with `@Command` must implement this interface.
320
- * The `execute` method is called when the command is invoked.
321
- *
322
- * @template TOptions - The type of options that the command accepts
323
- *
324
- * @example
325
- * ```typescript
326
- * import { Command, CommandHandler } from '@navios/commander'
327
- * import { z } from 'zod'
328
- *
329
- * const optionsSchema = z.object({
330
- * name: z.string()
331
- * })
332
- *
333
- * type Options = z.infer<typeof optionsSchema>
334
- *
335
- * @Command({ path: 'greet', optionsSchema })
336
- * export class GreetCommand implements CommandHandler<Options> {
337
- * async execute(options: Options) {
338
- * console.log(`Hello, ${options.name}!`)
339
- * }
340
- * }
341
- * ```
418
+ * @public
342
419
  */
343
- 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;
344
427
  /**
345
- * Executes the command with the provided options.
346
- *
347
- * @param options - The validated command options (validated against the command's schema if provided)
348
- * @returns A promise or void
428
+ * Sets up the adapter with the provided options.
429
+ * Called during application initialization.
349
430
  */
350
- 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
+ }>;
351
465
  }
352
466
  //#endregion
353
467
  //#region src/metadata/command.metadata.d.mts
@@ -366,6 +480,10 @@ interface CommandMetadata {
366
480
  * The command path (e.g., 'greet', 'user:create').
367
481
  */
368
482
  path: string;
483
+ /**
484
+ * Optional description of the command for help text.
485
+ */
486
+ description?: string;
369
487
  /**
370
488
  * Optional Zod schema for validating command options.
371
489
  */
@@ -382,10 +500,11 @@ interface CommandMetadata {
382
500
  * @param target - The command class
383
501
  * @param context - The decorator context
384
502
  * @param path - The command path
503
+ * @param description - Optional description for help text
385
504
  * @param optionsSchema - Optional Zod schema
386
505
  * @returns The command metadata
387
506
  */
388
- 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;
389
508
  /**
390
509
  * Extracts command metadata from a class.
391
510
  *
@@ -408,189 +527,123 @@ declare function extractCommandMetadata(target: ClassType): CommandMetadata;
408
527
  */
409
528
  declare function hasCommandMetadata(target: ClassType): boolean;
410
529
  //#endregion
411
- //#region src/interfaces/commander-execution-context.interface.d.mts
530
+ //#region src/metadata/command-entry.metadata.d.mts
412
531
  /**
413
- * Execution context for a command execution.
414
- *
415
- * Provides access to command metadata, path, and validated options during command execution.
416
- * This context is automatically injected and available via the `CommandExecutionContext` token.
417
- *
418
- * @example
419
- * ```typescript
420
- * import { inject, Injectable } from '@navios/di'
421
- * import { CommandExecutionContext } from '@navios/commander'
422
- *
423
- * @Injectable()
424
- * class CommandLogger {
425
- * private ctx = inject(CommandExecutionContext)
426
- *
427
- * log() {
428
- * console.log('Command:', this.ctx.getCommandPath())
429
- * console.log('Options:', this.ctx.getOptions())
430
- * }
431
- * }
432
- * ```
433
- */
434
- declare class CommanderExecutionContext {
435
- private readonly command;
436
- private readonly commandPath;
437
- private readonly options;
438
- /**
439
- * @internal
440
- * Creates a new execution context.
441
- */
442
- constructor(command: CommandMetadata, commandPath: string, options: any);
443
- /**
444
- * Gets the command metadata.
445
- *
446
- * @returns The command metadata including path and options schema
447
- */
448
- getCommand(): CommandMetadata;
449
- /**
450
- * Gets the command path that was invoked.
451
- *
452
- * @returns The command path (e.g., 'greet', 'user:create')
453
- */
454
- getCommandPath(): string;
455
- /**
456
- * Gets the validated command options.
457
- *
458
- * Options are validated against the command's Zod schema if one was provided.
459
- *
460
- * @returns The validated options object
461
- */
462
- getOptions(): any;
463
- }
464
- //#endregion
465
- //#region src/metadata/cli-module.metadata.d.mts
466
- /**
467
- * @internal
468
- * Symbol key used to store CLI module metadata on classes.
469
- */
470
- declare const CliModuleMetadataKey: unique symbol;
471
- /**
472
- * Metadata associated with a CLI module.
532
+ * Symbol key for storing commands in ModuleMetadata.customEntries.
533
+ * Used by @CliModule to store command classes.
473
534
  *
474
535
  * @public
475
536
  */
476
- interface CliModuleMetadata {
477
- /**
478
- * Set of command classes registered in this module.
479
- */
480
- commands: Set<ClassType>;
481
- /**
482
- * Set of other modules imported by this module.
483
- */
484
- imports: Set<ClassType>;
485
- /**
486
- * Set of service override classes imported for side effects.
487
- */
488
- overrides: Set<ClassType>;
489
- /**
490
- * Map of custom attributes that can be attached to the module.
491
- */
492
- customAttributes: Map<string | symbol, any>;
493
- }
537
+ declare const CommandEntryKey: unique symbol;
494
538
  /**
495
- * Gets or creates CLI module metadata for a class.
539
+ * Type for the command entry value stored in customEntries.
496
540
  *
497
- * @internal
498
- * @param target - The module class
499
- * @param context - The decorator context
500
- * @returns The module metadata
541
+ * @public
501
542
  */
502
- declare function getCliModuleMetadata(target: ClassType, context: ClassDecoratorContext): CliModuleMetadata;
543
+ type CommandEntryValue = Set<ClassType>;
503
544
  /**
504
- * Extracts CLI module metadata from a class.
545
+ * Extracts commands from a module's metadata.
546
+ * Returns empty set if no commands are defined.
505
547
  *
506
- * @param target - The module class
507
- * @returns The module metadata
508
- * @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
509
550
  *
510
551
  * @example
511
552
  * ```typescript
512
- * const metadata = extractCliModuleMetadata(AppModule)
513
- * 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
+ * }
514
557
  * ```
515
558
  */
516
- declare function extractCliModuleMetadata(target: ClassType): CliModuleMetadata;
517
- /**
518
- * Checks if a class has CLI module metadata.
519
- *
520
- * @param target - The class to check
521
- * @returns `true` if the class is decorated with @CliModule, `false` otherwise
522
- */
523
- declare function hasCliModuleMetadata(target: ClassType): boolean;
559
+ declare function extractModuleCommands(moduleClass: ClassType): Set<ClassType>;
524
560
  //#endregion
525
- //#region src/services/module-loader.service.d.mts
561
+ //#region src/services/command-registry.service.d.mts
526
562
  /**
527
- * Command class with its associated metadata.
563
+ * Represents a registered command with its metadata and module information.
528
564
  *
529
565
  * @public
530
566
  */
531
- interface CommandWithMetadata {
567
+ interface RegisteredCommand {
532
568
  /**
533
- * The command class constructor.
569
+ * The command class
534
570
  */
535
- class: ClassTypeWithInstance<CommandHandler>;
571
+ class: ClassType;
536
572
  /**
537
- * The command metadata including path and options schema.
573
+ * The command metadata from @Command decorator
538
574
  */
539
575
  metadata: CommandMetadata;
576
+ /**
577
+ * Name of the module this command belongs to
578
+ */
579
+ moduleName: string;
540
580
  }
541
581
  /**
542
- * Service for loading and managing CLI modules and commands.
543
- *
544
- * Handles module traversal, command registration, and metadata collection.
545
- * 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.
546
584
  *
547
585
  * @public
548
586
  */
549
- declare class CliModuleLoaderService {
550
- private logger;
551
- protected container: Container;
552
- private modulesMetadata;
553
- private loadedModules;
554
- private commandsMetadata;
555
- private initialized;
587
+ declare class CommandRegistryService {
588
+ private commands;
556
589
  /**
557
- * Loads all modules starting from the root app module.
590
+ * Register a command with its metadata.
558
591
  *
559
- * 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.
560
599
  *
561
- * @param appModule - The root CLI module
600
+ * @param path - The command path
601
+ * @returns The registered command or undefined if not found
562
602
  */
563
- loadModules(appModule: ClassTypeWithInstance<NaviosModule>): Promise<void>;
564
- private traverseModules;
565
- private validateOverrides;
566
- private mergeMetadata;
603
+ getByPath(path: string): RegisteredCommand | undefined;
567
604
  /**
568
- * Gets all loaded module metadata.
605
+ * Get all registered commands.
569
606
  *
570
- * @returns Map of module names to their metadata
607
+ * @returns Map of path to registered command
571
608
  */
572
- getAllModules(): Map<string, CliModuleMetadata>;
609
+ getAll(): Map<string, RegisteredCommand>;
573
610
  /**
574
- * 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.
575
613
  *
576
- * @returns Map of command class names to command classes
614
+ * @returns Array of objects containing path and class
577
615
  */
578
- getAllCommands(): Map<string, ClassTypeWithInstance<any>>;
616
+ getAllAsArray(): Array<{
617
+ path: string;
618
+ class: ClassType;
619
+ }>;
579
620
  /**
580
- * Get all commands with their metadata, indexed by command path.
581
- * This is populated during loadModules, so path information is available
582
- * before parsing CLI argv.
621
+ * Formats help text listing all available commands with descriptions.
622
+ *
623
+ * @returns Formatted string listing all commands
583
624
  */
584
- getAllCommandsWithMetadata(): Map<string, CommandWithMetadata>;
625
+ formatCommandList(): string;
585
626
  /**
586
- * Get a command by its path, with metadata already extracted.
587
- * 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
588
631
  */
589
- getCommandByPath(path: string): CommandWithMetadata | undefined;
632
+ formatCommandHelp(commandPath: string): string;
590
633
  /**
591
- * Disposes of all loaded modules and commands, clearing internal state.
634
+ * Gets a human-readable type name from a Zod schema.
592
635
  */
593
- 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;
594
647
  }
595
648
  //#endregion
596
649
  //#region src/services/cli-parser.service.d.mts
@@ -658,24 +711,95 @@ declare class CliParserService {
658
711
  private extractArrayFields;
659
712
  /**
660
713
  * Checks if a Zod schema represents a boolean type
661
- * Unwraps ZodOptional and ZodDefault
714
+ * Unwraps ZodOptional and ZodDefault using Zod v4 API
662
715
  */
663
716
  private isSchemaBoolean;
664
717
  /**
665
718
  * Checks if a Zod schema represents an array type
666
- * Unwraps ZodOptional and ZodDefault
719
+ * Unwraps ZodOptional and ZodDefault using Zod v4 API
667
720
  */
668
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;
669
778
  /**
670
- * 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.
671
785
  *
672
- * @param commands - Array of command objects with path and class
673
- * @returns Formatted string listing all commands
786
+ * @returns The command metadata including path and options schema
674
787
  */
675
- formatCommandList(commands: Array<{
676
- path: string;
677
- class: any;
678
- }>): 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;
679
803
  }
680
804
  //#endregion
681
805
  //#region src/tokens/execution-context.token.d.mts
@@ -687,7 +811,7 @@ declare class CliParserService {
687
811
  *
688
812
  * @example
689
813
  * ```typescript
690
- * import { inject, Injectable } from '@navios/di'
814
+ * import { inject, Injectable } from '@navios/core'
691
815
  * import { CommandExecutionContext } from '@navios/commander'
692
816
  *
693
817
  * @Injectable()
@@ -704,5 +828,5 @@ declare class CliParserService {
704
828
  */
705
829
  declare const CommandExecutionContext: InjectionToken<CommanderExecutionContext, undefined, false>;
706
830
  //#endregion
707
- 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 };
708
832
  //# sourceMappingURL=index.d.cts.map