@navios/commander 1.6.0 → 1.8.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 (35) hide show
  1. package/.turbo/turbo-build.log +21 -21
  2. package/.turbo/turbo-lint.log +1 -1
  3. package/.turbo/turbo-test$colon$ci.log +4 -4
  4. package/.turbo/turbo-test.log +7 -5
  5. package/CHANGELOG.md +20 -0
  6. package/dist/src/services/cli-parser.service.d.mts +55 -1
  7. package/dist/src/services/cli-parser.service.d.mts.map +1 -1
  8. package/dist/src/services/command-registry.service.d.mts +12 -0
  9. package/dist/src/services/command-registry.service.d.mts.map +1 -1
  10. package/dist/src/services/commander-adapter.service.d.mts.map +1 -1
  11. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  12. package/dist/tsconfig.tsbuildinfo +1 -1
  13. package/lib/{help-command.token-DamE31Aw.cjs → help-command.token-BI5XnE07.cjs} +35 -2
  14. package/lib/help-command.token-BI5XnE07.cjs.map +1 -0
  15. package/lib/{help-command.token-XHx3WkoD.mjs → help-command.token-D81bRnnl.mjs} +35 -2
  16. package/lib/help-command.token-D81bRnnl.mjs.map +1 -0
  17. package/lib/{help.command-Bynoll_7.mjs → help.command-B14cbwE_.mjs} +2 -2
  18. package/lib/{help.command-Bynoll_7.mjs.map → help.command-B14cbwE_.mjs.map} +1 -1
  19. package/lib/{help.command-DvKmMpB7.cjs → help.command-Dg-0v-yP.cjs} +2 -2
  20. package/lib/{help.command-DvKmMpB7.cjs.map → help.command-Dg-0v-yP.cjs.map} +1 -1
  21. package/lib/index.cjs +141 -11
  22. package/lib/index.cjs.map +1 -1
  23. package/lib/index.d.cts +67 -1
  24. package/lib/index.d.cts.map +1 -1
  25. package/lib/index.d.mts +67 -1
  26. package/lib/index.d.mts.map +1 -1
  27. package/lib/index.mjs +141 -11
  28. package/lib/index.mjs.map +1 -1
  29. package/package.json +2 -2
  30. package/src/services/__tests__/cli-parser.service.spec.mts +404 -0
  31. package/src/services/cli-parser.service.mts +243 -34
  32. package/src/services/command-registry.service.mts +61 -0
  33. package/src/services/commander-adapter.service.mts +8 -4
  34. package/lib/help-command.token-DamE31Aw.cjs.map +0 -1
  35. package/lib/help-command.token-XHx3WkoD.mjs.map +0 -1
