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_CLI_EPHEMERAL_ENABLED={}",
10        std::env::var("CODEX_CLI_EPHEMERAL_ENABLED").unwrap_or_default()
11    );
12    println!(
13        "CODEX_ALLOW_DANGEROUS_ENABLED={}",
14        snapshot.allow_dangerous_enabled_raw
15    );
16
17    if let Some(path) = snapshot.secret_dir {
18        println!("CODEX_SECRET_DIR={}", path.to_string_lossy());
19    } else {
20        println!("CODEX_SECRET_DIR=");
21    }
22
23    if let Some(path) = snapshot.auth_file {
24        println!("CODEX_AUTH_FILE={}", path.to_string_lossy());
25    } else {
26        println!("CODEX_AUTH_FILE=");
27    }
28
29    if let Some(path) = snapshot.secret_cache_dir {
30        println!("CODEX_SECRET_CACHE_DIR={}", path.to_string_lossy());
31    } else {
32        println!("CODEX_SECRET_CACHE_DIR=");
33    }
34
35    println!(
36        "CODEX_PROMPT_SEGMENT_ENABLED={}",
37        snapshot.prompt_segment_enabled
38    );
39    println!(
40        "CODEX_AUTO_REFRESH_ENABLED={}",
41        snapshot.auto_refresh_enabled
42    );
43    println!(
44        "CODEX_AUTO_REFRESH_MIN_DAYS={}",
45        snapshot.auto_refresh_min_days
46    );
47
48    0
49}
50
51pub fn set(key: &str, value: &str) -> i32 {
52    match key {
53        "model" | "CODEX_CLI_MODEL" => {
54            println!(
55                "export CODEX_CLI_MODEL={}",
56                quote_posix_single_with_style(value, SingleQuoteEscapeStyle::DoubleQuoteBoundary)
57            );
58            0
59        }
60        "reasoning" | "reason" | "CODEX_CLI_REASONING" => {
61            println!(
62                "export CODEX_CLI_REASONING={}",
63                quote_posix_single_with_style(value, SingleQuoteEscapeStyle::DoubleQuoteBoundary)
64            );
65            0
66        }
67        "ephemeral" | "CODEX_CLI_EPHEMERAL_ENABLED" => {
68            let lowered = value.trim().to_ascii_lowercase();
69            if lowered != "true" && lowered != "false" {
70                eprintln!(
71                    "codex-cli config: ephemeral must be true|false (got: {})",
72                    value
73                );
74                return 64;
75            }
76            println!("export CODEX_CLI_EPHEMERAL_ENABLED={}", lowered);
77            0
78        }
79        "dangerous" | "allow-dangerous" | "CODEX_ALLOW_DANGEROUS_ENABLED" => {
80            let lowered = value.trim().to_ascii_lowercase();
81            if lowered != "true" && lowered != "false" {
82                eprintln!(
83                    "codex-cli config: dangerous must be true|false (got: {})",
84                    value
85                );
86                return 64;
87            }
88            println!("export CODEX_ALLOW_DANGEROUS_ENABLED={}", lowered);
89            0
90        }
91        _ => {
92            eprintln!("codex-cli config: unknown key: {key}");
93            eprintln!("codex-cli config: keys: model|reasoning|ephemeral|dangerous");
94            64
95        }
96    }
97}