Skip to content

fix: read snake_case keys from yek config files - #269

Open
amareshhebbar wants to merge 1 commit into
prooflinedev:mainfrom
amareshhebbar:fix/snake-case-config-keys
Open

amareshhebbar wants to merge 1 commit into
prooflinedev:mainfrom
amareshhebbar:fix/snake-case-config-keys

Conversation

@amareshhebbar

Copy link
Copy Markdown

Fixes #268

Problem

The README's example yek.yaml uses snake_case keys (ignore_patterns, priority_rules, git_boost_max, max_size, output_template and others). clap-config-file names every config field in kebab-case, so those keys are silently dropped. #251 fixed this for the five boolean flags only.

Change

YekConfig::apply_snake_case_config_keys runs right after apply_config_bool_overrides. It reads the same config file and, for each setting whose snake_case key is present and whose kebab-case key is not, applies the value:

  • ignore_patterns and unignore_patterns extend the list, the same as the kebab-case keys and the CLI.
  • priority_rules, binary_extensions, git_boost_max, max_git_depth and category_weights are set from the file.
  • output_dir, output_name and output_template are filled only when still unset, so the CLI keeps precedence.
  • max_size is taken from the file only when it still has the default 10MB.

The values go through the existing validate(), so an invalid pattern in a snake_case key fails the same way as in a kebab-case key. If a file sets both spellings, the kebab-case key wins, so existing configs behave exactly as before. The README now says both spellings are accepted.

One limit: if someone passes --max-size 10MB on the CLI and also sets max_size in snake_case in the file, the file value wins, because the CLI value equals the default. The kebab-case key does not have this limit.

Tests

New tests in tests/main_test.rs run the binary:

  • test_main_with_snake_case_yaml_config: snake_case ignore_patterns, priority_rules and output_template in yek.yaml are applied.
  • test_main_with_snake_case_toml_config: snake_case ignore_patterns in yek.toml is applied.
  • test_main_kebab_case_config_key_wins_over_snake_case: with both spellings, the kebab-case value is used.
  • test_main_cli_ignore_patterns_extend_snake_case_config: CLI and config patterns both apply.

Without the change, the YAML, TOML and CLI tests fail. The kebab-case test passes before and after, as a guard.

Verification

cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo test

All pass on Fedora.

I used an AI assistant to help trace the bug and draft the change. I reproduced the bug myself, read the change, and ran the full suite locally.

This branch has not been deployed

No deployments
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.

yek.yaml settings written in snake_case, as in the README, are silently ignored

1 participant