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