use anyhow::Result;
use clap::{Parser, Subcommand};
use rmpca::commands;
#[derive(Parser)]
#[command(name = "rmpca")]
#[command(about = "Unified CLI for rmp.ca operations", long_about = None)]
#[command(version)]
#[command(long_about = rmpca_long_help())]
struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(long, global = true, env = "RMPCA_JSON_LOGS")]
json: bool,
}
#[derive(Subcommand)]
enum Commands {
ExtractOverture(commands::extract_overture::Args),
ExtractOsm(commands::extract_osm::Args),
#[command(alias = "cache-map")]
CompileMap(commands::compile_map::Args),
#[command(aliases = &["opt"])]
Optimize(commands::optimize::Args),
Clean(commands::clean::Args),
Validate(commands::validate::Args),
Pipeline(commands::pipeline::Args),
Status(commands::status::Args),
Logs(commands::logs::Args),
#[command(alias = "proptest")]
TestProperties,
}
fn rmpca_long_help() -> &'static str {
r#"
rmpca — Enterprise-grade route optimization CLI
Quick Start:
rmpca compile-map city.geojson # Compile map once (5-30s)
rmpca optimize --cache city.rmp # Optimize instantly (1-5ms!)
Configuration (Priority: CLI > Env > Config File > Defaults):
RouteMaster.toml - User configuration file (~/.config/RouteMaster.toml)
RMPCA_* env vars - Environment variable overrides
--flag arguments - Command-line flags (highest priority)
Enterprise Features:
• Graph caching - Subsequent optimizations: 1000x faster
• Lean 4 FFI - Formal verification via compiled Lean 4 proofs
• Property tests - Mathematically rigorous algorithm testing
• JSON telemetry - Structured logs for frontend integration
• Layered config - Flexible profiles for trucks, cars, etc.
For help with a specific command: rmpca <command> --help
"#
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
let config = rmpca::config::Config::load().unwrap_or_else(|e| {
eprintln!("Warning: Failed to load configuration: {}", e);
rmpca::config::Config::default()
});
config.init_logging();
tracing::info!("rmpca v{} starting", env!("CARGO_PKG_VERSION"));
match cli.command {
Commands::ExtractOverture(args) => commands::extract_overture::run(args).await,
Commands::ExtractOsm(args) => commands::extract_osm::run(args).await,
Commands::CompileMap(args) => commands::compile_map::run(args).await,
Commands::Optimize(args) => commands::optimize::run(args).await,
Commands::Clean(args) => commands::clean::run(args).await,
Commands::Validate(args) => commands::validate::run(args).await,
Commands::Pipeline(args) => commands::pipeline::run(args).await,
Commands::Status(args) => commands::status::run(args).await,
Commands::Logs(args) => commands::logs::run(args).await,
Commands::TestProperties => {
eprintln!("Running property-based tests...");
eprintln!("This tests algorithmic invariants across random inputs.");
eprintln!("Use: cargo test --release --tests property_tests");
Ok(())
}
}
}