API Reference
Complete API reference for Navios Commander.
Decorators
@Command(options)
Decorator that marks a class as a CLI command.
Parameters:
options.path: string- The command path (e.g., 'greet', 'user:create', 'db:migrate')options.description?: string- Optional description for help textoptions.optionsSchema?: ZodObject- Optional Zod schema for validating command options
Returns: Class decorator function
Example:
@CliModule(options)
Decorator that marks a class as a CLI module.
Parameters:
options.commands?: ClassType[] | Set<ClassType>- Array or Set of command classesoptions.imports?: ClassType[] | Set<ClassType>- Array or Set of other modules to import
Returns: Class decorator function
Example:
Interfaces
CommandHandler<TOptions>
Interface that command classes must implement.
Parameters:
options: TOptions- The validated command options (validated against the command's schema if provided)
Returns: void | Promise<void>
Example:
CommandOptions
Options for the @Command decorator.
CliModuleOptions
Options for the @CliModule decorator.
CommandMetadata
Metadata for a command.
Classes
CommanderFactory
Factory class for creating CLI applications.
static create(appModule, options?)
Creates a new CommanderApplication instance.
Parameters:
appModule: ClassTypeWithInstance<NaviosModule>- The root CLI module classoptions?: CommanderApplicationOptions- Optional configuration options
Returns: Promise<CommanderApplication>
Example:
NaviosApplication
Main application class returned by CommanderFactory.create().
init()
Initializes the application by loading all modules and registering commands.
Returns: Promise<void>
Throws: Error if the app module is not set
Example:
getAdapter()
Gets the CLI adapter for running commands.
Returns: AbstractCliAdapterInterface
Example:
getContainer()
Gets the dependency injection container used by this application.
Returns: Container
Example:
close()
Closes the application and cleans up resources.
Returns: Promise<void>
Example:
AbstractCliAdapterInterface
CLI adapter interface returned by app.getAdapter().
run(argv?)
Runs the CLI application by parsing command-line arguments and executing the appropriate command.
Parameters:
argv?: string[]- Command-line arguments array (defaults toprocess.argv)
Returns: Promise<void>
Throws:
Errorif the application is not initializedErrorif no command is providedErrorif the command is not foundZodErrorif options validation fails
Example:
executeCommand(path, options?)
Executes a command programmatically with the provided options.
Parameters:
path: string- The command path (e.g., 'greet', 'user:create')options?: any- The command options object (will be validated if schema exists)
Returns: Promise<void>
Throws:
Errorif the application is not initializedErrorif the command is not foundErrorif the command does not implement the execute methodZodErrorif options validation fails
Example:
getAllCommands()
Gets all registered commands with their paths and class references.
Returns: Array<{ path: string; class: ClassType }>
Example:
CommanderExecutionContext
Execution context for a command execution. Provides access to command metadata, path, and validated options.
getCommand()
Gets the command metadata.
Returns: CommandMetadata
Example:
getCommandPath()
Gets the command path that was invoked.
Returns: string
Example:
getOptions()
Gets the validated command options.
Returns: any
Example:
Tokens
CommandExecutionContext
Injection token for accessing the command execution context.
Type: InjectionToken<CommanderExecutionContext>
Example:
Types
CommandOptions
Type for command decorator options.
CliModuleOptions
Type for CLI module decorator options.
CommandMetadata
Type for command metadata.
Services
CliParserService
Service for parsing command-line arguments.
Internal: This service is used internally by CommanderApplication and is not typically accessed directly.
CliModuleLoaderService
Service for loading CLI modules and collecting command metadata.
Internal: This service is used internally by CommanderApplication and is not typically accessed directly.
Error Types
ZodError
Thrown when command options fail validation against the provided Zod schema.
Source: Zod library
Example:
Integration with @navios/di
All @navios/di types and functions are re-exported from @navios/commander:
InjectableInjectableScopeInjectionTokeninjectasyncInjectoptionalContainerRegistry- And more...
See the DI documentation for complete details.
Integration with @navios/core
Navios Commander uses @navios/core for module support:
NaviosModuleinterface for module lifecycle hooksClassTypeandClassTypeWithInstancetypes- Module initialization hooks
See the Core documentation for more details.