xbp 0.5.0

XBP is a build pack and deployment management tool to deploy, rust, nextjs etc and manage the NGINX configs below it
Documentation
//! Config command module
//!
//! Locates and prints `xbp.json` from either `.xbp/xbp.json` or `./xbp.json`.
//! When debug is enabled, prints resolution details and raw JSON.
use std::env;
use std::fs;
use std::path::PathBuf;

/// Execute the `config` command.
///
/// Prints discovered configuration keys and values in a simple aligned table.
/// Returns `Ok(())` even when no config is found to keep UX friendly.
pub async fn run_config(debug: bool) -> Result<(), String> {
    let current_dir: PathBuf = env::current_dir().map_err(|e| format!("Failed to get current directory: {}", e))?;
    let xbp_json_path_dotfolder: PathBuf = current_dir.join(".xbp/xbp.json");
    let xbp_json_path_root: PathBuf = current_dir.join("xbp.json");

    if debug {
        println!("[DEBUG] Current dir: {}", current_dir.display());
        println!("[DEBUG] Checking for: {}", xbp_json_path_dotfolder.display());
        println!("[DEBUG] Checking for: {}", xbp_json_path_root.display());
    }

    let (found_path, found_location) = if xbp_json_path_dotfolder.exists() {
        (Some(xbp_json_path_dotfolder), Some(".xbp/xbp.json"))
    } else if xbp_json_path_root.exists() {
        (Some(xbp_json_path_root), Some("xbp.json"))
    } else {
        (None, None)
    };

    if let (Some(path), Some(location)) = (found_path, found_location) {
        println!("Found xbp.json at: {}", path.display());

        match fs::read_to_string(&path) {
            Ok(contents) => {
                if debug {
                    println!("[DEBUG] xbp.json contents: {}", contents);
                }
                if let Ok(json_data) = serde_json::from_str::<serde_json::Value>(&contents) {
                    for (key, value) in json_data.as_object().unwrap() {
                        let value_str: String = value.to_string().replace("\"", "");
                        println!("{:<15} |   {}", key, value_str);
                    }
                } else {
                    eprintln!(
                        "\x1b[91mFailed to parse {} contents as JSON.\x1b[0m",
                        location
                    );
                }
            }
            Err(e) => {
                eprintln!("\x1b[91mFailed to read {}: {}\x1b[0m", location, e);
            }
        }
    } else {
        println!("\x1b[91mNo .xbp/xbp.json or xbp.json found in the current directory.\x1b[0m");
    }

    Ok(())
}