mecha10_cli/lib.rs
1//! Mecha10 CLI Library
2//!
3//! This crate provides both a command-line interface and a library API for managing
4//! Mecha10 robot projects. The library can be used programmatically by other tools.
5//!
6//! # Architecture
7//!
8//! The CLI follows a 3-layer architecture for maintainability and testability:
9//!
10//! ```text
11//! Commands (clap Args) → Pure data structures, no logic
12//! ↓
13//! Handlers (orchestration) → Coordinate services, handle UI
14//! ↓
15//! Services (business logic)→ Reusable, testable logic
16//! ↓
17//! Mecha10 Core (framework) → Message passing runtime
18//! ```
19//!
20//! # Library Usage
21//!
22//! ## Basic Project Operations
23//!
24//! ```rust,no_run
25//! use mecha10_cli::{CliContext, services::ProjectService};
26//! use std::path::Path;
27//!
28//! # async fn example() -> anyhow::Result<()> {
29//! // Detect a Mecha10 project
30//! let project = ProjectService::detect(Path::new("."))?;
31//! println!("Project: {} v{}", project.name()?, project.version()?);
32//!
33//! // List project components
34//! let nodes = project.list_nodes()?;
35//! let drivers = project.list_drivers()?;
36//! println!("Nodes: {:?}", nodes);
37//! println!("Drivers: {:?}", drivers);
38//!
39//! // Validate project structure
40//! project.validate()?;
41//! # Ok(())
42//! # }
43//! ```
44//!
45//! ## Working with Docker
46//!
47//! ```rust,no_run
48//! use mecha10_cli::services::DockerService;
49//!
50//! # async fn example() -> anyhow::Result<()> {
51//! let docker = DockerService::new();
52//!
53//! // Check Docker availability
54//! docker.check_installation()?;
55//! docker.check_daemon()?;
56//!
57//! // Manage services
58//! docker.compose_up(true).await?;
59//! let containers = docker.list_containers().await?;
60//!
61//! for container in containers {
62//! println!("{}: {}", container.name, container.status);
63//! }
64//! # Ok(())
65//! # }
66//! ```
67//!
68//! ## Using CliContext
69//!
70//! ```rust,no_run
71//! use mecha10_cli::CliContextBuilder;
72//! use tracing::Level;
73//!
74//! # async fn example() -> anyhow::Result<()> {
75//! // Build a context with custom settings
76//! let ctx = CliContextBuilder::new()
77//! .redis_url("redis://localhost:6380".to_string())
78//! .log_level(Level::DEBUG)
79//! .verbose(true)
80//! .build()?;
81//!
82//! // Access services through context
83//! let docker = ctx.docker();
84//! let redis = ctx.redis()?;
85//!
86//! // Services are lazy-initialized
87//! let project = ctx.project()?;
88//! # Ok(())
89//! # }
90//! ```
91//!
92//! ## Configuration Management
93//!
94//! ```rust,no_run
95//! use mecha10_cli::services::ConfigService;
96//! use std::path::Path;
97//!
98//! # async fn example() -> anyhow::Result<()> {
99//! // Load configuration
100//! let config = ConfigService::load_default().await?;
101//! println!("Robot ID: {}", config.robot.id);
102//!
103//! // Load from specific path
104//! let config = ConfigService::load_from(Path::new("mecha10.json")).await?;
105//!
106//! // Check if initialized
107//! if ConfigService::is_initialized_here() {
108//! println!("Project is initialized");
109//! }
110//! # Ok(())
111//! # }
112//! ```
113
114// Public API exports
115pub use context::{CliContext, CliContextBuilder};
116
117// Re-export Level for tests and consumers
118pub use tracing::Level;
119
120// Public modules for library consumers
121pub mod dev;
122pub mod infrastructure;
123pub mod services;
124pub mod types;
125
126// Internal modules (not public)
127mod commands;
128mod component_catalog;
129mod context;
130mod framework;
131mod run;
132mod sim;
133mod templates;
134mod utils;
135
136// Re-export commonly used types
137pub use types::{Cli, Commands};