@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/CHANGELOG.md CHANGED
@@ -5,6 +5,73 @@ 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] - 2026-01-09
9
+
10
+ ### Added
11
+
12
+ - **Stable Release**: First stable release of @navios/commander
13
+ - Production-ready CLI command framework for Navios
14
+ - Type-safe command definitions with Zod validation
15
+ - Seamless integration with Navios dependency injection
16
+
17
+ ## [1.0.0-alpha.4] - 2026-01-09
18
+
19
+ ### Added
20
+
21
+ - **Unified Adapter Architecture**: Commander now uses the unified adapter system from `@navios/core`
22
+ - `CommanderAdapterService` implements `AbstractCliAdapterInterface` with standard lifecycle methods
23
+ - `AbstractCliAdapterInterface` extends `AbstractAdapterInterface` with CLI-specific methods (`run`, `executeCommand`, `getAllCommands`)
24
+ - `CliEnvironment` interface for type-safe CLI configuration
25
+ - `defineCommanderEnvironment()` function for creating CLI adapter environments
26
+ - **Command Description Support**: Commands now support `description` property for help text
27
+ - `@Command({ path: 'greet', description: 'Greet a user' })`
28
+ - Descriptions displayed in `--help` output
29
+ - **Built-in Help Command**: Automatic `help` command with `--help` flag support
30
+ - Shows all available commands with descriptions
31
+ - Per-command help with option details from Zod schema metadata
32
+ - Supports `.meta({ description: '...' })` on Zod fields for option descriptions
33
+ - **Command Registry Service**: New `CommandRegistryService` for managing registered commands
34
+ - Replaces module-level command tracking
35
+ - Provides `register()`, `getByPath()`, `getAllAsArray()`, and `clear()` methods
36
+ - **Module Custom Entries**: Commands are now registered via `customEntries` in module metadata
37
+ - `@CliModule({ commands: [...] })` stores commands in `customEntries` Map
38
+ - Adapter discovers commands via `CommandEntryKey` in module metadata
39
+
40
+ ### Changed
41
+
42
+ - **Factory Returns NaviosApplication**: `CommanderFactory.create()` now returns `NaviosApplication` instead of `CommanderApplication`
43
+ - Use `app.getAdapter()` to access CLI-specific methods
44
+ - Aligns with HTTP adapter pattern for consistency
45
+ - **CLI Module Decorator**: `@CliModule()` now extends `@Module()` with command registration
46
+ - Commands are added to `customEntries` instead of separate metadata
47
+ - Module imports and providers work the same as `@Module()`
48
+ - **Command Decorator**: Now stores metadata using standard Navios metadata system
49
+ - Metadata includes `description` field for help text
50
+ - **Application Lifecycle**: Uses standard `NaviosApplication` lifecycle
51
+ - `app.init()` initializes modules and adapter
52
+ - `app.getAdapter().run()` executes CLI commands
53
+ - `app.close()` disposes resources
54
+
55
+ ### Removed
56
+
57
+ - **CommanderApplication Class**: Replaced by `NaviosApplication` with CLI adapter
58
+ - **CliModuleLoaderService**: Replaced by `CommanderAdapterService.onModulesInit()`
59
+ - **CliModuleMetadata**: Module metadata now uses standard `ModuleMetadata` with `customEntries`
60
+
61
+ ### Breaking Changes
62
+
63
+ - **Factory Return Type**: `CommanderFactory.create()` returns `NaviosApplication` instead of `CommanderApplication`
64
+ - Before: `const app = await CommanderFactory.create(AppModule); await app.run()`
65
+ - After: `const app = await CommanderFactory.create(AppModule); await app.init(); await app.getAdapter().run()`
66
+ - **Method Access**: CLI methods accessed via `app.getAdapter()` instead of directly on app
67
+ - Before: `app.executeCommand('greet', opts)`
68
+ - After: `app.getAdapter().executeCommand('greet', opts)`
69
+ - **Module Decorator**: `@CliModule()` decorator signature unchanged but internal metadata format changed
70
+
71
+ ### Dependencies
72
+
73
+ - Updated to support `@navios/core` ^1.0.0-alpha.4
74
+
8
75
  ## [1.0.0-alpha.2] - 2026-01-07
9
76
 
10
77
  ### Added
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> {
@@ -74,8 +76,9 @@ async function bootstrap() {
74
76
  const app = await CommanderFactory.create(AppModule)
75
77
  await app.init()
76
78
 
77
- // Run with command-line arguments
78
- 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)
79
82
 
80
83
  await app.close()
81
84
  }
