Skip to main content

ubt_cli/commands/
config.rs

1use crate::config::load_config;
2use crate::error::UbtError;
3
4pub fn cmd_config_show() -> Result<(), UbtError> {
5    let cwd = std::env::current_dir()?;
6    match load_config(&cwd)? {
7        Some((config, root)) => {
8            println!("Config file: {}", root.join("ubt.toml").display());
9            if let Some(project) = &config.project
10                && let Some(tool) = &project.tool
11            {
12                println!("Tool: {tool}");
13            }
14            if !config.commands.is_empty() {
15                println!("\nCommands:");
16                let mut keys: Vec<_> = config.commands.keys().collect();
17                keys.sort();
18                for key in keys {
19                    println!("  {key} = {:?}", config.commands[key]);
20                }
21            }
22            if !config.aliases.is_empty() {
23                println!("\nAliases:");
24                let mut keys: Vec<_> = config.aliases.keys().collect();
25                keys.sort();
26                for key in keys {
27                    println!("  {key} = {:?}", config.aliases[key]);
28                }
29            }
30            Ok(())
31        }
32        None => {
33            println!("No ubt.toml found.");
34            Ok(())
35        }
36    }
37}