Skip to main content

codex_cli/
config.rs

1use nils_common::shell::{SingleQuoteEscapeStyle, quote_posix_single_with_style};
2
3pub fn show() -> i32 {
4    let snapshot = crate::runtime::config_snapshot();
5
6    println!("CODEX_CLI_MODEL={}", snapshot.model);
7    println!("CODEX_CLI_REASONING={}", snapshot.reasoning);
8    println!(
9        "CODEX_ALLOW_DANGEROUS_ENABLED={}",
10        snapshot.allow_dangerous_enabled_raw
11    );
12
13    if let Some(path) = snapshot.secret_dir {
14        println!("CODEX_SECRET_DIR={}", path.to_string_lossy());
15    } else {
16        println!("CODEX_SECRET_DIR=");
17    }
18
19    if let Some(path) = snapshot.auth_file {
20        println!("CODEX_AUTH_FILE={}", path.to_string_lossy());
21    } else {
22        println!("CODEX_AUTH_FILE=");
23    }
24
25    if let Some(path) = snapshot.secret_cache_dir {
26        println!("CODEX_SECRET_CACHE_DIR={}", path.to_string_lossy());
27    } else {
28        println!("CODEX_SECRET_CACHE_DIR=");
29    }
30
31    println!("CODEX_STARSHIP_ENABLED={}", snapshot.starship_enabled);
32    println!(
33        "CODEX_AUTO_REFRESH_ENABLED={}",
34        snapshot.auto_refresh_enabled
35    );
36    println!(
37        "CODEX_AUTO_REFRESH_MIN_DAYS={}",
38        snapshot.auto_refresh_min_days
39    );
40
41    0
42}
43
44pub fn set(key: &str, value: &str) -> i32 {
45    match key {
46        "model" | "CODEX_CLI_MODEL" => {
47            println!(
48                "export CODEX_CLI_MODEL={}",
49                quote_posix_single_with_style(value, SingleQuoteEscapeStyle::DoubleQuoteBoundary)
50            );
51            0
52        }
53        "reasoning" | "reason" | "CODEX_CLI_REASONING" => {
54            println!(
55                "export CODEX_CLI_REASONING={}",
56                quote_posix_single_with_style(value, SingleQuoteEscapeStyle::DoubleQuoteBoundary)
57            );
58            0
59        }
60        "dangerous" | "allow-dangerous" | "CODEX_ALLOW_DANGEROUS_ENABLED" => {
61            let lowered = value.trim().to_ascii_lowercase();
62            if lowered != "true" && lowered != "false" {
63                eprintln!(
64                    "codex-cli config: dangerous must be true|false (got: {})",
65                    value
66                );
67                return 64;
68            }
69            println!("export CODEX_ALLOW_DANGEROUS_ENABLED={}", lowered);
70            0
71        }
72        _ => {
73            eprintln!("codex-cli config: unknown key: {key}");
74            eprintln!("codex-cli config: keys: model|reasoning|dangerous");
75            64
76        }
77    }
78}