@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/CHANGELOG.md CHANGED
@@ -5,6 +5,79 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.0-alpha.4] - 2026-01-09
9
+
10
+ ### Added
11
+
12
+ - **Unified Adapter Architecture**: Commander now uses the unified adapter system from `@navios/core`
13
+ - `CommanderAdapterService` implements `AbstractCliAdapterInterface` with standard lifecycle methods
14
+ - `AbstractCliAdapterInterface` extends `AbstractAdapterInterface` with CLI-specific methods (`run`, `executeCommand`, `getAllCommands`)
15
+ - `CliEnvironment` interface for type-safe CLI configuration
16
+ - `defineCommanderEnvironment()` function for creating CLI adapter environments
17
+ - **Command Description Support**: Commands now support `description` property for help text
18
+ - `@Command({ path: 'greet', description: 'Greet a user' })`
19
+ - Descriptions displayed in `--help` output
20
+ - **Built-in Help Command**: Automatic `help` command with `--help` flag support
21
+ - Shows all available commands with descriptions
22
+ - Per-command help with option details from Zod schema metadata
23
+ - Supports `.meta({ description: '...' })` on Zod fields for option descriptions
24
+ - **Command Registry Service**: New `CommandRegistryService` for managing registered commands
25
+ - Replaces module-level command tracking
26
+ - Provides `register()`, `getByPath()`, `getAllAsArray()`, and `clear()` methods
27
+ - **Module Custom Entries**: Commands are now registered via `customEntries` in module metadata
28
+ - `@CliModule({ commands: [...] })` stores commands in `customEntries` Map
29
+ - Adapter discovers commands via `CommandEntryKey` in module metadata
30
+
31
+ ### Changed
32
+
33
+ - **Factory Returns NaviosApplication**: `CommanderFactory.create()` now returns `NaviosApplication` instead of `CommanderApplication`
34
+ - Use `app.getAdapter()` to access CLI-specific methods
35
+ - Aligns with HTTP adapter pattern for consistency
36
+ - **CLI Module Decorator**: `@CliModule()` now extends `@Module()` with command registration
37
+ - Commands are added to `customEntries` instead of separate metadata
38
+ - Module imports and providers work the same as `@Module()`
39
+ - **Command Decorator**: Now stores metadata using standard Navios metadata system
40
+ - Metadata includes `description` field for help text
41
+ - **Application Lifecycle**: Uses standard `NaviosApplication` lifecycle
42
+ - `app.init()` initializes modules and adapter
43
+ - `app.getAdapter().run()` executes CLI commands
44
+ - `app.close()` disposes resources
45
+
46
+ ### Removed
47
+
48
+ - **CommanderApplication Class**: Replaced by `NaviosApplication` with CLI adapter
49
+ - **CliModuleLoaderService**: Replaced by `CommanderAdapterService.onModulesInit()`
50
+ - **CliModuleMetadata**: Module metadata now uses standard `ModuleMetadata` with `customEntries`
51
+
52
+ ### Breaking Changes
53
+
54
+ - **Factory Return Type**: `CommanderFactory.create()` returns `NaviosApplication` instead of `CommanderApplication`
55
+ - Before: `const app = await CommanderFactory.create(AppModule); await app.run()`
56
+ - After: `const app = await CommanderFactory.create(AppModule); await app.init(); await app.getAdapter().run()`
57
+ - **Method Access**: CLI methods accessed via `app.getAdapter()` instead of directly on app
58
+ - Before: `app.executeCommand('greet', opts)`
59
+ - After: `app.getAdapter().executeCommand('greet', opts)`
60
+ - **Module Decorator**: `@CliModule()` decorator signature unchanged but internal metadata format changed
61
+
62
+ ### Dependencies
63
+
64
+ - Updated to support `@navios/core` ^1.0.0-alpha.4
65
+
66
+ ## [1.0.0-alpha.2] - 2026-01-07
67
+
68
+ ### Added
69
+
70
+ - **Module Overrides**: New `overrides` option in `@CliModule()` decorator for service override classes
71
+ - Service override classes are imported for side effects to ensure their `@Injectable` decorators execute
72
+ - Overrides should use the same `InjectionToken` as the original service with a higher priority
73
+ - `CliModuleLoaderService` validates overrides and logs warnings if override is not active or not registered
74
+ - Mirrors the same functionality as `@Module()` in `@navios/core`
75
+ - **Logger Integration**: `CliModuleLoaderService` now uses the `Logger` service for consistent logging
76
+
77
+ ### Dependencies
78
+
79
+ - Updated to support `@navios/core` ^1.0.0-alpha.2
80
+
8
81
  ## [0.9.0] - 2025-12-23
