Skip to content

Commit 13bc5c8

Browse files
committed
fix: CLI args should override env vars, not the other way around
Merge order: config file → env vars → CLI args. This ensures explicit --connection-string flags take precedence over DATABASE_URL.
1 parent a4fab57 commit 13bc5c8

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

crates/pgls_cli/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,8 @@ impl<'app> CliSession<'app> {
201201
}
202202

203203
let mut configuration = loaded_configuration.configuration;
204-
if let Some(cli_config) = cli_configuration {
205-
configuration.merge_with(cli_config);
206-
}
207204

208-
// Env vars take highest priority — merge last so they override everything.
205+
// Env vars override config file but are overridden by explicit CLI args.
209206
if let Some(env_db) = pgls_configuration::database::PartialDatabaseConfiguration::from_env()
210207
{
211208
let env_config = PartialConfiguration {
@@ -215,6 +212,10 @@ impl<'app> CliSession<'app> {
215212
configuration.merge_with(env_config);
216213
}
217214

215+
if let Some(cli_config) = cli_configuration {
216+
configuration.merge_with(cli_config);
217+
}
218+
218219
Ok(configuration)
219220
}
220221

0 commit comments

Comments
 (0)