Repository navigation
Allow value-taking options to be repeated, like boolean flags - #4102
Conversation
e832851 to
e35c032
Compare
rahul05ranjan
left a comment
There was a problem hiding this comment.
I verified the scope of this fix by enumerating every Arg::new in clap_app.rs on main: the five options changed here (--binary, --italic-text, --nonprintable-notation, --fallback-syntax, --squeeze-limit) are exactly the top-level value-taking arguments that lacked overrides_with, while the other valued options (--theme, --language, --paging, --tabs, --wrap, --terminal-width, --color, --decorations, --pager, --strip-ansi, --sanitize, --diff-context, …) already have it. So this closes the remaining gap rather than picking an arbitrary subset — and the --fallback-language visible alias maps to the same arg id, so the override covers it too.
For anyone wondering why overrides_with(self) is the right idiom here: with ArgAction::Set, clap errors on repeat occurrences, and self-override is clap's documented way to allow them with last-value-wins — consistent with how #3912/#3921 handled the boolean flags (I confirmed those SetTrue args now carry overrides_with on main as well). The config-file angle makes this user-visible: get_args_from_config_file prepends config entries to the CLI argv, so any option in both places hit the "cannot be used multiple times" error, which matches your repro.
Two test-design notes I appreciated: the second test reproduces the actual reported scenario (config value overridden by CLI value) and asserts the behavioral consequence — Binary content from with no NUL bytes in stdout — rather than only exit status. tests/examples/test.binary exists as the fixture, so that's solid.
One small observation: bat cache's --source/--target/--completion also lack overrides_with, but they're subcommand-scoped so they can't collide with config-file entries on the top-level invocation — leaving them out is correct.
6edb1ff to
ff7baaa
Compare
The config file is prepended to the command line, so an option set in both places is passed twice. Boolean flags were made repeatable in sharkdp#3912, but options that take a value were missed: --binary, --italic-text, --nonprintable-notation, --fallback-syntax and --squeeze-limit were rejected with 'cannot be used multiple times', which aborts bat with exit code 2 before it reads any input. Add self-overrides so that the last occurrence wins, matching the behavior of --color, --theme, --wrap, --tabs and friends.
ff7baaa to
b5281b5
Compare
Resolve the CHANGELOG conflict with sharkdp#4102 and sharkdp#4103: keep their new entries, keep this PR's sharkdp#4084 entry, and point the UTF-16BE entry back at sharkdp#4076 (the merge of sharkdp#4102 had filled its placeholder with sharkdp#4102). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
Problem
A value-taking option given in both the config file and on the command line is rejected, so the config value cannot be overridden:
Exit code 2 and no output at all. The config file is prepended to the command line, so any option that appears in both places hits this.
Boolean flags were fixed the same way in #3912/#3921; the valued options were left out. Affected:
--binary,--italic-text,--nonprintable-notation,--fallback-syntax,--squeeze-limit.Fix
Give each of them a self-override, following the "last one wins" behaviour that
--color,--themeand the boolean flags already have:Five one-line additions in
src/bin/bat/clap_app.rs.Tests
Two integration tests in
tests/integration_tests.rs: one repeats each of the five options on the command line, the other puts--binary=as-textin a config file and overrides it with--binary=no-printingon the command line.Without the fix:
With it:
Full suite:
cargo test --test integration_tests→ 251 passed, 2 ignored, 0 failed;cargo test --lib→ 144 passed.