@@ -92,8 +95,13 @@ node dist/cli.js greet --name World --greeting Hi
92
95
  ### Advanced Example with Dependency Injection
93
96
 
94
97
  ```typescript
95
- import { CliModule, Command, CommandHandler } from '@navios/commander'
96
- import { inject, Injectable } from '@navios/di'
98
+ import {
99
+ CliModule,
100
+ Command,
101
+ CommandHandler,
102
+ inject,
103
+ Injectable,
104
+ } from '@navios/commander'
97
105
 
98
106
  import { z } from 'zod'
99
107
 
@@ -142,8 +150,13 @@ export class AppModule {}
142
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.
143
151
 
144
152
  ```typescript
145
- import { Command, CommandHandler, CommandExecutionContext } from '@navios/commander'
146
- import { inject, Injectable } from '@navios/di'
153
+ import {
154
+ Command,
155
+ CommandExecutionContext,
156
+ CommandHandler,
157
+ inject,
158
+ Injectable,
159
+ } from '@navios/commander'
147
160
 
148
161
  @Injectable()
149
162
  class CommandLogger {
@@ -180,7 +193,8 @@ The `ExecutionContext` provides the following methods:
180
193
  const app = await CommanderFactory.create(AppModule)
181
194
  await app.init()
182
195
 
183
- const commands = app.getAllCommands()
196
+ const adapter = app.getAdapter()
197
+ const commands = adapter.getAllCommands()
184
198
  console.log('Available commands:')
185
199
  commands.forEach(({ path }) => {
186
200
  console.log(` - ${path}`)
@@ -203,7 +217,8 @@ async function bootstrap() {
203
217
  await app.init()
204
218
 
205
219
  // Execute a command programmatically
206
- await app.executeCommand('greet', {
220
+ const adapter = app.getAdapter()
221
+ await adapter.executeCommand('greet', {
207
222
  name: 'World',
208
223
  greeting: 'Hi',
209
224
  })
@@ -231,6 +246,7 @@ Defines a CLI command.
231
246
  **Options:**
232
247
 
233
248
  - `path: string` - The command path (e.g., 'user:create', 'db:migrate')
249
+ - `description?: string` - Optional description for help text
234
250
  - `optionsSchema?: ZodSchema` - Optional Zod schema for validating command options
235
251
 
236
252
  #### `@CliModule(options)`
@@ -275,19 +291,27 @@ Factory class for creating CLI applications.
275
291
 
276
292
  - `static async create(appModule, options?)` - Creates a new CommanderApplication
277
293
 
278
- #### `CommanderApplication`
294
+ #### `NaviosApplication`
279
295
 
280
- Main application class.
296
+ Main application class returned by `CommanderFactory.create()`.
281
297
 
282
298
  **Methods:**
283
299
 
284
300
  - `async init()` - Initializes the application
285
- - `async run(argv)` - Parses command-line arguments and executes the appropriate command (default usage)
286
- - `async executeCommand(path, options?)` - Executes a command programmatically with options (advanced usage)
287
- - `getAllCommands()` - Returns all registered commands
301
+ - `getAdapter()` - Returns the CLI adapter for running commands
288
302
  - `getContainer()` - Returns the DI container
289
303
  - `async close()` - Closes the application
290
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
+
291
315
  ## License
292
316
 
293
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,20 @@ 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>;
18
28
  /**
19
29
  * Service override classes to import for side effects.
20
30
  * These classes are imported to ensure their @Injectable decorators execute,
@@ -36,7 +46,11 @@ export interface CliModuleOptions {
36
46
  /**
37
47
  * Decorator that marks a class as a CLI module.
38
48
  *
39
- * 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
+ *
40
54
  * The module can optionally implement `NaviosModule` interface for lifecycle hooks.
41
55
  *
42
56
  * @param options - Configuration options for the module
@@ -54,6 +68,17 @@ export interface CliModuleOptions {
54
68
  * })
55
69
  * export class AppModule {}
56
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
+ * ```
57
82
  */
58
- export declare function CliModule({ commands, imports, overrides, 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;
59
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;;;;;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;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CACvB,EACE,QAAa,EACb,OAAY,EACZ,SAAc,EACd,QAAQ,EACR,QAAQ,GACT,GAAE,gBAIF,IAEO,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eA0B1D"}
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/interfaces/index.mts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA;AAC/C,cAAc,6CAA6C,CAAA"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/interfaces/index.mts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA;AAC/C,cAAc,6CAA6C,CAAA;AAC3D,cAAc,sCAAsC,CAAA;AACpD,cAAc,6BAA6B,CAAA"}