Merge --style
s from different places using +
/-
#2929
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit aims to solve #1032, #1161, #1741, and #2894 by introducing a mechanism for merging the styles specified in the config file,
BAT_STYLE
environment variable, and the--style
command-line argument.This does so by treating each
--style
argument as a list of style components, and introducing a new+
and-
component prefix (e.g.+numbers
,-grid
) that allows--style
lists to be merged together. When a style list consists only of prefixed components, it will be merged into the list that comes before it. If it contains any non-prefixed components, it will replace the list before it instead.Ultimately, the style lists are merged into a final set of style components roughly following this pseudocode algorithm:
This preserves the existing behavior of
--style
taking precedence overBAT_STYLE
or the config file, while also allowing users to add or remove styles from individual runs ofbat
.Examples:
BAT_STYLE=full bat --style=plain
=> (none)Overriding the style from the config file or environment variable. (current behavior)
bat --style=default,-header,-numbers
=>changes,grid,snip
Removing components from the default/full style.
BAT_STYLE=full bat --style=-grid
=>changes,header-filename,header-filesize,numbers,snip
Removing components specified from the config file or environment variable.
BAT_STYLE=grid,numbers bat --style=+header
=>grid,numbers,header-filename
Adding components from the config file or environment variable. (current behavior)
Questions & Answers
Q. Why introduce
+component
instead of usingcomponent
without the prefix?A. In part due to technical limitations, and in part to avoid breaking users' existing configurations by preserving the original behavior of
--style
.Q. Why did you remove
overrides_with
?A. It forced clap's argument matcher to discard all but the most recent occurrence of
--style
.Unresolved Questions
What should we do when there is only one
--style
, and it contains something like+numbers
? It's currently treated like--style=numbers
; would it be better to treat it likedefault,+numbers
?Why is this test failing under the MSRV toolchain?