package/lib/index.d.mts CHANGED
@@ -214,6 +214,7 @@ interface ParsedCliArgs {
214
214
  /**
215
215
  * Parsed options as key-value pairs.
216
216
  * Keys are converted from kebab-case to camelCase.
217
+ * Supports object notation (e.g., --obj.field=value creates { obj: { field: value } }).
217
218
  */
218
219
  options: Record<string, any>;
219
220
  /**
@@ -230,6 +231,8 @@ interface ParsedCliArgs {
230
231
  * - Boolean flags
231
232
  * - Array options
232
233
  * - Positional arguments
234
+ * - Object notation: `--obj.field=value` or `--obj.nested.field value`
235
+ * Creates nested objects automatically (e.g., { obj: { field: value } })
233
236
  *
234
237
  * @public
235
238
  */
@@ -241,9 +244,21 @@ declare class CliParserService {
241
244
  *
242
245
  * @param argv - Array of command-line arguments (typically process.argv)
243
246
  * @param optionsSchema - Optional zod/v4 schema to determine boolean flags and option types
247
+ * @param availableCommands - Optional list of registered command paths for smart detection.
248
+ * When provided, scans argv to find the best matching command, enabling support for
249
+ * custom launchers (tsx, ts-node, npx, etc.) that add extra args before the command.
244
250
  * @returns Parsed command (space-separated if multi-word), options, and positional arguments
245
251
  */
246
- parse(argv: string[], optionsSchema?: z.ZodObject): ParsedCliArgs;
252
+ parse(argv: string[], optionsSchema?: z.ZodObject, availableCommands?: string[]): ParsedCliArgs;
253
+ /**
254
+ * Finds the index in argv where the command starts by matching against available commands.
255
+ * Prioritizes longer/more specific commands (e.g., 'db migrate' matches before 'db').
256
+ *
257
+ * @param argv - Full argv array
258
+ * @param availableCommands - List of registered command paths
259
+ * @returns Index where the command starts, or 2 as fallback
260
+ */
261
+ private findCommandStartIndex;
247
262
  /**
248
263
  * Converts kebab-case to camelCase
249
264
  */
@@ -272,6 +287,45 @@ declare class CliParserService {
272
287
  * Unwraps zod/v4Optional and zod/v4Default using zod/v4 v4 API
273
288
  */
274
289
  private isSchemaArray;
290
+ /**
291
+ * Sets a nested property on an object using dot notation path.
292
+ * Creates intermediate objects as needed.
293
+ *
294
+ * @example
295
+ * setNestedProperty({}, 'a.b.c', 'value') // { a: { b: { c: 'value' } } }
296
+ */
297
+ private setNestedProperty;
298
+ /**
299
+ * Gets a nested property from an object using dot notation path.
300
+ * Returns undefined if path doesn't exist.
301
+ */
302
+ private getNestedProperty;
303
+ /**
304
+ * Checks if an option key contains dot notation (object notation).
305
+ * Returns true for keys like "obj.field" or "deep.nested.value".
306
+ */
307
+ private isObjectNotation;
308
+ /**
309
+ * Processes an option key that may contain object notation.
310
+ * Converts each segment from kebab-case to camelCase.
311
+ *
312
+ * @example
313
+ * processObjectNotationKey('my-obj.field-name') // 'myObj.fieldName'
314
+ */
315
+ private processObjectNotationKey;
316
+ /**
317
+ * Gets the nested schema for a given dot-notation path.
318
+ * Returns undefined if the path doesn't lead to a valid schema.
319
+ */
320
+ private getNestedSchema;
321
+ /**
322
+ * Checks if a nested path represents a boolean field in the schema.
323
+ */
324
+ private isNestedBoolean;
325
+ /**
326
+ * Checks if a nested path represents an array field in the schema.
327
+ */
328
+ private isNestedArray;
275
329
  }
276
330
  //#endregion
277
331
  //#region src/metadata/command-entry.metadata.d.mts
@@ -377,6 +431,11 @@ declare class CommandRegistryService {
377
431
  * @returns Formatted string with command help
378
432
  */
379
433
  formatCommandHelp(commandPath: string): string;
434
+ /**
435
+ * Recursively formats nested object options for help display.
436
+ * Shows nested fields with dot notation (e.g., --config.port)
437
+ */
438
+ private formatNestedObjectOptions;
380
439
  /**
381
440
  * Gets a human-readable type name from a zod/v4 schema.
382
441
  */
@@ -387,6 +446,13 @@ declare class CommandRegistryService {
387
446
  * or in innerType when .meta() is called before .optional()/.default().
388
447
  */
389
448
  private getSchemaMeta;
449
+ /**
450
+ * Get all registered command paths.
451
+ * Useful for smart command detection in argv parsing.
452
+ *
453
+ * @returns Array of command paths
454
+ */
455
+ getAllPaths(): string[];
390
456
  /**
391
457
  * Clear all registered commands.
392
458
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":["z","CommandHandler","helpOptionsSchema","ZodString","ZodOptional","core","$strip","ZodObject","HelpOptions","infer","HelpCommand","Promise","ClassTypeWithInstance","LogLevel","NaviosApplication","NaviosModule","CliEnvironment","CommanderLoggerOptions","CommanderTuiOptions","Record","CommanderFactoryOptions","CommanderFactory","TModule","Promise","z","ParsedCliArgs","Record","CliParserService","ZodObject","ClassType","CommandEntryKey","CommandEntryValue","Set","extractModuleCommands","ClassType","CommandMetadata","RegisteredCommand","CommandRegistryService","Map","Array","ClassType","ModuleMetadata","AbstractCliAdapterInterface","CliAdapterOptions","CommanderAdapterService","Promise","Map","Record","Array","AnyInjectableType","InjectionToken","CliParserService","CommandRegistryService","CommanderAdapterService","defineCliEnvironment","Map","InjectionToken","CommanderExecutionContext","CommandExecutionContext"],"sources":["../src/commands/help.command.d.mts","../src/commander.factory.d.mts","../src/services/cli-parser.service.d.mts","../src/metadata/command-entry.metadata.d.mts","../src/services/command-registry.service.d.mts","../src/services/commander-adapter.service.d.mts","../src/define-environment.d.mts","../src/tokens/execution-context.token.d.mts"],"sourcesContent":["import { z } from 'zod/v4'\n\nimport type { CommandHandler } from '../interfaces/command-handler.interface.mjs'\ndeclare const helpOptionsSchema: z.ZodObject<\n {\n command: z.ZodOptional<z.ZodString>\n },\n z.core.$strip\n>\ntype HelpOptions = z.infer<typeof helpOptionsSchema>\n/**\n * Built-in help command that lists all available commands or shows help for a specific command.\n *\n * @public\n */\nexport declare class HelpCommand implements CommandHandler<HelpOptions> {\n private logger\n private commandRegistry\n execute(options: HelpOptions): Promise<void>\n}\nexport {}\n//# sourceMappingURL=help.command.d.mts.map\n","import type { ClassTypeWithInstance, LogLevel, NaviosApplication, NaviosModule } from '@navios/core'\n\nimport type { CliEnvironment } from './interfaces/environment.interface.mjs'\n/**\n * Logger display options for CLI applications.\n * All options default to false for cleaner CLI output.\n *\n * @public\n */\nexport interface CommanderLoggerOptions {\n /**\n * Enabled log levels.\n * @default ['log', 'error', 'warn', 'debug', 'verbose', 'fatal']\n */\n logLevels?: LogLevel[]\n /**\n * If true, will print the process ID in the log message.\n * @default false\n */\n showPid?: boolean\n /**\n * If true, will print the log level in the log message.\n * @default true\n */\n showLogLevel?: boolean\n /**\n * If true, will print the prefix/app name in the log message.\n * @default false\n */\n showPrefix?: boolean\n /**\n * If true, will print the context in the log message.\n * @default true\n */\n showContext?: boolean\n /**\n * If true, will print the absolute timestamp in the log message.\n * @default false\n */\n showTimestamp?: boolean\n /**\n * If enabled, will print timestamp difference between current and previous log message.\n * @default false\n */\n showTimeDiff?: boolean\n}\n/**\n * TUI-specific options for terminal UI mode.\n * Only used when enableTUI is true.\n *\n * @public\n */\nexport interface CommanderTuiOptions {\n /**\n * Exit on Ctrl+C.\n * @default true\n */\n exitOnCtrlC?: boolean\n /**\n * Adapter to use for the TUI.\n * @default 'none'\n */\n adapter?: 'react' | 'solid' | 'ink' | 'none'\n /**\n * Sidebar width in columns.\n */\n sidebarWidth?: number\n /**\n * Sidebar position.\n */\n sidebarPosition?: 'left' | 'right'\n /**\n * Sidebar header title.\n */\n sidebarTitle?: string\n /**\n * Auto close after all screens complete successfully.\n * Set to true for default delay (5000ms), or specify delay in milliseconds.\n */\n autoClose?: boolean | number\n /**\n * Theme preset name ('dark', 'light', 'high-contrast') or custom theme object.\n */\n theme?: string | Record<string, unknown>\n /**\n * Enable mouse support.\n * @default false\n */\n useMouse?: boolean\n /**\n * Hide the default console logger screen from the sidebar.\n * @default false\n */\n hideDefaultScreen?: boolean\n /**\n * Use OpenTUI for terminal rendering.\n * When true: Full TUI with sidebar, scrolling, interactive prompts.\n * When false: Stdout mode - static screens print immediately, others on completion.\n * @default true for Node.js, false for Bun (OpenTUI not supported)\n */\n useOpenTUI?: boolean\n}\n/**\n * Configuration options for CommanderFactory.\n *\n * @public\n */\nexport interface CommanderFactoryOptions {\n /**\n * Enabled log levels.\n * @default ['log', 'error', 'warn', 'debug', 'verbose', 'fatal']\n */\n logLevels?: LogLevel[]\n /**\n * Logger display options. These override the default CLI-friendly logger settings.\n * Ignored when enableTUI is true.\n */\n logger?: CommanderLoggerOptions\n /**\n * Enable TUI mode with @navios/commander-tui.\n * Requires @navios/commander-tui to be installed.\n */\n enableTUI?: boolean\n /**\n * TUI-specific options. Only used when enableTUI is true.\n */\n tuiOptions?: CommanderTuiOptions\n}\n/**\n * Factory class for creating CLI applications.\n *\n * This is a convenience wrapper around `NaviosFactory.create()` that\n * configures everything needed for CLI usage. It sets up the CLI adapter\n * and returns a typed `NaviosApplication<CliEnvironment>`.\n *\n * @example\n * ```typescript\n * import { CommanderFactory } from '@navios/commander'\n * import { AppModule } from './app.module'\n *\n * async function bootstrap() {\n * const app = await CommanderFactory.create(AppModule)\n * await app.init()\n *\n * const adapter = app.getAdapter()\n * await adapter.run(process.argv)\n *\n * await app.close()\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Alternative: use NaviosFactory directly\n * import { NaviosFactory } from '@navios/core'\n * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'\n *\n * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {\n * adapter: defineCliEnvironment(),\n * })\n * ```\n */\nexport declare class CommanderFactory {\n /**\n * Creates a new CLI application instance configured with the provided module.\n *\n * @param appModule - The root CLI module class decorated with `@CliModule`\n * @param options - Optional configuration options for the CLI application\n * @returns A promise that resolves to a configured NaviosApplication instance\n *\n * @example\n * ```typescript\n * const app = await CommanderFactory.create(AppModule)\n * await app.init()\n *\n * const adapter = app.getAdapter()\n * await adapter.run(process.argv)\n * ```\n */\n static create<TModule extends NaviosModule = NaviosModule>(\n appModule: ClassTypeWithInstance<TModule>,\n options?: CommanderFactoryOptions,\n ): Promise<NaviosApplication<CliEnvironment>>\n}\n//# sourceMappingURL=commander.factory.d.mts.map\n","import type { z } from 'zod/v4'\n/**\n * Result of parsing command-line arguments.\n *\n * @public\n */\nexport interface ParsedCliArgs {\n /**\n * The command path (e.g., 'greet', 'user:create').\n * Multi-word commands are joined with spaces.\n */\n command: string\n /**\n * Parsed options as key-value pairs.\n * Keys are converted from kebab-case to camelCase.\n */\n options: Record<string, any>\n /**\n * Positional arguments that don't match any option flags.\n */\n positionals: string[]\n}\n/**\n * Service for parsing command-line arguments.\n *\n * Handles parsing of various CLI argument formats including:\n * - Long options: `--key value` or `--key=value`\n * - Short options: `-k value` or `-abc` (multiple flags)\n * - Boolean flags\n * - Array options\n * - Positional arguments\n *\n * @public\n */\nexport declare class CliParserService {\n /**\n * Parses command-line arguments from process.argv\n * Commands can be multi-word (e.g., 'db migrate', 'cache clear')\n * Expected format: node script.js command [subcommand...] --flag value --boolean-flag positional1 positional2\n *\n * @param argv - Array of command-line arguments (typically process.argv)\n * @param optionsSchema - Optional zod/v4 schema to determine boolean flags and option types\n * @returns Parsed command (space-separated if multi-word), options, and positional arguments\n */\n parse(argv: string[], optionsSchema?: z.ZodObject): ParsedCliArgs\n /**\n * Converts kebab-case to camelCase\n */\n private camelCase\n /**\n * Attempts to parse string values into appropriate types\n */\n private parseValue\n /**\n * Extracts boolean field names from a zod/v4 schema\n * Handles z.ZodObject, zod/v4Optional, and zod/v4Default wrappers\n */\n private extractBooleanFields\n /**\n * Extracts array field names from a zod/v4 schema\n * Handles z.ZodObject, zod/v4Optional, and zod/v4Default wrappers\n */\n private extractArrayFields\n /**\n * Checks if a zod/v4 schema represents a boolean type\n * Unwraps zod/v4Optional and zod/v4Default using zod/v4 v4 API\n */\n private isSchemaBoolean\n /**\n * Checks if a zod/v4 schema represents an array type\n * Unwraps zod/v4Optional and zod/v4Default using zod/v4 v4 API\n */\n private isSchemaArray\n}\n//# sourceMappingURL=cli-parser.service.d.mts.map\n","import type { ClassType } from '@navios/core'\n/**\n * Symbol key for storing commands in ModuleMetadata.customEntries.\n * Used by @CliModule to store command classes.\n *\n * @public\n */\nexport declare const CommandEntryKey: unique symbol\n/**\n * Type for the command entry value stored in customEntries.\n *\n * @public\n */\nexport type CommandEntryValue = Set<ClassType>\n/**\n * Extracts commands from a module's metadata.\n * Returns empty set if no commands are defined.\n *\n * @param moduleClass - The module class decorated with @CliModule or @Module\n * @returns Set of command classes registered in the module\n *\n * @example\n * ```typescript\n * const commands = extractModuleCommands(AppModule)\n * for (const command of commands) {\n * console.log(command.name)\n * }\n * ```\n */\nexport declare function extractModuleCommands(moduleClass: ClassType): Set<ClassType>\n//# sourceMappingURL=command-entry.metadata.d.mts.map\n","import type { ClassType } from '@navios/core'\n\nimport type { CommandMetadata } from '../metadata/index.mjs'\n/**\n * Represents a registered command with its metadata and module information.\n *\n * @public\n */\nexport interface RegisteredCommand {\n /**\n * The command class\n */\n class: ClassType\n /**\n * The command metadata from @Command decorator\n */\n metadata: CommandMetadata\n /**\n * Name of the module this command belongs to\n */\n moduleName: string\n}\n/**\n * Service for registering and looking up CLI commands.\n * Used internally by the CLI adapter to manage discovered commands.\n *\n * @public\n */\nexport declare class CommandRegistryService {\n private commands\n /**\n * Register a command with its metadata.\n *\n * @param path - The command path (e.g., 'greet', 'user:create')\n * @param command - The registered command data\n * @throws Error if a command with the same path is already registered\n */\n register(path: string, command: RegisteredCommand): void\n /**\n * Get a command by its path.\n *\n * @param path - The command path\n * @returns The registered command or undefined if not found\n */\n getByPath(path: string): RegisteredCommand | undefined\n /**\n * Get all registered commands.\n *\n * @returns Map of path to registered command\n */\n getAll(): Map<string, RegisteredCommand>\n /**\n * Get all registered commands as an array of path and class pairs.\n * Useful for listing available commands.\n *\n * @returns Array of objects containing path and class\n */\n getAllAsArray(): Array<{\n path: string\n class: ClassType\n }>\n /**\n * Formats help text listing all available commands with descriptions.\n *\n * @returns Formatted string listing all commands\n */\n formatCommandList(): string\n /**\n * Formats help text for a specific command.\n *\n * @param commandPath - The command path to show help for\n * @returns Formatted string with command help\n */\n formatCommandHelp(commandPath: string): string\n /**\n * Gets a human-readable type name from a zod/v4 schema.\n */\n private getSchemaTypeName\n /**\n * Gets metadata from a zod/v4 schema, traversing innerType if needed.\n * zod/v4 v4 stores meta at the outermost layer when .meta() is called last,\n * or in innerType when .meta() is called before .optional()/.default().\n */\n private getSchemaMeta\n /**\n * Clear all registered commands.\n */\n clear(): void\n}\n//# sourceMappingURL=command-registry.service.d.mts.map\n","import type { ClassType, ModuleMetadata } from '@navios/core'\n\nimport type { AbstractCliAdapterInterface } from '../interfaces/abstract-cli-adapter.interface.mjs'\nimport type { CliAdapterOptions } from '../interfaces/environment.interface.mjs'\n/**\n * CLI adapter service that implements the AbstractCliAdapterInterface.\n * Handles command discovery, registration, parsing, and execution.\n *\n * @public\n */\nexport declare class CommanderAdapterService implements AbstractCliAdapterInterface {\n private container\n private commandRegistry\n private cliParser\n private logger\n private options\n private isReady\n /**\n * Sets up the adapter with the provided options.\n * Called during application initialization.\n */\n setupAdapter(options: CliAdapterOptions): Promise<void>\n /**\n * Called after all modules are loaded.\n * Iterates through modules and extracts commands from customEntries.\n */\n onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>\n /**\n * Registers built-in commands like help.\n */\n private registerBuiltInCommands\n /**\n * Signals that the adapter is ready to handle commands.\n */\n ready(): Promise<void>\n /**\n * Disposes of the adapter and cleans up resources.\n */\n dispose(): Promise<void>\n /**\n * Run the CLI application with the given arguments.\n * Parses arguments and executes the matching command.\n */\n run(argv?: string[]): Promise<void>\n /**\n * Execute a command programmatically with the provided options.\n */\n executeCommand(\n path: string,\n options?: Record<string, unknown>,\n positionals?: string[],\n ): Promise<void>\n /**\n * Get all registered command paths and their class references.\n */\n getAllCommands(): Array<{\n path: string\n class: ClassType\n }>\n}\n//# sourceMappingURL=commander-adapter.service.d.mts.map\n","import type { AnyInjectableType, InjectionToken } from '@navios/core'\n\nimport { CliParserService } from './services/cli-parser.service.mjs'\nimport { CommandRegistryService } from './services/command-registry.service.mjs'\nimport { CommanderAdapterService } from './services/commander-adapter.service.mjs'\n/**\n * Defines the CLI environment configuration for use with NaviosFactory.\n *\n * This function returns the token mappings needed to configure a CLI application.\n * Use it with `NaviosFactory.create()` to create a CLI application.\n *\n * @returns Environment configuration with token mappings\n *\n * @example\n * ```typescript\n * import { NaviosFactory } from '@navios/core'\n * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'\n *\n * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {\n * adapter: defineCliEnvironment(),\n * })\n * await app.init()\n *\n * const adapter = app.getAdapter() as AbstractCliAdapterInterface\n * await adapter.run(process.argv)\n * ```\n */\nexport declare function defineCliEnvironment(): {\n tokens: Map<InjectionToken<any, undefined, false>, AnyInjectableType>\n}\nexport { CommanderAdapterService, CommandRegistryService, CliParserService }\n//# sourceMappingURL=define-environment.d.mts.map\n","import { InjectionToken } from '@navios/core'\n\nimport type { CommanderExecutionContext } from '../interfaces/index.mjs'\n/**\n * Injection token for accessing the current command execution context.\n *\n * Use this token with `inject()` to access the `CommanderExecutionContext` in services\n * that need information about the currently executing command.\n *\n * @example\n * ```typescript\n * import { inject, Injectable } from '@navios/core'\n * import { CommandExecutionContext } from '@navios/commander'\n *\n * @Injectable()\n * class MyService {\n * private ctx = inject(CommandExecutionContext)\n *\n * doSomething() {\n * const commandPath = this.ctx.getCommandPath()\n * const options = this.ctx.getOptions()\n * // Use context information...\n * }\n * }\n * ```\n */\nexport declare const CommandExecutionContext: InjectionToken<\n CommanderExecutionContext,\n undefined,\n false\n>\n//# sourceMappingURL=execution-context.token.d.mts.map\n"],"mappings":";;;;;;cAGcE,mBAAmBF,CAAAA,CAAEO;WAEtBP,CAAAA,CAAEI,YAAYJ,CAAAA,CAAEG;GAE3BH,CAAAA,CAAEK,IAAAA,CAAKC,MAJKJ,CAEaF;KAItBQ,WAAAA,GAAcR,CAAAA,CAAES,KAJNL,CAAAA,OAImBF,iBAJnBE,CAAAA;;;;AAF6B;AAY5C;AAA2DI,cAAtCE,WAAAA,YAAuBT,cAAeO,CAAAA,WAAAA,CAAAA,CAAAA;EAGxCA,QAAAA,MAAAA;EAAcG,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AA,MAAAA,EAMTC,OAAwBF,CAAxBE,EEoCEgB,MFpCFhB,CAAAA,MAAiB,EAAA,OAAOF,CAAAA,EAgBZI,WAAAA,CAAAA,EAAAA,MAAAA,EAAAA,CAAmCJ,EEsBtDgB,OFtBsDhB,CAAAA,IAAAA,CAAAA;EAAgBA;;;oBE0BvDmB;;WAETR;EDjDX,CAAA,CAAiBJ;AAoBjB;;;;;AJ1BiF;;;;;;AACrC;AAY5C;;;;;;;;;ACNA;AA2CA;AAuDA;;AAUWnB,iBK1FaqC,oBAAAA,CAAAA,CL0FbrC,EAAAA;EASIC,MAAAA,EKlGLqC,GLkGKrC,CKlGDgC,cLkGChC,CAAAA,GAAAA,EAAAA,SAAAA,EAAAA,KAAAA,CAAAA,EKlGsC+B,iBLkGtC/B,CAAAA;CAAmB;;;;;;;AD5H+C;;;;;;AACrC;AAY5C;;;;;;;;;ACNA;AA2CA;AAuDA;AAKcL,cMtFO6C,uBNsFP7C,EMtFgC2C,cNsFhC3C,CMrFZ4C,yBN0FSxC,EASIC,SAAAA,EAAmB,KAAA,CAoClC"}
1
+ {"version":3,"file":"index.d.mts","names":["z","CommandHandler","helpOptionsSchema","ZodString","ZodOptional","core","$strip","ZodObject","HelpOptions","infer","HelpCommand","Promise","ClassTypeWithInstance","LogLevel","NaviosApplication","NaviosModule","CliEnvironment","CommanderLoggerOptions","CommanderTuiOptions","Record","CommanderFactoryOptions","CommanderFactory","TModule","Promise","z","ParsedCliArgs","Record","CliParserService","ZodObject","ClassType","CommandEntryKey","CommandEntryValue","Set","extractModuleCommands","ClassType","CommandMetadata","RegisteredCommand","CommandRegistryService","Map","Array","ClassType","ModuleMetadata","AbstractCliAdapterInterface","CliAdapterOptions","CommanderAdapterService","Promise","Map","Record","Array","AnyInjectableType","InjectionToken","CliParserService","CommandRegistryService","CommanderAdapterService","defineCliEnvironment","Map","InjectionToken","CommanderExecutionContext","CommandExecutionContext"],"sources":["../src/commands/help.command.d.mts","../src/commander.factory.d.mts","../src/services/cli-parser.service.d.mts","../src/metadata/command-entry.metadata.d.mts","../src/services/command-registry.service.d.mts","../src/services/commander-adapter.service.d.mts","../src/define-environment.d.mts","../src/tokens/execution-context.token.d.mts"],"sourcesContent":["import { z } from 'zod/v4'\n\nimport type { CommandHandler } from '../interfaces/command-handler.interface.mjs'\ndeclare const helpOptionsSchema: z.ZodObject<\n {\n command: z.ZodOptional<z.ZodString>\n },\n z.core.$strip\n>\ntype HelpOptions = z.infer<typeof helpOptionsSchema>\n/**\n * Built-in help command that lists all available commands or shows help for a specific command.\n *\n * @public\n */\nexport declare class HelpCommand implements CommandHandler<HelpOptions> {\n private logger\n private commandRegistry\n execute(options: HelpOptions): Promise<void>\n}\nexport {}\n//# sourceMappingURL=help.command.d.mts.map\n","import type { ClassTypeWithInstance, LogLevel, NaviosApplication, NaviosModule } from '@navios/core'\n\nimport type { CliEnvironment } from './interfaces/environment.interface.mjs'\n/**\n * Logger display options for CLI applications.\n * All options default to false for cleaner CLI output.\n *\n * @public\n */\nexport interface CommanderLoggerOptions {\n /**\n * Enabled log levels.\n * @default ['log', 'error', 'warn', 'debug', 'verbose', 'fatal']\n */\n logLevels?: LogLevel[]\n /**\n * If true, will print the process ID in the log message.\n * @default false\n */\n showPid?: boolean\n /**\n * If true, will print the log level in the log message.\n * @default true\n */\n showLogLevel?: boolean\n /**\n * If true, will print the prefix/app name in the log message.\n * @default false\n */\n showPrefix?: boolean\n /**\n * If true, will print the context in the log message.\n * @default true\n */\n showContext?: boolean\n /**\n * If true, will print the absolute timestamp in the log message.\n * @default false\n */\n showTimestamp?: boolean\n /**\n * If enabled, will print timestamp difference between current and previous log message.\n * @default false\n */\n showTimeDiff?: boolean\n}\n/**\n * TUI-specific options for terminal UI mode.\n * Only used when enableTUI is true.\n *\n * @public\n */\nexport interface CommanderTuiOptions {\n /**\n * Exit on Ctrl+C.\n * @default true\n */\n exitOnCtrlC?: boolean\n /**\n * Adapter to use for the TUI.\n * @default 'none'\n */\n adapter?: 'react' | 'solid' | 'ink' | 'none'\n /**\n * Sidebar width in columns.\n */\n sidebarWidth?: number\n /**\n * Sidebar position.\n */\n sidebarPosition?: 'left' | 'right'\n /**\n * Sidebar header title.\n */\n sidebarTitle?: string\n /**\n * Auto close after all screens complete successfully.\n * Set to true for default delay (5000ms), or specify delay in milliseconds.\n */\n autoClose?: boolean | number\n /**\n * Theme preset name ('dark', 'light', 'high-contrast') or custom theme object.\n */\n theme?: string | Record<string, unknown>\n /**\n * Enable mouse support.\n * @default false\n */\n useMouse?: boolean\n /**\n * Hide the default console logger screen from the sidebar.\n * @default false\n */\n hideDefaultScreen?: boolean\n /**\n * Use OpenTUI for terminal rendering.\n * When true: Full TUI with sidebar, scrolling, interactive prompts.\n * When false: Stdout mode - static screens print immediately, others on completion.\n * @default true for Node.js, false for Bun (OpenTUI not supported)\n */\n useOpenTUI?: boolean\n}\n/**\n * Configuration options for CommanderFactory.\n *\n * @public\n */\nexport interface CommanderFactoryOptions {\n /**\n * Enabled log levels.\n * @default ['log', 'error', 'warn', 'debug', 'verbose', 'fatal']\n */\n logLevels?: LogLevel[]\n /**\n * Logger display options. These override the default CLI-friendly logger settings.\n * Ignored when enableTUI is true.\n */\n logger?: CommanderLoggerOptions\n /**\n * Enable TUI mode with @navios/commander-tui.\n * Requires @navios/commander-tui to be installed.\n */\n enableTUI?: boolean\n /**\n * TUI-specific options. Only used when enableTUI is true.\n */\n tuiOptions?: CommanderTuiOptions\n}\n/**\n * Factory class for creating CLI applications.\n *\n * This is a convenience wrapper around `NaviosFactory.create()` that\n * configures everything needed for CLI usage. It sets up the CLI adapter\n * and returns a typed `NaviosApplication<CliEnvironment>`.\n *\n * @example\n * ```typescript\n * import { CommanderFactory } from '@navios/commander'\n * import { AppModule } from './app.module'\n *\n * async function bootstrap() {\n * const app = await CommanderFactory.create(AppModule)\n * await app.init()\n *\n * const adapter = app.getAdapter()\n * await adapter.run(process.argv)\n *\n * await app.close()\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Alternative: use NaviosFactory directly\n * import { NaviosFactory } from '@navios/core'\n * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'\n *\n * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {\n * adapter: defineCliEnvironment(),\n * })\n * ```\n */\nexport declare class CommanderFactory {\n /**\n * Creates a new CLI application instance configured with the provided module.\n *\n * @param appModule - The root CLI module class decorated with `@CliModule`\n * @param options - Optional configuration options for the CLI application\n * @returns A promise that resolves to a configured NaviosApplication instance\n *\n * @example\n * ```typescript\n * const app = await CommanderFactory.create(AppModule)\n * await app.init()\n *\n * const adapter = app.getAdapter()\n * await adapter.run(process.argv)\n * ```\n */\n static create<TModule extends NaviosModule = NaviosModule>(\n appModule: ClassTypeWithInstance<TModule>,\n options?: CommanderFactoryOptions,\n ): Promise<NaviosApplication<CliEnvironment>>\n}\n//# sourceMappingURL=commander.factory.d.mts.map\n","import type { z } from 'zod/v4'\n/**\n * Result of parsing command-line arguments.\n *\n * @public\n */\nexport interface ParsedCliArgs {\n /**\n * The command path (e.g., 'greet', 'user:create').\n * Multi-word commands are joined with spaces.\n */\n command: string\n /**\n * Parsed options as key-value pairs.\n * Keys are converted from kebab-case to camelCase.\n * Supports object notation (e.g., --obj.field=value creates { obj: { field: value } }).\n */\n options: Record<string, any>\n /**\n * Positional arguments that don't match any option flags.\n */\n positionals: string[]\n}\n/**\n * Service for parsing command-line arguments.\n *\n * Handles parsing of various CLI argument formats including:\n * - Long options: `--key value` or `--key=value`\n * - Short options: `-k value` or `-abc` (multiple flags)\n * - Boolean flags\n * - Array options\n * - Positional arguments\n * - Object notation: `--obj.field=value` or `--obj.nested.field value`\n * Creates nested objects automatically (e.g., { obj: { field: value } })\n *\n * @public\n */\nexport declare class CliParserService {\n /**\n * Parses command-line arguments from process.argv\n * Commands can be multi-word (e.g., 'db migrate', 'cache clear')\n * Expected format: node script.js command [subcommand...] --flag value --boolean-flag positional1 positional2\n *\n * @param argv - Array of command-line arguments (typically process.argv)\n * @param optionsSchema - Optional zod/v4 schema to determine boolean flags and option types\n * @param availableCommands - Optional list of registered command paths for smart detection.\n * When provided, scans argv to find the best matching command, enabling support for\n * custom launchers (tsx, ts-node, npx, etc.) that add extra args before the command.\n * @returns Parsed command (space-separated if multi-word), options, and positional arguments\n */\n parse(argv: string[], optionsSchema?: z.ZodObject, availableCommands?: string[]): ParsedCliArgs\n /**\n * Finds the index in argv where the command starts by matching against available commands.\n * Prioritizes longer/more specific commands (e.g., 'db migrate' matches before 'db').\n *\n * @param argv - Full argv array\n * @param availableCommands - List of registered command paths\n * @returns Index where the command starts, or 2 as fallback\n */\n private findCommandStartIndex\n /**\n * Converts kebab-case to camelCase\n */\n private camelCase\n /**\n * Attempts to parse string values into appropriate types\n */\n private parseValue\n /**\n * Extracts boolean field names from a zod/v4 schema\n * Handles z.ZodObject, zod/v4Optional, and zod/v4Default wrappers\n */\n private extractBooleanFields\n /**\n * Extracts array field names from a zod/v4 schema\n * Handles z.ZodObject, zod/v4Optional, and zod/v4Default wrappers\n */\n private extractArrayFields\n /**\n * Checks if a zod/v4 schema represents a boolean type\n * Unwraps zod/v4Optional and zod/v4Default using zod/v4 v4 API\n */\n private isSchemaBoolean\n /**\n * Checks if a zod/v4 schema represents an array type\n * Unwraps zod/v4Optional and zod/v4Default using zod/v4 v4 API\n */\n private isSchemaArray\n /**\n * Sets a nested property on an object using dot notation path.\n * Creates intermediate objects as needed.\n *\n * @example\n * setNestedProperty({}, 'a.b.c', 'value') // { a: { b: { c: 'value' } } }\n */\n private setNestedProperty\n /**\n * Gets a nested property from an object using dot notation path.\n * Returns undefined if path doesn't exist.\n */\n private getNestedProperty\n /**\n * Checks if an option key contains dot notation (object notation).\n * Returns true for keys like \"obj.field\" or \"deep.nested.value\".\n */\n private isObjectNotation\n /**\n * Processes an option key that may contain object notation.\n * Converts each segment from kebab-case to camelCase.\n *\n * @example\n * processObjectNotationKey('my-obj.field-name') // 'myObj.fieldName'\n */\n private processObjectNotationKey\n /**\n * Gets the nested schema for a given dot-notation path.\n * Returns undefined if the path doesn't lead to a valid schema.\n */\n private getNestedSchema\n /**\n * Checks if a nested path represents a boolean field in the schema.\n */\n private isNestedBoolean\n /**\n * Checks if a nested path represents an array field in the schema.\n */\n private isNestedArray\n}\n//# sourceMappingURL=cli-parser.service.d.mts.map\n","import type { ClassType } from '@navios/core'\n/**\n * Symbol key for storing commands in ModuleMetadata.customEntries.\n * Used by @CliModule to store command classes.\n *\n * @public\n */\nexport declare const CommandEntryKey: unique symbol\n/**\n * Type for the command entry value stored in customEntries.\n *\n * @public\n */\nexport type CommandEntryValue = Set<ClassType>\n/**\n * Extracts commands from a module's metadata.\n * Returns empty set if no commands are defined.\n *\n * @param moduleClass - The module class decorated with @CliModule or @Module\n * @returns Set of command classes registered in the module\n *\n * @example\n * ```typescript\n * const commands = extractModuleCommands(AppModule)\n * for (const command of commands) {\n * console.log(command.name)\n * }\n * ```\n */\nexport declare function extractModuleCommands(moduleClass: ClassType): Set<ClassType>\n//# sourceMappingURL=command-entry.metadata.d.mts.map\n","import type { ClassType } from '@navios/core'\n\nimport type { CommandMetadata } from '../metadata/index.mjs'\n/**\n * Represents a registered command with its metadata and module information.\n *\n * @public\n */\nexport interface RegisteredCommand {\n /**\n * The command class\n */\n class: ClassType\n /**\n * The command metadata from @Command decorator\n */\n metadata: CommandMetadata\n /**\n * Name of the module this command belongs to\n */\n moduleName: string\n}\n/**\n * Service for registering and looking up CLI commands.\n * Used internally by the CLI adapter to manage discovered commands.\n *\n * @public\n */\nexport declare class CommandRegistryService {\n private commands\n /**\n * Register a command with its metadata.\n *\n * @param path - The command path (e.g., 'greet', 'user:create')\n * @param command - The registered command data\n * @throws Error if a command with the same path is already registered\n */\n register(path: string, command: RegisteredCommand): void\n /**\n * Get a command by its path.\n *\n * @param path - The command path\n * @returns The registered command or undefined if not found\n */\n getByPath(path: string): RegisteredCommand | undefined\n /**\n * Get all registered commands.\n *\n * @returns Map of path to registered command\n */\n getAll(): Map<string, RegisteredCommand>\n /**\n * Get all registered commands as an array of path and class pairs.\n * Useful for listing available commands.\n *\n * @returns Array of objects containing path and class\n */\n getAllAsArray(): Array<{\n path: string\n class: ClassType\n }>\n /**\n * Formats help text listing all available commands with descriptions.\n *\n * @returns Formatted string listing all commands\n */\n formatCommandList(): string\n /**\n * Formats help text for a specific command.\n *\n * @param commandPath - The command path to show help for\n * @returns Formatted string with command help\n */\n formatCommandHelp(commandPath: string): string\n /**\n * Recursively formats nested object options for help display.\n * Shows nested fields with dot notation (e.g., --config.port)\n */\n private formatNestedObjectOptions\n /**\n * Gets a human-readable type name from a zod/v4 schema.\n */\n private getSchemaTypeName\n /**\n * Gets metadata from a zod/v4 schema, traversing innerType if needed.\n * zod/v4 v4 stores meta at the outermost layer when .meta() is called last,\n * or in innerType when .meta() is called before .optional()/.default().\n */\n private getSchemaMeta\n /**\n * Get all registered command paths.\n * Useful for smart command detection in argv parsing.\n *\n * @returns Array of command paths\n */\n getAllPaths(): string[]\n /**\n * Clear all registered commands.\n */\n clear(): void\n}\n//# sourceMappingURL=command-registry.service.d.mts.map\n","import type { ClassType, ModuleMetadata } from '@navios/core'\n\nimport type { AbstractCliAdapterInterface } from '../interfaces/abstract-cli-adapter.interface.mjs'\nimport type { CliAdapterOptions } from '../interfaces/environment.interface.mjs'\n/**\n * CLI adapter service that implements the AbstractCliAdapterInterface.\n * Handles command discovery, registration, parsing, and execution.\n *\n * @public\n */\nexport declare class CommanderAdapterService implements AbstractCliAdapterInterface {\n private container\n private commandRegistry\n private cliParser\n private logger\n private options\n private isReady\n /**\n * Sets up the adapter with the provided options.\n * Called during application initialization.\n */\n setupAdapter(options: CliAdapterOptions): Promise<void>\n /**\n * Called after all modules are loaded.\n * Iterates through modules and extracts commands from customEntries.\n */\n onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>\n /**\n * Registers built-in commands like help.\n */\n private registerBuiltInCommands\n /**\n * Signals that the adapter is ready to handle commands.\n */\n ready(): Promise<void>\n /**\n * Disposes of the adapter and cleans up resources.\n */\n dispose(): Promise<void>\n /**\n * Run the CLI application with the given arguments.\n * Parses arguments and executes the matching command.\n */\n run(argv?: string[]): Promise<void>\n /**\n * Execute a command programmatically with the provided options.\n */\n executeCommand(\n path: string,\n options?: Record<string, unknown>,\n positionals?: string[],\n ): Promise<void>\n /**\n * Get all registered command paths and their class references.\n */\n getAllCommands(): Array<{\n path: string\n class: ClassType\n }>\n}\n//# sourceMappingURL=commander-adapter.service.d.mts.map\n","import type { AnyInjectableType, InjectionToken } from '@navios/core'\n\nimport { CliParserService } from './services/cli-parser.service.mjs'\nimport { CommandRegistryService } from './services/command-registry.service.mjs'\nimport { CommanderAdapterService } from './services/commander-adapter.service.mjs'\n/**\n * Defines the CLI environment configuration for use with NaviosFactory.\n *\n * This function returns the token mappings needed to configure a CLI application.\n * Use it with `NaviosFactory.create()` to create a CLI application.\n *\n * @returns Environment configuration with token mappings\n *\n * @example\n * ```typescript\n * import { NaviosFactory } from '@navios/core'\n * import { defineCliEnvironment, type CliEnvironment } from '@navios/commander'\n *\n * const app = await NaviosFactory.create<CliEnvironment>(AppModule, {\n * adapter: defineCliEnvironment(),\n * })\n * await app.init()\n *\n * const adapter = app.getAdapter() as AbstractCliAdapterInterface\n * await adapter.run(process.argv)\n * ```\n */\nexport declare function defineCliEnvironment(): {\n tokens: Map<InjectionToken<any, undefined, false>, AnyInjectableType>\n}\nexport { CommanderAdapterService, CommandRegistryService, CliParserService }\n//# sourceMappingURL=define-environment.d.mts.map\n","import { InjectionToken } from '@navios/core'\n\nimport type { CommanderExecutionContext } from '../interfaces/index.mjs'\n/**\n * Injection token for accessing the current command execution context.\n *\n * Use this token with `inject()` to access the `CommanderExecutionContext` in services\n * that need information about the currently executing command.\n *\n * @example\n * ```typescript\n * import { inject, Injectable } from '@navios/core'\n * import { CommandExecutionContext } from '@navios/commander'\n *\n * @Injectable()\n * class MyService {\n * private ctx = inject(CommandExecutionContext)\n *\n * doSomething() {\n * const commandPath = this.ctx.getCommandPath()\n * const options = this.ctx.getOptions()\n * // Use context information...\n * }\n * }\n * ```\n */\nexport declare const CommandExecutionContext: InjectionToken<\n CommanderExecutionContext,\n undefined,\n false\n>\n//# sourceMappingURL=execution-context.token.d.mts.map\n"],"mappings":";;;;;;cAGcE,mBAAmBF,CAAAA,CAAEO;WAEtBP,CAAAA,CAAEI,YAAYJ,CAAAA,CAAEG;GAE3BH,CAAAA,CAAEK,IAAAA,CAAKC,MAJKJ,CAEaF;KAItBQ,WAAAA,GAAcR,CAAAA,CAAES,KAJNL,CAAAA,OAImBF,iBAJnBE,CAAAA;;;;AAF6B;AAY5C;AAA2DI,cAAtCE,WAAAA,YAAuBT,cAAeO,CAAAA,WAAAA,CAAAA,CAAAA;EAGxCA,QAAAA,MAAAA;EAAcG,QAAAA,eAAAA;EAHWV,OAAAA,CAAAA,OAAAA,EAGzBO,WAHyBP,CAAAA,EAGXU,OAHWV,CAAAA,IAAAA,CAAAA;;;;;;;;AAbqC;;AAGlEG,UCIEa,sBAAAA,CDJFb;EAEbJ;;;AAJ0C;EAY5C,SAAqBU,CAAAA,ECDPG,QDCkB,EAAA;EAA2BL;;;;EAAD,OAAA,CAAA,EAAA,OAAA;;;;ACN1D;EA2CA,YAAiBU,CAAAA,EAAAA,OAAAA;EAuDjB;;;;EAmBkC,UAAA,CAAA,EAAA,OAAA;EAoClC;;;;EAkBeN,WAAAA,CAAAA,EAAAA,OAAAA;EACDQ;;;;EACF,aAAA,CAAA,EAAA,OAAA;;;;AChLZ;EA+BA,YAAqBO,CAAAA,EAAAA,OAAgB;;;;AC9BrC;AAMA;AAgBA;;AAA2EE,UFuB1DX,mBAAAA,CEvB0DW;EAAJG;;;;;ECrBvE;AAoBA;;;EAsBwBI,OAAAA,CAAAA,EAAAA,OAAAA,GAAAA,OAAAA,GAAAA,KAAAA,GAAAA,MAAAA;EAAZE;;;EAOY,YAAA,CAAA,EAAA,MAAA;;;;EC/CxB,eAAqBM,CAAAA,EAAAA,MAAAA,GAAAA,OAAuB;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CA;AAuDA;AAKcL,cMtFO6C,uBNsFP7C,EMtFgC2C,cNsFhC3C,CMrFZ4C,yBN0FSxC,EASIC,SAAAA,EAAmB,KAAA,CAoClC"}
package/lib/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { a as extractCommandMetadata, i as CommandMetadataKey, n as CommandEntryKey, o as getCommandMetadata, r as extractModuleCommands, s as hasCommandMetadata, t as Command } from "./command.decorator-QiRU7ny3.mjs";
2
- import { n as _CommandRegistryService, t as HelpCommandToken } from "./help-command.token-XHx3WkoD.mjs";
2
+ import { n as _CommandRegistryService, t as HelpCommandToken } from "./help-command.token-D81bRnnl.mjs";
3
3
  import { t as CliModule } from "./cli-module.decorator-DAjf_r_W.mjs";
4
4
  import { AdapterToken, ConsoleLogger, Container, Injectable, InjectionToken, Logger, NaviosFactory, inject } from "@navios/core";
5
5
  import { z } from "zod/v4";
@@ -601,9 +601,13 @@ var CliParserService = class {
601
601
  *
602
602
  * @param argv - Array of command-line arguments (typically process.argv)
603
603
  * @param optionsSchema - Optional zod/v4 schema to determine boolean flags and option types
604
+ * @param availableCommands - Optional list of registered command paths for smart detection.
605
+ * When provided, scans argv to find the best matching command, enabling support for
606
+ * custom launchers (tsx, ts-node, npx, etc.) that add extra args before the command.
604
607
  * @returns Parsed command (space-separated if multi-word), options, and positional arguments
605
- */ parse(argv, optionsSchema) {
606
- const args = argv.slice(2);
608
+ */ parse(argv, optionsSchema, availableCommands) {
609
+ const startIndex = availableCommands?.length ? this.findCommandStartIndex(argv, availableCommands) : 2;
610
+ const args = argv.slice(startIndex);
607
611
  if (args.length === 0) throw new Error("[Navios Commander] No command provided");
608
612
  const booleanFields = optionsSchema ? this.extractBooleanFields(optionsSchema) : /* @__PURE__ */ new Set();
609
613
  const arrayFields = optionsSchema ? this.extractArrayFields(optionsSchema) : /* @__PURE__ */ new Set();
@@ -625,12 +629,41 @@ var CliParserService = class {
625
629
  if (equalIndex !== -1) {
626
630
  const optionName = key.slice(0, equalIndex);
627
631
  const optionValue = key.slice(equalIndex + 1);
628
- const camelCaseKey = this.camelCase(optionName);
629
- if (arrayFields.has(camelCaseKey) || arrayFields.has(optionName)) {
630
- if (!options[camelCaseKey]) options[camelCaseKey] = [];
631
- options[camelCaseKey].push(this.parseValue(optionValue));
632
- } else options[camelCaseKey] = this.parseValue(optionValue);
632
+ if (this.isObjectNotation(optionName)) {
633
+ const processedPath = this.processObjectNotationKey(optionName);
634
+ if (optionsSchema ? this.isNestedArray(optionsSchema, processedPath) : false) {
635
+ const existingValue = this.getNestedProperty(options, processedPath);
636
+ if (!Array.isArray(existingValue)) this.setNestedProperty(options, processedPath, []);
637
+ this.getNestedProperty(options, processedPath).push(this.parseValue(optionValue));
638
+ } else this.setNestedProperty(options, processedPath, this.parseValue(optionValue));
639
+ } else {
640
+ const camelCaseKey = this.camelCase(optionName);
641
+ if (arrayFields.has(camelCaseKey) || arrayFields.has(optionName)) {
642
+ if (!options[camelCaseKey]) options[camelCaseKey] = [];
643
+ options[camelCaseKey].push(this.parseValue(optionValue));
644
+ } else options[camelCaseKey] = this.parseValue(optionValue);
645
+ }
633
646
  i++;
647
+ } else if (this.isObjectNotation(key)) {
648
+ const processedPath = this.processObjectNotationKey(key);
649
+ const isBoolean = optionsSchema ? this.isNestedBoolean(optionsSchema, processedPath) : false;
650
+ const isArray = optionsSchema ? this.isNestedArray(optionsSchema, processedPath) : false;
651
+ const nextArg = args[i + 1];
652
+ if (isBoolean) {
653
+ this.setNestedProperty(options, processedPath, true);
654
+ i++;
655
+ } else if (isArray && nextArg && !nextArg.startsWith("-")) {
656
+ const existingValue = this.getNestedProperty(options, processedPath);
657
+ if (!Array.isArray(existingValue)) this.setNestedProperty(options, processedPath, []);
658
+ this.getNestedProperty(options, processedPath).push(this.parseValue(nextArg));
659
+ i += 2;
660
+ } else if (nextArg && !nextArg.startsWith("-")) {
661
+ this.setNestedProperty(options, processedPath, this.parseValue(nextArg));
662
+ i += 2;
663
+ } else {
664
+ this.setNestedProperty(options, processedPath, true);
665
+ i++;
666
+ }
634
667
  } else {
635
668
  const camelCaseKey = this.camelCase(key);
636
669
  const isBoolean = booleanFields.has(camelCaseKey) || booleanFields.has(key);
@@ -687,6 +720,28 @@ var CliParserService = class {
687
720
  };
688
721
  }
689
722
  /**
723
+ * Finds the index in argv where the command starts by matching against available commands.
724
+ * Prioritizes longer/more specific commands (e.g., 'db migrate' matches before 'db').
725
+ *
726
+ * @param argv - Full argv array
727
+ * @param availableCommands - List of registered command paths
728
+ * @returns Index where the command starts, or 2 as fallback
729
+ */ findCommandStartIndex(argv, availableCommands) {
730
+ const sortedCommands = [...availableCommands].sort((a, b) => {
731
+ const aParts = a.split(" ").length;
732
+ const bParts = b.split(" ").length;
733
+ if (bParts !== aParts) return bParts - aParts;
734
+ return b.length - a.length;
735
+ });
736
+ for (let startIdx = 1; startIdx < argv.length; startIdx++) for (const cmd of sortedCommands) {
737
+ const cmdParts = cmd.split(" ");
738
+ const endIdx = startIdx + cmdParts.length;
739
+ if (endIdx > argv.length) continue;
740
+ if (argv.slice(startIdx, endIdx).join(" ") === cmd) return startIdx;
741
+ }
742
+ return 2;
743
+ }
744
+ /**
690
745
  * Converts kebab-case to camelCase
691
746
  */ camelCase(str) {
692
747
  return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
@@ -769,6 +824,80 @@ var CliParserService = class {
769
824
  return false;
770
825
  }
771
826
  }
827
+ /**
828
+ * Sets a nested property on an object using dot notation path.
829
+ * Creates intermediate objects as needed.
830
+ *
831
+ * @example
832
+ * setNestedProperty({}, 'a.b.c', 'value') // { a: { b: { c: 'value' } } }
833
+ */ setNestedProperty(obj, path, value) {
834
+ const parts = path.split(".");
835
+ let current = obj;
836
+ for (let i = 0; i < parts.length - 1; i++) {
837
+ const part = parts[i];
838
+ if (!(part in current) || typeof current[part] !== "object" || current[part] === null) current[part] = {};
839
+ current = current[part];
840
+ }
841
+ current[parts[parts.length - 1]] = value;
842
+ }
843
+ /**
844
+ * Gets a nested property from an object using dot notation path.
845
+ * Returns undefined if path doesn't exist.
846
+ */ getNestedProperty(obj, path) {
847
+ const parts = path.split(".");
848
+ let current = obj;
849
+ for (const part of parts) {
850
+ if (current === void 0 || current === null || typeof current !== "object") return;
851
+ current = current[part];
852
+ }
853
+ return current;
854
+ }
855
+ /**
856
+ * Checks if an option key contains dot notation (object notation).
857
+ * Returns true for keys like "obj.field" or "deep.nested.value".
858
+ */ isObjectNotation(key) {
859
+ return key.includes(".");
860
+ }
861
+ /**
862
+ * Processes an option key that may contain object notation.
863
+ * Converts each segment from kebab-case to camelCase.
864
+ *
865
+ * @example
866
+ * processObjectNotationKey('my-obj.field-name') // 'myObj.fieldName'
867
+ */ processObjectNotationKey(key) {
868
+ return key.split(".").map((segment) => this.camelCase(segment)).join(".");
869
+ }
870
+ /**
871
+ * Gets the nested schema for a given dot-notation path.
872
+ * Returns undefined if the path doesn't lead to a valid schema.
873
+ */ getNestedSchema(schema, path) {
874
+ try {
875
+ const parts = path.split(".");
876
+ let currentSchema = schema;
877
+ for (const part of parts) {
878
+ while (currentSchema?.def?.type === "optional" || currentSchema?.def?.type === "default") currentSchema = currentSchema.def.innerType;
879
+ if (currentSchema?.def?.type !== "object") return;
880
+ const shape = currentSchema.def.shape;
881
+ if (!shape || !(part in shape)) return;
882
+ currentSchema = shape[part];
883
+ }
884
+ return currentSchema;
885
+ } catch {
886
+ return;
887
+ }
888
+ }
889
+ /**
890
+ * Checks if a nested path represents a boolean field in the schema.
891
+ */ isNestedBoolean(schema, path) {
892
+ const nestedSchema = this.getNestedSchema(schema, path);
893
+ return nestedSchema ? this.isSchemaBoolean(nestedSchema) : false;
894
+ }
895
+ /**
896
+ * Checks if a nested path represents an array field in the schema.
897
+ */ isNestedArray(schema, path) {
898
+ const nestedSchema = this.getNestedSchema(schema, path);
899
+ return nestedSchema ? this.isSchemaArray(nestedSchema) : false;
900
+ }
772
901
  static {
773
902
  _initClass$1();
774
903
  }
@@ -1220,14 +1349,15 @@ var CommanderAdapterService = class {
1220
1349
  */ async run(argv = process.argv) {
1221
1350
  if (!this.isReady) throw new Error("Adapter not ready. Call app.init() first.");
1222
1351
  try {
1223
- const preliminaryParse = this.cliParser.parse(argv);
1352
+ const commandPaths = this.commandRegistry.getAllPaths();
1353
+ const preliminaryParse = this.cliParser.parse(argv, void 0, commandPaths);
1224
1354
  if (preliminaryParse.options.help || preliminaryParse.options.h) {
1225
1355
  if (preliminaryParse.command === "help") await this.executeCommand("help", {});
1226
1356
  else await this.executeCommand("help", { command: preliminaryParse.command });
1227
1357
  return;
1228
1358
  }
1229
1359
  const command = this.commandRegistry.getByPath(preliminaryParse.command);
1230
- const parsed = command?.metadata.optionsSchema ? this.cliParser.parse(argv, command.metadata.optionsSchema) : preliminaryParse;
1360
+ const parsed = command?.metadata.optionsSchema ? this.cliParser.parse(argv, command.metadata.optionsSchema, commandPaths) : preliminaryParse;
1231
1361
  await this.executeCommand(parsed.command, parsed.options, parsed.positionals);
1232
1362
  } catch (error) {
1233
1363
  if (error instanceof Error) {
@@ -1374,7 +1504,7 @@ function dynamicImport(modulePath) {
1374
1504
  }
1375
1505
  const { overrideConsoleLogger, ScreenManager } = tuiModule;
1376
1506
  overrideConsoleLogger(options.tuiOptions?.hideDefaultScreen ?? false);
1377
- if (options.tuiOptions?.hideDefaultScreen) await import("./help.command-Bynoll_7.mjs");
1507
+ if (options.tuiOptions?.hideDefaultScreen) await import("./help.command-B14cbwE_.mjs");
1378
1508
  const app = await NaviosFactory.create(appModule, {
1379
1509
  adapter: defineCliEnvironment(),
1380
1510
  logger: options.logLevels