9
82
 
10
83
  ### Dependencies
package/README.md CHANGED
@@ -1,19 +1,20 @@
1
1
  # @navios/commander
2
2
 
3
- A CLI command framework built on `@navios/di` that provides a decorator-based approach to building command-line applications, similar to how `@navios/core` works for HTTP applications.
3
+ A CLI command framework built on `@navios/core` that provides a decorator-based approach to building command-line applications. It uses the same patterns and architecture as Navios HTTP applications, making it easy to share code and services between your CLI tools and web servers.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @navios/commander @navios/di zod
8
+ npm install @navios/commander zod
9
9
  ```
10
10
 
11
11
  ## Features
12
12
 
13
13
  - **Decorator-based**: Use `@Command` and `@CliModule` decorators to define commands and modules
14
- - **Dependency Injection**: Full integration with `@navios/di`
14
+ - **Dependency Injection**: Full DI support via `@navios/core` with request-scoped command execution
15
15
  - **Schema Validation**: Built-in support for Zod schemas to validate command options
16
16
  - **Modular Architecture**: Organize commands into modules with imports support
17
+ - **Built-in Help**: Automatic `help` command and `--help` flag support with Zod meta descriptions
17
18
 
18
19
  ## Usage
19
20
 
@@ -27,14 +28,15 @@ import { Command, CommandHandler } from '@navios/commander'
27
28
  import { z } from 'zod'
28
29
 
29
30
  const greetOptionsSchema = z.object({
30
- name: z.string(),
31
- greeting: z.string().optional().default('Hello'),
31
+ name: z.string().meta({ description: 'Name of the person to greet' }),
32
+ greeting: z.string().optional().default('Hello').meta({ description: 'Greeting message' }),
32
33
  })
33
34
 
34
35
  type GreetOptions = z.infer<typeof greetOptionsSchema>
35
36
 
36
37
  @Command({
37
38
  path: 'greet',
39
+ description: 'Greet a user with a custom message',
38
40
  optionsSchema: greetOptionsSchema,
39
41
  })
40
42
  export class GreetCommand implements CommandHandler<GreetOptions> {
@@ -55,6 +57,8 @@ import { GreetCommand } from './greet.command'
55
57
 
56
58
  @CliModule({
57
59
  commands: [GreetCommand],
60
+ // Optional: overrides for service implementations with higher priority
61
+ // overrides: [OverrideService],
58
62
  })
59
63
  export class AppModule {}
60
64
  ```
@@ -72,8 +76,9 @@ async function bootstrap() {
72
76
  const app = await CommanderFactory.create(AppModule)
73
77
  await app.init()
74
78
 
75
- // Run with command-line arguments
76
- await app.run(process.argv)
79
+ // Get the adapter and run with command-line arguments
80
+ const adapter = app.getAdapter()
81
+ await adapter.run(process.argv)
77
82
 
78
83
  await app.close()
79
84
  }
@@ -90,8 +95,13 @@ node dist/cli.js greet --name World --greeting Hi
90
95
  ### Advanced Example with Dependency Injection
91
96
 
92
97
  ```typescript
93
- import { CliModule, Command, CommandHandler } from '@navios/commander'
94
- import { inject, Injectable } from '@navios/di'
98
+ import {
99
+ CliModule,
100
+ Command,
101
+ CommandHandler,
102
+ inject,
103
+ Injectable,
104
+ } from '@navios/commander'
95
105
 
96
106
  import { z } from 'zod'
97
107
 
@@ -140,8 +150,13 @@ export class AppModule {}
140
150
  The `ExecutionContext` provides access to the current command execution information, including the module metadata, command metadata, command path, and options. This is useful for middleware, guards, or any service that needs context about the current command execution.
141
151
 
142
152
  ```typescript
