Skip to content

[Fix::cli] preserve config values unless CLI arguments are explicit - #130

Merged
mistricky merged 1 commit into
codesnap-rs:mainfrom
ermengchao:fix/cli-config-precedence
Oct 8, 2026
Merged

mistricky merged 1 commit into
codesnap-rs:mainfrom
ermengchao:fix/cli-config-precedence

Conversation

@ermengchao

Copy link
Copy Markdown
Contributor

Summary

Fixes #126 and #123.

CLI defaults previously overwrote JSON config values even when the corresponding arguments were omitted. This change preserves configured line-number color, scale factor, window border, breadcrumbs, and title unless explicitly overridden by CLI arguments.

  • Support bare flags and explicit true/false values for --has-border and --has-breadcrumbs.
  • Merge border color and width independently, preserving a configured positive width when enabling the border.
  • Document configuration precedence and boolean option usage.

Validation

  • Added 8 regression tests covering config preservation, explicit overrides, built-in defaults, boolean arguments, border width, and invalid scale factors.
  • cargo test -p codesnap-cli --locked — passed.
  • cargo fmt --all -- --check — passed.
  • git diff --check — passed.

@ermengchao

Copy link
Copy Markdown
Contributor Author

主程序改动点很简单:原来的 line_number_color 等参数在 clap 中定义了默认值,所以即使用户不传参数,cli 解析结果也会有值,随后无条件覆盖 json 配置。现在改成不带默认值的 Option<T>;主要工作量是增加了测试代码

@mistricky
mistricky self-requested a review October 8, 2026 02:23
@mistricky
mistricky merged commit 9258841 into codesnap-rs:main Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI defaults override values from config file

2 participants