Overview
Navios Commander is 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.
Package: @navios/commander
License: MIT
Peer Dependencies: @navios/di, zod (^4.0.0)
Installation
Core Concepts
Decorator-Based Commands
Commands are defined using the @Command decorator, similar to how controllers work in @navios/core. Commands implement the CommandHandler interface with an execute method.
Modular Architecture
Commands are organized into modules using the @CliModule decorator. Modules can import other modules to build complex CLI structures.
Dependency Injection
Full integration with @navios/di allows you to inject services into commands. All DI features are available, including scopes, lifecycle hooks, and injection tokens.
Schema Validation
Built-in support for Zod schemas to validate command options. Options are automatically validated and typed.
Key Features
Architecture
Command Lifecycle
- Registration - Commands are registered via
@Commanddecorator - Module Loading - Modules are loaded and commands are collected
- Initialization - Application initializes and prepares command handlers
- Execution - Commands are executed with validated options
- Cleanup - Resources are cleaned up after execution
Request Context
Each command execution runs in its own request context, allowing for:
- Request-scoped services
- Execution context access
- Isolated dependency resolution
Use Cases
CLI Tools
Build command-line tools with type-safe options and dependency injection.
Development Scripts
Create development scripts with validation and services.
Automation Workflows
Build automation workflows with programmatic command execution.
Integration with Navios Ecosystem
With @navios/di
Commander uses @navios/di for dependency injection. All DI features are available:
- Service injection with
inject() - Request-scoped services
- Lifecycle hooks
- Injection tokens
Learn more about dependency injection in commands.
With @navios/core
You can share services between your HTTP server and CLI commands, allowing code reuse across different entry points.
Next Steps
- Getting Started - Set up your first command
- Commands Guide - Learn how to create commands
- Modules Guide - Organize commands into modules
- Dependency Injection - Use DI in commands
- API Reference - Complete API documentation