143
- import { Command, CommandHandler, CommandExecutionContext } from '@navios/commander'
144
- import { inject, Injectable } from '@navios/di'
153
+ import {
154
+ Command,
155
+ CommandExecutionContext,
156
+ CommandHandler,
157
+ inject,
158
+ Injectable,
159
+ } from '@navios/commander'
145
160
 
146
161
  @Injectable()
147
162
  class CommandLogger {
@@ -178,7 +193,8 @@ The `ExecutionContext` provides the following methods:
178
193
  const app = await CommanderFactory.create(AppModule)
179
194
  await app.init()
180
195
 
181
- const commands = app.getAllCommands()
196
+ const adapter = app.getAdapter()
197
+ const commands = adapter.getAllCommands()
182
198
  console.log('Available commands:')
183
199
  commands.forEach(({ path }) => {
184
200
  console.log(` - ${path}`)
@@ -201,7 +217,8 @@ async function bootstrap() {
201
217
  await app.init()
202
218
 
203
219
  // Execute a command programmatically
204
- await app.executeCommand('greet', {
220
+ const adapter = app.getAdapter()
221
+ await adapter.executeCommand('greet', {
205
222
  name: 'World',
206
223
  greeting: 'Hi',
207
224
  })
@@ -229,6 +246,7 @@ Defines a CLI command.
229
246
  **Options:**
230
247
 
231
248
  - `path: string` - The command path (e.g., 'user:create', 'db:migrate')
249
+ - `description?: string` - Optional description for help text
232
250
  - `optionsSchema?: ZodSchema` - Optional Zod schema for validating command options
233
251
 
234
252
  #### `@CliModule(options)`
@@ -239,6 +257,7 @@ Defines a CLI module.
239
257
 
240
258
  - `commands?: ClassType[]` - Array of command classes
241
259
  - `imports?: ClassType[]` - Array of other modules to import
260
+ - `overrides?: ClassType[]` - Array of service override classes to import for side effects (ensures `@Injectable` decorators execute)
242
261
 
243
262
  ### Interfaces
244
263
 
@@ -272,19 +291,27 @@ Factory class for creating CLI applications.
272
291
 
273
292
  - `static async create(appModule, options?)` - Creates a new CommanderApplication
274
293
 
275
- #### `CommanderApplication`
294
+ #### `NaviosApplication`
276
295
 
277
- Main application class.
296
+ Main application class returned by `CommanderFactory.create()`.
278
297
 
279
298
  **Methods:**
280
299
 
281
300
  - `async init()` - Initializes the application
282
- - `async run(argv)` - Parses command-line arguments and executes the appropriate command (default usage)
283
- - `async executeCommand(path, options?)` - Executes a command programmatically with options (advanced usage)
284
- - `getAllCommands()` - Returns all registered commands
301
+ - `getAdapter()` - Returns the CLI adapter for running commands
285
302
  - `getContainer()` - Returns the DI container
286
303
  - `async close()` - Closes the application
287
304
 
305
+ #### `AbstractCliAdapterInterface`
306
+
307
+ CLI adapter interface returned by `app.getAdapter()`.
308
+
309
+ **Methods:**
310
+
311
+ - `async run(argv)` - Parses command-line arguments and executes the appropriate command
312
+ - `async executeCommand(path, options?)` - Executes a command programmatically with options
313
+ - `getAllCommands()` - Returns all registered commands
314
+
288
315
  ## License
289
316
 
290
317
  MIT
@@ -1,8 +1,65 @@
1
- import type { ClassTypeWithInstance, NaviosModule } from '@navios/core';
2
- import type { CommanderApplicationOptions } from './commander.application.mjs';
3
- import { CommanderApplication } from './commander.application.mjs';
1
+ import type { ClassTypeWithInstance, LogLevel, NaviosApplication, NaviosModule } from '@navios/core';
2
+ import type { CliEnvironment } from './interfaces/environment.interface.mjs';
4
3
  /**
5
- * Factory class for creating and configuring CLI applications.
4
+ * Logger display options for CLI applications.
5
+ * All options default to false for cleaner CLI output.
6
+ *
7
+ * @public
8
+ */
9
+ export interface CommanderLoggerOptions {
10
+ /**
11
+ * Enabled log levels.
12
+ * @default ['log', 'error', 'warn', 'debug', 'verbose', 'fatal']
13
+ */
14
+ logLevels?: LogLevel[];
15
+ /**
16
+ * If true, will print the process ID in the log message.
17
+ * @default false
18
+ */
19
+ showPid?: boolean;
20
+ /**
21
+ * If true, will print the log level in the log message.
22
+ * @default true
23
+ */
24
+ showLogLevel?: boolean;
25
+ /**
26
+ * If true, will print the prefix/app name in the log message.
27
+ * @default false
28
+ */
29
+ showPrefix?: boolean;
30
+ /**
31
+ * If true, will print the context in the log message.
32
+ * @default true
33
+ */
34
+ showContext?: boolean;
35
+ /**
36
+ * If true, will print the absolute timestamp in the log message.
37
+ * @default false
38
+ */
39
+ showTimestamp?: boolean;
40
+ /**
41
+ * If enabled, will print timestamp difference between current and previous log message.
42
+ * @default false
43
+ */
44
+ showTimeDiff?: boolean;
45
+ }
46
+ /**
47
+ * Configuration options for CommanderFactory.
48
+ *
49
+ * @public
50
+ */
51
+ export interface CommanderFactoryOptions {
52
+ /**
53
+ * Logger display options. These override the default CLI-friendly logger settings.
54
+ */
55
+ logger?: CommanderLoggerOptions;
56
+ }
57
+ /**
58
+ * Factory class for creating CLI applications.
59
+ *
60
+ * This is a convenience wrapper around `NaviosFactory.create()` that
61
+ * configures everything needed for CLI usage. It sets up the CLI adapter
62
+ * and returns a typed `NaviosApplication<CliEnvironment>`.
6
63
  *
7
64
  * @example
8
65
  * ```typescript
@@ -12,25 +69,42 @@ import { CommanderApplication } from './commander.application.mjs';
12
69
  * async function bootstrap() {
13
70
  * const app = await CommanderFactory.create(AppModule)
14
71
  * await app.init()
15
- * await app.run(process.argv)
72
+ *
73
+ * const adapter = app.getAdapter()
74
+ * await adapter.run(process.argv)
75
+ *
16
76
  * await app.close()
17
77
  * }
18
78
  * ```
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // Alternative: use NaviosFactory directly
83
+ * import { NaviosFactory } from '@navios/core'
84
+ * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'
85
+ *
86
+ * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {
87
+ * adapter: defineCliEnvironment(),
88
+ * })
89
+ * ```
19
90
  */
20
91
  export declare class CommanderFactory {
21
92
  /**
22
- * Creates a new CommanderApplication instance and configures it with the provided module.
93
+ * Creates a new CLI application instance configured with the provided module.
23
94
  *
24
- * @param appModule - The root CLI module class that contains commands and/or imports other modules
25
- * @param options - Optional configuration options for the application
26
- * @returns A promise that resolves to a configured CommanderApplication instance
95
+ * @param appModule - The root CLI module class decorated with `@CliModule`
96
+ * @param options - Optional configuration options for the CLI application
97
+ * @returns A promise that resolves to a configured NaviosApplication instance
27
98
  *
28
99
  * @example
29
100
  * ```typescript
30
101
  * const app = await CommanderFactory.create(AppModule)
31
102
  * await app.init()
103
+ *
104
+ * const adapter = app.getAdapter()
105
+ * await adapter.run(process.argv)
32
106
  * ```
33
107
  */
34
- static create(appModule: ClassTypeWithInstance<NaviosModule>, options?: CommanderApplicationOptions): Promise<CommanderApplication>;
108
+ static create<TModule extends NaviosModule = NaviosModule>(appModule: ClassTypeWithInstance<TModule>, options?: CommanderFactoryOptions): Promise<NaviosApplication<CliEnvironment>>;
35
109
  }
36
110
  //# sourceMappingURL=commander.factory.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commander.factory.d.mts","sourceRoot":"","sources":["../../src/commander.factory.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAIvE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAA;AAE9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAElE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;OAYG;WACU,MAAM,CACjB,SAAS,EAAE,qBAAqB,CAAC,YAAY,CAAC,EAC9C,OAAO,GAAE,2BAAgC;CAO5C"}
1
+ {"version":3,"file":"commander.factory.d.mts","sourceRoot":"","sources":["../../src/commander.factory.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,QAAQ,EACR,iBAAiB,EACjB,YAAY,EACb,MAAM,cAAc,CAAA;AAIrB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA;AAI5E;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAA;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,MAAM,CAAC,EAAE,sBAAsB,CAAA;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;;OAeG;WACU,MAAM,CAAC,OAAO,SAAS,YAAY,GAAG,YAAY,EAC7D,SAAS,EAAE,qBAAqB,CAAC,OAAO,CAAC,EACzC,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;CAgB9C"}
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+ import type { CommandHandler } from '../interfaces/command-handler.interface.mjs';
3
+ declare const helpOptionsSchema: z.ZodObject<{
4
+ command: z.ZodOptional<z.ZodString>;
5
+ }, z.core.$strip>;
6
+ type HelpOptions = z.infer<typeof helpOptionsSchema>;
7
+ /**
8
+ * Built-in help command that lists all available commands or shows help for a specific command.
9
+ *
10
+ * @public
11
+ */
12
+ export declare class HelpCommand implements CommandHandler<HelpOptions> {
13
+ private logger;
14
+ private commandRegistry;
15
+ execute(options: HelpOptions): Promise<void>;
16
+ }
17
+ export {};
18
+ //# sourceMappingURL=help.command.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.command.d.mts","sourceRoot":"","sources":["../../../src/commands/help.command.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAA;AAKjF,QAAA,MAAM,iBAAiB;;iBAErB,CAAA;AAEF,KAAK,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAEpD;;;;GAIG;AACH,qBAKa,WAAY,YAAW,cAAc,CAAC,WAAW,CAAC;IAC7D,OAAO,CAAC,MAAM,CAA2C;IACzD,OAAO,CAAC,eAAe,CAAiC;IAElD,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAOnD"}
@@ -0,0 +1,2 @@
1
+ export * from './help.command.mjs';
2
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/commands/index.mts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
@@ -11,10 +11,27 @@ export interface CliModuleOptions {
11
11
  */
12
12
  commands?: ClassType[] | Set<ClassType>;
13
13
  /**
14
- * Array or Set of other CLI modules to import.
15
- * Imported modules' commands will be available in this module.
14
+ * Array or Set of controller classes for HTTP endpoints.
15
+ * Allows mixing HTTP and CLI functionality in the same module.
16
+ */
17
+ controllers?: ClassType[] | Set<ClassType>;
18
+ /**
19
+ * Array or Set of other modules to import.
20
+ * Imported modules' commands and controllers will be available.
16
21
  */
17
22
  imports?: ClassType[] | Set<ClassType>;
23
+ /**
24
+ * Guards to apply to all controllers in this module.
25
+ * Guards are executed in reverse order (last guard first).
26
+ */
27
+ guards?: ClassType[] | Set<ClassType>;
28
+ /**
29
+ * Service override classes to import for side effects.
30
+ * These classes are imported to ensure their @Injectable decorators execute,
31
+ * allowing them to register with the DI system. Overrides should use the same
32
+ * InjectionToken as the original service with a higher priority.
33
+ */
34
+ overrides?: ClassType[] | Set<ClassType>;
18
35
  /**
19
36
  * Priority level for the module.
20
37
  * Higher priority modules will be loaded first.
@@ -29,7 +46,11 @@ export interface CliModuleOptions {
29
46
  /**
30
47
  * Decorator that marks a class as a CLI module.
31
48
  *
32
- * Modules organize commands and can import other modules to compose larger CLI applications.
49
+ * This decorator extends the standard @Module decorator, adding support for
50
+ * CLI commands while maintaining full compatibility with HTTP controllers.
51
+ * Modules organize commands and can import other modules to compose larger
52
+ * CLI applications.
53
+ *
33
54
  * The module can optionally implement `NaviosModule` interface for lifecycle hooks.
34
55
  *
35
56
  * @param options - Configuration options for the module
@@ -47,6 +68,17 @@ export interface CliModuleOptions {
47
68
  * })
48
69
  * export class AppModule {}
49
70
  * ```
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * // Mixed HTTP and CLI module
75
+ * @CliModule({
76
+ * controllers: [HealthController],
77
+ * commands: [MigrateCommand],
78
+ * imports: [DatabaseModule],
79
+ * })
80
+ * export class AppModule {}
81
+ * ```
50
82
  */
51
- export declare function CliModule({ commands, imports, priority, registry }?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
83
+ export declare function CliModule({ commands, controllers, imports, guards, overrides, priority, registry, }?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
52
84
  //# sourceMappingURL=cli-module.decorator.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli-module.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/cli-module.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAMvD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IACvC;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IACtC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CACvB,EAAE,QAAa,EAAE,OAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAE,gBAGpD,IAEO,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eAuB1D"}
1
+ {"version":3,"file":"cli-module.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/cli-module.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AASvD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IACvC;;;OAGG;IACH,WAAW,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IAC1C;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IACtC;;;OAGG;IACH,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IACxC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,SAAS,CACvB,EACE,QAAa,EACb,WAAgB,EAChB,OAAY,EACZ,MAAW,EACX,SAAc,EACd,QAAQ,EACR,QAAQ,GACT,GAAE,gBAMF,IAEO,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eAgC1D"}
@@ -11,6 +11,11 @@ export interface CommandOptions {
11
11
  * Can be a single word (e.g., 'greet') or multi-word with colons (e.g., 'user:create', 'db:migrate').
12
12
  */
13
13
  path: string;
14
+ /**
15
+ * Optional description of the command for help text.
16
+ * Displayed when users run `help` or `--help`.
17
+ */
18
+ description?: string;
14
19
  /**
15
20
  * Optional Zod schema for validating command options.
16
21
  * If provided, options will be validated and parsed according to this schema.
@@ -57,5 +62,5 @@ export interface CommandOptions {
57
62
  * }
58
63
  * ```
59
64
  */
60
- export declare function Command({ path, optionsSchema, priority, registry, }: CommandOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
65
+ export declare function Command({ path, description, optionsSchema, priority, registry, }: CommandOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
61
66
  //# sourceMappingURL=command.decorator.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"command.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/command.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAMpC;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,aAAa,CAAC,EAAE,SAAS,CAAA;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,OAAO,CAAC,EACtB,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,QAAQ,GACT,EAAE,cAAc,IACE,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eAiBnE"}
1
+ {"version":3,"file":"command.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/command.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAMpC;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,aAAa,CAAC,EAAE,SAAS,CAAA;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,OAAO,CAAC,EACtB,IAAI,EACJ,WAAW,EACX,aAAa,EACb,QAAQ,EACR,QAAQ,GACT,EAAE,cAAc,IACE,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eAiBnE"}
@@ -0,0 +1,31 @@
1
+ import type { AnyInjectableType, InjectionToken } from '@navios/core';
2
+ import { CommanderAdapterService } from './services/commander-adapter.service.mjs';
3
+ import { CommandRegistryService } from './services/command-registry.service.mjs';
4
+ import { CliParserService } from './services/cli-parser.service.mjs';
5
+ /**
6
+ * Defines the CLI environment configuration for use with NaviosFactory.
7
+ *
8
+ * This function returns the token mappings needed to configure a CLI application.
9
+ * Use it with `NaviosFactory.create()` to create a CLI application.
10
+ *
11
+ * @returns Environment configuration with token mappings
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { NaviosFactory } from '@navios/core'
16
+ * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'
17
+ *
18
+ * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {
19
+ * adapter: defineCliEnvironment(),
20
+ * })
21
+ * await app.init()
22
+ *
23
+ * const adapter = app.getAdapter() as AbstractCliAdapterInterface
24
+ * await adapter.run(process.argv)
25
+ * ```
26
+ */
27
+ export declare function defineCliEnvironment(): {
28
+ tokens: Map<InjectionToken<any, undefined, false>, AnyInjectableType>;
29
+ };
30
+ export { CommanderAdapterService, CommandRegistryService, CliParserService };
31
+ //# sourceMappingURL=define-environment.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-environment.d.mts","sourceRoot":"","sources":["../../src/define-environment.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAIrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAA;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAEpE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB;;EAKnC;AAGD,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,CAAA"}
@@ -1,7 +1,8 @@
1
1
  export * from '@navios/core';
2
- export * from './commander.application.mjs';
2
+ export * from './commands/index.mjs';
3
3
  export * from './commander.factory.mjs';
4
4
  export * from './decorators/index.mjs';
5
+ export * from './define-environment.mjs';
5
6
  export * from './interfaces/index.mjs';
6
7
  export * from './metadata/index.mjs';
7
8
  export * from './services/index.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.mts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA;AAG5B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.mts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA;AAG5B,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA"}
@@ -0,0 +1,53 @@
1
+ import type { AbstractAdapterInterface } from '@navios/core';
2
+ /**
3
+ * Interface for CLI adapters.
4
+ * Extends the base adapter interface with CLI-specific methods.
5
+ *
6
+ * @public
7
+ */
8
+ export interface AbstractCliAdapterInterface extends AbstractAdapterInterface {
9
+ /**
10
+ * Run the CLI application with the given arguments.
11
+ * Parses arguments and executes the matching command.
12
+ *
13
+ * @param argv - Command-line arguments array (defaults to `process.argv`)
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const adapter = app.getAdapter() as AbstractCliAdapterInterface
18
+ * await adapter.run(process.argv)
19
+ * ```
20
+ */
21
+ run(argv?: string[]): Promise<void>;
22
+ /**
23
+ * Execute a command programmatically with the provided options.
24
+ *
25
+ * @param path - The command path (e.g., 'greet', 'user:create')
26
+ * @param options - The command options object
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * await adapter.executeCommand('user:create', {
31
+ * name: 'John',
32
+ * email: 'john@example.com',
33
+ * })
34
+ * ```
35
+ */
36
+ executeCommand(path: string, options: Record<string, unknown>): Promise<void>;
37
+ /**
38
+ * Get all registered command paths and their class references.
39
+ *
40
+ * @returns Array of objects containing path and class
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const commands = adapter.getAllCommands()
45
+ * commands.forEach(({ path }) => console.log(path))
46
+ * ```
47
+ */
48
+ getAllCommands(): Array<{
49
+ path: string;
50
+ class: unknown;
51
+ }>;
52
+ }
53
+ //# sourceMappingURL=abstract-cli-adapter.interface.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-cli-adapter.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/abstract-cli-adapter.interface.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,2BAA4B,SAAQ,wBAAwB;IAC3E;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEnC;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7E;;;;;;;;;;OAUG;IACH,cAAc,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;CAC1D"}
@@ -7,7 +7,7 @@ import type { CommandMetadata } from '../metadata/command.metadata.mjs';
7
7
  *
8
8
  * @example
9
9
  * ```typescript
10
- * import { inject, Injectable } from '@navios/di'
10
+ * import { inject, Injectable } from '@navios/core'
11
11
  * import { CommandExecutionContext } from '@navios/commander'
12
12
  *
13
13
  * @Injectable()
@@ -0,0 +1,30 @@
1
+ import type { AdapterEnvironment } from '@navios/core';
2
+ import type { AbstractCliAdapterInterface } from './abstract-cli-adapter.interface.mjs';
3
+ /**
4
+ * Options for configuring the CLI adapter.
5
+ *
6
+ * @public
7
+ */
8
+ export interface CliAdapterOptions {
9
+ }
10
+ /**
11
+ * Environment type definition for CLI adapters.
12
+ * Used with NaviosFactory.create<CliEnvironment>() for type-safe CLI applications.
13
+ *
14
+ * @public
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { NaviosFactory } from '@navios/core'
19
+ * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'
20
+ *
21
+ * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {
22
+ * adapter: defineCliEnvironment(),
23
+ * })
24
+ * ```
25
+ */
26
+ export interface CliEnvironment extends AdapterEnvironment {
27
+ options: CliAdapterOptions;
28
+ adapter: AbstractCliAdapterInterface;
29
+ }
30
+ //# sourceMappingURL=environment.interface.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/environment.interface.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEtD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAA;AAEvF;;;;GAIG;AAEH,MAAM,WAAW,iBAAiB;CAEjC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,cAAe,SAAQ,kBAAkB;IACxD,OAAO,EAAE,iBAAiB,CAAA;IAC1B,OAAO,EAAE,2BAA2B,CAAA;CACrC"}
@@ -1,3 +1,5 @@
1
1
  export * from './command-handler.interface.mjs';
2
2
  export * from './commander-execution-context.interface.mjs';
3
+ export * from './abstract-cli-adapter.interface.mjs';
4
+ export * from './environment.interface.mjs';
3
5
  //# sourceMappingURL=index.d.mts.map