Expand description
Mecha10 CLI Library
This crate provides both a command-line interface and a library API for managing Mecha10 robot projects. The library can be used programmatically by other tools.
§Architecture
The CLI follows a 3-layer architecture for maintainability and testability:
Commands (clap Args) → Pure data structures, no logic
↓
Handlers (orchestration) → Coordinate services, handle UI
↓
Services (business logic)→ Reusable, testable logic
↓
Mecha10 Core (framework) → Message passing runtime§Library Usage
§Basic Project Operations
use mecha10_cli::{CliContext, services::ProjectService};
use std::path::Path;
// Detect a Mecha10 project
let project = ProjectService::detect(Path::new("."))?;
println!("Project: {} v{}", project.name()?, project.version()?);
// List project components
let nodes = project.list_nodes()?;
let drivers = project.list_drivers()?;
println!("Nodes: {:?}", nodes);
println!("Drivers: {:?}", drivers);
// Validate project structure
project.validate()?;§Working with Docker
use mecha10_cli::services::DockerService;
let docker = DockerService::new();
// Check Docker availability
docker.check_installation()?;
docker.check_daemon()?;
// Manage services
docker.compose_up(true).await?;
let containers = docker.list_containers().await?;
for container in containers {
println!("{}: {}", container.name, container.status);
}§Using CliContext
use mecha10_cli::CliContextBuilder;
use tracing::Level;
// Build a context with custom settings
let ctx = CliContextBuilder::new()
.redis_url("redis://localhost:6380".to_string())
.log_level(Level::DEBUG)
.verbose(true)
.build()?;
// Access services through context
let docker = ctx.docker();
let redis = ctx.redis()?;
// Services are lazy-initialized
let project = ctx.project()?;§Configuration Management
use mecha10_cli::services::ConfigService;
use std::path::Path;
// Load configuration
let config = ConfigService::load_default().await?;
println!("Robot ID: {}", config.robot.id);
// Load from specific path
let config = ConfigService::load_from(Path::new("mecha10.json")).await?;
// Check if initialized
if ConfigService::is_initialized_here() {
println!("Project is initialized");
}Re-exports§
Modules§
- dev
- Dev module - Support code for development mode
- infrastructure
- Infrastructure management module
- services
- Service layer for CLI business logic
- types
- Shared type definitions for the CLI
Structs§
- CliContext
- CLI execution context
- CliContext
Builder - Builder for CliContext with proper precedence handling
- Level
- Describes the level of verbosity of a span or event.