Description
Some CLI options define default values via clap, then unconditionally overwrite values loaded from the JSON config file. As a result, config values are ignored even when the user does not explicitly pass the corresponding CLI flags.
Expected precedence should likely be:
- built-in defaults
- config file values
- explicitly provided CLI arguments
But current behavior makes some CLI defaults take precedence over config file values.
Examples
line_number_color
Config file:
{
"snapshot_config": {
"line_number_color": "#8c8fa1"
}
}
CLI defines a default:
#[arg(long, default_value = "#495162")]
line_number_color: String,
Then later always overwrites the loaded config value:
codesnap.line_number_color = cli.line_number_color.clone();
So #8c8fa1 from config is replaced by #495162 even when --line-number-color was not passed.
Other affected options
A similar pattern appears to affect:
scale_factor
window.border
code_config.breadcrumbs.enable
Possibly others should be audited as well.
Expected behavior
Values from the config file should be preserved unless the corresponding CLI option was explicitly provided.
For example, CLI fields could use Option<T> where appropriate:
#[arg(long)]
line_number_color: Option<String>,
Then only override config when present:
if let Some(line_number_color) = cli.line_number_color {
codesnap.line_number_color = line_number_color;
}
Environment
Observed in current main source.
Description
Some CLI options define default values via
clap, then unconditionally overwrite values loaded from the JSON config file. As a result, config values are ignored even when the user does not explicitly pass the corresponding CLI flags.Expected precedence should likely be:
But current behavior makes some CLI defaults take precedence over config file values.
Examples
line_number_colorConfig file:
{ "snapshot_config": { "line_number_color": "#8c8fa1" } }CLI defines a default:
Then later always overwrites the loaded config value:
So
#8c8fa1from config is replaced by#495162even when--line-number-colorwas not passed.Other affected options
A similar pattern appears to affect:
scale_factorwindow.bordercode_config.breadcrumbs.enablePossibly others should be audited as well.
Expected behavior
Values from the config file should be preserved unless the corresponding CLI option was explicitly provided.
For example, CLI fields could use
Option<T>where appropriate:Then only override config when present:
Environment
Observed in current
mainsource.