Skip to main content

changepacks_cli/commands/
config.rs

1use anyhow::Result;
2use changepacks_utils::get_changepacks_config;
3use clap::Args;
4
5#[derive(Args, Debug)]
6#[command(about = "Change changepacks configuration")]
7pub struct ConfigArgs {}
8
9/// Display changepacks configuration
10///
11/// # Errors
12/// Returns error if reading the configuration fails.
13pub async fn handle_config(_args: &ConfigArgs) -> Result<()> {
14    let current_dir = std::env::current_dir()?;
15    let config = get_changepacks_config(&current_dir).await?;
16    println!("{}", serde_json::to_string_pretty(&config)?);
17    Ok(())
18}
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23    use clap::Parser;
24
25    #[derive(Parser)]
26    struct TestCli {
27        #[command(flatten)]
28        config: ConfigArgs,
29    }
30
31    #[test]
32    fn test_config_args_parsing() {
33        // ConfigArgs has no arguments, just verify it parses
34        let _cli = TestCli::parse_from(["test"]);
35    }
36
37    #[test]
38    fn test_config_args_debug() {
39        let args = ConfigArgs {};
40        let debug_str = format!("{:?}", args);
41        assert!(debug_str.contains("ConfigArgs"));
42    }
43}