Skip to main content

rbnx/cmd/
config.rs

1// SPDX-License-Identifier: MulanPSL-2.0
2// Config Command Module
3//
4// Config command implementation for robonix-cli
5
6use anyhow::Result;
7use colored::*;
8use robonix_cli::Config;
9use std::path::PathBuf;
10
11pub async fn execute(_config: Config, set_storage_path: Option<PathBuf>, show: bool) -> Result<()> {
12    let mut config = Config::load()?;
13    let mut updated = false;
14
15    if let Some(new_path) = set_storage_path {
16        config.package_storage_path = new_path;
17        config.save()?;
18        config.ensure_storage_dir()?;
19        println!(
20            "Package storage path updated to: {}",
21            config.package_storage_path.display()
22        );
23        updated = true;
24    }
25
26    if show {
27        // Get actual config file path and display real absolute path
28        let config_path = Config::config_file_path()?;
29        // Get canonical (real) path, resolving symlinks
30        let real_path = std::fs::canonicalize(&config_path).unwrap_or_else(|_| config_path.clone());
31
32        println!(
33            "Current robonix system config are located at: {}",
34            real_path.display().to_string().bold().cyan()
35        );
36        println!("\n{}", "Configuration:".bold().cyan());
37        let label1 = format!("{:<25}", "Package storage path:");
38        println!(
39            "  {} {}",
40            label1.bright_white(),
41            config.package_storage_path.display().to_string().white()
42        );
43        let label2 = format!("{:<25}", "Robonix source path:");
44        match &config.robonix_source_path {
45            Some(p) => println!(
46                "  {} {}",
47                label2.bright_white(),
48                p.display().to_string().white()
49            ),
50            None => println!(
51                "  {} {} ({})",
52                label2.bright_white(),
53                "<not set>".yellow(),
54                "run `rbnx setup` in the robonix repo".dimmed()
55            ),
56        }
57        println!();
58    } else if !updated {
59        eprintln!("Error: Either --set-storage-path or --show must be specified");
60        std::process::exit(1);
61    }
62
63    Ok(())
64}