Skip to main content

rbnx/
main.rs

1// SPDX-License-Identifier: MulanPSL-2.0
2// Robonix CLI Main Entry
3//
4// Main entry point for robonix-cli command-line tool
5
6use anyhow::Result;
7use clap::Parser;
8use robonix_cli::Config;
9
10mod cmd;
11mod pb;
12
13#[derive(Parser)]
14#[command(name = "rbnx")]
15#[command(version)]
16#[command(about = "Robonix helper CLI for package validation, build, and local orchestration", long_about = None)]
17struct Cli {
18    #[command(subcommand)]
19    command: cmd::Commands,
20}
21
22#[tokio::main]
23async fn main() -> Result<()> {
24    env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
25        .filter_module("rustdds", log::LevelFilter::Off)
26        .filter_module("ros2_client", log::LevelFilter::Warn)
27        .init();
28
29    let cli = Cli::parse();
30
31    let config = Config::load()?;
32    config.ensure_storage_dir()?;
33
34    // Enforce robonix_source_path migration: subcommands that build / start packages
35    // need the new ~/.robonix/config.yaml field. Exempt commands that bootstrap the
36    // config itself (Setup), read it (Config, Path), or operate purely on atlas (Nodes,
37    // Describe, Tools, Channels, Inspect, Chat, Graph, List, Info).
38    let needs_source = matches!(
39        &cli.command,
40        cmd::Commands::Build { .. }
41            | cmd::Commands::Start { .. }
42            | cmd::Commands::Validate { .. }
43            | cmd::Commands::Install { .. }
44            | cmd::Commands::Codegen { .. }
45    );
46    if needs_source {
47        let _ = config.require_source_path();
48    }
49
50    if let Err(e) = robonix_cli::PackageDatabase::sync(&config.package_storage_path) {
51        log::warn!("Package database sync failed: {}", e);
52    }
53
54    cmd::execute(cli.command, config).await?;
55
56    Ok(())
57}