Skip to content

CLI defaults override values from config file #126

@ermengchao

Description

@ermengchao

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:

  1. built-in defaults
  2. config file values
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions