Skip to content

Commit e025cbe

Browse files
factorydroidechobt
authored andcommitted
fix(cli): show config file content in debug config command
Fixes bounty issue #1418 The debug config command previously only showed config file paths and whether they exist, but did not display the actual configuration content. This change adds the config file contents to both JSON and human-readable output formats when the files exist.
1 parent 69ef44f commit e025cbe

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

cortex-cli/src/debug_cmd.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ struct ConfigDebugOutput {
7676
resolved: ResolvedConfig,
7777
locations: ConfigLocations,
7878
#[serde(skip_serializing_if = "Option::is_none")]
79+
global_config_content: Option<String>,
80+
#[serde(skip_serializing_if = "Option::is_none")]
81+
local_config_content: Option<String>,
82+
#[serde(skip_serializing_if = "Option::is_none")]
7983
environment: Option<HashMap<String, String>>,
8084
}
8185

@@ -112,10 +116,28 @@ async fn run_config(args: ConfigArgs) -> Result<()> {
112116
cortex_home: config.cortex_home.clone(),
113117
};
114118

119+
let global_config_exists = global_config.exists();
120+
let local_config_exists = local_config.as_ref().is_some_and(|p| p.exists());
121+
122+
// Read config file contents if they exist
123+
let global_config_content = if global_config_exists {
124+
std::fs::read_to_string(&global_config).ok()
125+
} else {
126+
None
127+
};
128+
129+
let local_config_content = if local_config_exists {
130+
local_config
131+
.as_ref()
132+
.and_then(|p| std::fs::read_to_string(p).ok())
133+
} else {
134+
None
135+
};
136+
115137
let locations = ConfigLocations {
116-
global_config_exists: global_config.exists(),
138+
global_config_exists,
117139
global_config,
118-
local_config_exists: local_config.as_ref().is_some_and(|p| p.exists()),
140+
local_config_exists,
119141
local_config,
120142
};
121143

@@ -163,6 +185,8 @@ async fn run_config(args: ConfigArgs) -> Result<()> {
163185
let output = ConfigDebugOutput {
164186
resolved,
165187
locations,
188+
global_config_content,
189+
local_config_content,
166190
environment,
167191
};
168192

@@ -200,6 +224,26 @@ async fn run_config(args: ConfigArgs) -> Result<()> {
200224
);
201225
}
202226

227+
// Display global config content
228+
if let Some(ref content) = output.global_config_content {
229+
println!();
230+
println!("Global Config Content");
231+
println!("{}", "-".repeat(40));
232+
for line in content.lines() {
233+
println!(" {}", line);
234+
}
235+
}
236+
237+
// Display local config content
238+
if let Some(ref content) = output.local_config_content {
239+
println!();
240+
println!("Local Config Content");
241+
println!("{}", "-".repeat(40));
242+
for line in content.lines() {
243+
println!(" {}", line);
244+
}
245+
}
246+
203247
if let Some(ref env) = output.environment {
204248
println!();
205249
println!("Environment Variables");

0 commit comments

Comments
 (0)