Skip to content

Commit ef0b3bc

Browse files
factorydroidechobt
authored andcommitted
fix(cortex-common): warn on duplicate -c config flags
Fixes bounty issue #1628 When the user specifies the same config key multiple times using the -c flag (e.g., cortex run -c model=gpt-4 -c model=claude), the CLI now emits a warning to stderr indicating which key is duplicated and which value will be used. Previously, duplicates were silently overridden.
1 parent f325ba8 commit ef0b3bc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cortex-common/src/config_override.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Configuration override helpers for CLI.
22
3+
use std::collections::HashSet;
34
use std::path::PathBuf;
45

56
use cortex_protocol::AskForApproval;
@@ -18,8 +19,13 @@ pub struct CliConfigOverrides {
1819

1920
impl CliConfigOverrides {
2021
/// Parse the raw overrides into key-value pairs.
22+
///
23+
/// If a key is specified multiple times, a warning is emitted to stderr
24+
/// and the last value is used.
2125
pub fn parse_overrides(&self) -> Result<Vec<(String, toml::Value)>, String> {
2226
let mut result = Vec::new();
27+
let mut seen_keys: HashSet<String> = HashSet::new();
28+
2329
for raw in &self.raw_overrides {
2430
let parts: Vec<&str> = raw.splitn(2, '=').collect();
2531
if parts.len() != 2 {
@@ -30,6 +36,15 @@ impl CliConfigOverrides {
3036
let key = parts[0].trim().to_string();
3137
let value_str = parts[1].trim();
3238

39+
// Warn if key was already specified
40+
if seen_keys.contains(&key) {
41+
eprintln!(
42+
"Warning: config key '{}' specified multiple times, using last value '{}'",
43+
key, value_str
44+
);
45+
}
46+
seen_keys.insert(key.clone());
47+
3348
// Try to parse as various TOML types
3449
let value = if value_str.eq_ignore_ascii_case("true") {
3550
toml::Value::Boolean(true)

0 commit comments

Comments
 (0)