Add --no-* negation flags for boolean CLI options#2095
Conversation
Allow disabling boolean flags (e.g. --side-by-side, --line-numbers, --navigate) from the command line when they are enabled in gitconfig. Uses clap's overrides_with for last-flag-wins semantics, so `--side-by-side --no-side-by-side` disables and vice versa. Flags added: --no-color-only, --no-diff-highlight, --no-diff-so-fancy, --no-hyperlinks, --no-keep-plus-minus-markers, --no-line-numbers, --no-navigate, --no-raw, --no-relative-paths, --no-side-by-side
Test that --no-* flags override gitconfig values and that last-flag-wins semantics work correctly.
Use if-let destructuring instead of is_some() + unwrap().
Keep tuple destructuring approach for width/alignment_spec to avoid unnecessary unwrap().
|
@dandavison Ready for review. Thanks |
|
Hi @pablospe, how confident are you that the command names here will match exactly what clap introduces, if they do introduce a solution? |
|
That's a fair concern. I'm not fully confident the names would match exactly. However, the upstream issue (clap-rs/clap#815) has been open since 2017 and there doesn't seem to be movement toward a built-in solution anytime soon. Given how straightforward this implementation is and that it addresses a real usability need (being able to override config file settings from the command line), I think it's worth having now rather than waiting indefinitely. If clap ever does add native support, it should be easy to migrate at that point. |
|
@dandavison. Following up on your question about clap compatibility. I went with the Would you prefer a different approach here? For example:
Let me know what you'd like and I'll update the PR accordingly. |
Summary
--no-*counterparts for 10 boolean flags:--no-side-by-side,--no-line-numbers,--no-navigate,--no-hyperlinks,--no-color-only,--no-diff-highlight,--no-diff-so-fancy,--no-keep-plus-minus-markers,--no-raw,--no-relative-pathsoverrides_withfor last-flag-wins semantics (e.g.--side-by-side --no-side-by-side→ disabled)Motivation
When boolean flags like
--side-by-sideor--line-numbersare set in gitconfig, there is currently no CLI way to disable them. This is needed for tools that invoke delta programmatically and need to toggle features on and off.Note: this is a workaround until clap-rs/clap#815 is resolved, which would allow clap to natively support
--no-*flag generation.