1use crate::auth::remote;
2use nils_common::shell::{SingleQuoteEscapeStyle, quote_posix_single_with_style};
3
4pub fn show() -> i32 {
5 let snapshot = crate::runtime::config_snapshot();
6
7 println!("CODEX_CLI_MODEL={}", snapshot.model);
8 println!("CODEX_CLI_REASONING={}", snapshot.reasoning);
9 println!(
10 "CODEX_CLI_EPHEMERAL_ENABLED={}",
11 std::env::var("CODEX_CLI_EPHEMERAL_ENABLED").unwrap_or_default()
12 );
13 println!(
14 "CODEX_ALLOW_DANGEROUS_ENABLED={}",
15 snapshot.allow_dangerous_enabled_raw
16 );
17
18 if let Some(path) = snapshot.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) = snapshot.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) = snapshot.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_PROMPT_SEGMENT_ENABLED={}",
38 snapshot.prompt_segment_enabled
39 );
40 println!(
41 "CODEX_AUTO_REFRESH_ENABLED={}",
42 snapshot.auto_refresh_enabled
43 );
44 println!(
45 "CODEX_AUTO_REFRESH_MIN_DAYS={}",
46 snapshot.auto_refresh_min_days
47 );
48 println!(
49 "{}={}",
50 remote::ENV_AUTH_REMOTE_SSH,
51 std::env::var(remote::ENV_AUTH_REMOTE_SSH).unwrap_or_default()
52 );
53 println!(
54 "{}={}",
55 remote::ENV_AUTH_REMOTE_NAME,
56 std::env::var(remote::ENV_AUTH_REMOTE_NAME).unwrap_or_default()
57 );
58 println!(
59 "{}={}",
60 remote::ENV_AUTH_REMOTE_REFRESH,
61 std::env::var(remote::ENV_AUTH_REMOTE_REFRESH).unwrap_or_default()
62 );
63
64 0
65}
66
67pub fn set(key: &str, value: &str) -> i32 {
68 match key {
69 "model" | "CODEX_CLI_MODEL" => {
70 println!(
71 "export CODEX_CLI_MODEL={}",
72 quote_posix_single_with_style(value, SingleQuoteEscapeStyle::DoubleQuoteBoundary)
73 );
74 0
75 }
76 "reasoning" | "reason" | "CODEX_CLI_REASONING" => {
77 println!(
78 "export CODEX_CLI_REASONING={}",
79 quote_posix_single_with_style(value, SingleQuoteEscapeStyle::DoubleQuoteBoundary)
80 );
81 0
82 }
83 "ephemeral" | "CODEX_CLI_EPHEMERAL_ENABLED" => {
84 let lowered = value.trim().to_ascii_lowercase();
85 if lowered != "true" && lowered != "false" {
86 eprintln!(
87 "codex-cli config: ephemeral must be true|false (got: {})",
88 value
89 );
90 return 64;
91 }
92 println!("export CODEX_CLI_EPHEMERAL_ENABLED={}", lowered);
93 0
94 }
95 "dangerous" | "allow-dangerous" | "CODEX_ALLOW_DANGEROUS_ENABLED" => {
96 let lowered = value.trim().to_ascii_lowercase();
97 if lowered != "true" && lowered != "false" {
98 eprintln!(
99 "codex-cli config: dangerous must be true|false (got: {})",
100 value
101 );
102 return 64;
103 }
104 println!("export CODEX_ALLOW_DANGEROUS_ENABLED={}", lowered);
105 0
106 }
107 "remote-ssh" | "remote_ssh" | "CODEX_AUTH_REMOTE_SSH" => {
108 println!(
109 "export {}={}",
110 remote::ENV_AUTH_REMOTE_SSH,
111 quote_posix_single_with_style(value, SingleQuoteEscapeStyle::DoubleQuoteBoundary)
112 );
113 0
114 }
115 "remote-name" | "remote_name" | "CODEX_AUTH_REMOTE_NAME" => {
116 println!(
117 "export {}={}",
118 remote::ENV_AUTH_REMOTE_NAME,
119 quote_posix_single_with_style(value, SingleQuoteEscapeStyle::DoubleQuoteBoundary)
120 );
121 0
122 }
123 "remote-refresh" | "remote_refresh" | "CODEX_AUTH_REMOTE_REFRESH" => {
124 let lowered = value.trim().to_ascii_lowercase();
125 if lowered != "true" && lowered != "false" {
126 eprintln!(
127 "codex-cli config: remote-refresh must be true|false (got: {})",
128 value
129 );
130 return 64;
131 }
132 println!("export {}={}", remote::ENV_AUTH_REMOTE_REFRESH, lowered);
133 0
134 }
135 _ => {
136 eprintln!("codex-cli config: unknown key: {key}");
137 eprintln!(
138 "codex-cli config: keys: model|reasoning|ephemeral|dangerous|remote-ssh|remote-name|remote-refresh"
139 );
140 64
141 }
142 }
143}