Allow boolean flags to be repeated
bat prepends the arguments from its config file to the command line, so a user who has `--show-all` in their config and also types `-A` passes the flag twice, and clap rejects that with "the argument '--show-all' cannot be used multiple times" and exit code 2. The file is never displayed. `--plain`, `--number`, `--number-nonblank`, `--force-colorization` and `--no-paging` already avoid this by overriding themselves. The same is now done for the eight remaining flags that affect how a file is displayed: --show-all, --diff, --chop-long-lines, --squeeze-blank, --unbuffered, --quiet-empty, --no-custom-assets and --set-terminal-title. Repeating a flag produces byte-identical output to giving it once, and --show-all still conflicts with --language as before.
This commit is contained in:
1 parent
16b5f99d16
commit
cf72a432ac
4 files changed
+34
No files matched your search
@@ -25,6 +25,7 @@
|
|||||||
- Syntax highlighting for Python files using uv as script runner in shebang #3689 (@janlarres)
|
- Syntax highlighting for Python files using uv as script runner in shebang #3689 (@janlarres)
|
||||||
|
|
||||||
## Bugfixes
|
## Bugfixes
|
||||||
|
- Allow boolean flags to be given more than once, so that a flag set in the config file can also be passed on the command line without erroring, see #3912 (@logarithmone1128)
|
||||||
- Use parsed CLI arguments to detect number flags, see #3908 (@cuishuang)
|
- Use parsed CLI arguments to detect number flags, see #3908 (@cuishuang)
|
||||||
- Detect binary content beyond the first line, preventing encrypted files with early line breaks from being treated as text. Closes #3554, see #3877 (@Matei02355)
|
- Detect binary content beyond the first line, preventing encrypted files with early line breaks from being treated as text. Closes #3554, see #3877 (@Matei02355)
|
||||||
- Use the last occurrence of numbering and plain flags in combined short arguments, see #3897 (@cuishuang)
|
- Use the last occurrence of numbering and plain flags in combined short arguments, see #3897 (@cuishuang)
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
|||||||
.long("show-all")
|
.long("show-all")
|
||||||
.alias("show-nonprintable")
|
.alias("show-nonprintable")
|
||||||
.short('A')
|
.short('A')
|
||||||
|
.overrides_with("show-all")
|
||||||
.action(ArgAction::SetTrue)
|
.action(ArgAction::SetTrue)
|
||||||
.conflicts_with("language")
|
.conflicts_with("language")
|
||||||
.help("Show non-printable characters (space, tab, newline, ..).")
|
.help("Show non-printable characters (space, tab, newline, ..).")
|
||||||
@@ -171,6 +172,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
|||||||
Arg::new("diff")
|
Arg::new("diff")
|
||||||
.long("diff")
|
.long("diff")
|
||||||
.short('d')
|
.short('d')
|
||||||
|
.overrides_with("diff")
|
||||||
.action(ArgAction::SetTrue)
|
.action(ArgAction::SetTrue)
|
||||||
.conflicts_with("line-range")
|
.conflicts_with("line-range")
|
||||||
.help("Only show lines that have been added/removed/modified.")
|
.help("Only show lines that have been added/removed/modified.")
|
||||||
@@ -235,6 +237,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
|||||||
Arg::new("chop-long-lines")
|
Arg::new("chop-long-lines")
|
||||||
.long("chop-long-lines")
|
.long("chop-long-lines")
|
||||||
.short('S')
|
.short('S')
|
||||||
|
.overrides_with("chop-long-lines")
|
||||||
.action(ArgAction::SetTrue)
|
.action(ArgAction::SetTrue)
|
||||||
.help("Truncate all lines longer than screen width. Alias for '--wrap=never'."),
|
.help("Truncate all lines longer than screen width. Alias for '--wrap=never'."),
|
||||||
)
|
)
|
||||||
@@ -473,6 +476,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
|||||||
Arg::new("squeeze-blank")
|
Arg::new("squeeze-blank")
|
||||||
.long("squeeze-blank")
|
.long("squeeze-blank")
|
||||||
.short('s')
|
.short('s')
|
||||||
|
.overrides_with("squeeze-blank")
|
||||||
.action(ArgAction::SetTrue)
|
.action(ArgAction::SetTrue)
|
||||||
.help("Squeeze consecutive empty lines.")
|
.help("Squeeze consecutive empty lines.")
|
||||||
.long_help("Squeeze consecutive empty lines into a single empty line.")
|
.long_help("Squeeze consecutive empty lines into a single empty line.")
|
||||||
@@ -598,6 +602,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
|||||||
Arg::new("unbuffered")
|
Arg::new("unbuffered")
|
||||||
.short('u')
|
.short('u')
|
||||||
.long("unbuffered")
|
.long("unbuffered")
|
||||||
|
.overrides_with("unbuffered")
|
||||||
.action(ArgAction::SetTrue)
|
.action(ArgAction::SetTrue)
|
||||||
.help("Enable unbuffered input reading for streaming use cases.")
|
.help("Enable unbuffered input reading for streaming use cases.")
|
||||||
.long_help(
|
.long_help(
|
||||||
@@ -619,6 +624,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
|||||||
.arg(
|
.arg(
|
||||||
Arg::new("no-custom-assets")
|
Arg::new("no-custom-assets")
|
||||||
.long("no-custom-assets")
|
.long("no-custom-assets")
|
||||||
|
.overrides_with("no-custom-assets")
|
||||||
.action(ArgAction::SetTrue)
|
.action(ArgAction::SetTrue)
|
||||||
.hide(true)
|
.hide(true)
|
||||||
.help("Do not load custom assets"),
|
.help("Do not load custom assets"),
|
||||||
@@ -699,6 +705,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
|||||||
Arg::new("quiet-empty")
|
Arg::new("quiet-empty")
|
||||||
.long("quiet-empty")
|
.long("quiet-empty")
|
||||||
.short('E')
|
.short('E')
|
||||||
|
.overrides_with("quiet-empty")
|
||||||
.action(ArgAction::SetTrue)
|
.action(ArgAction::SetTrue)
|
||||||
.help("Produce no output when the input is empty.")
|
.help("Produce no output when the input is empty.")
|
||||||
.long_help(
|
.long_help(
|
||||||
@@ -717,6 +724,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
|||||||
.arg(
|
.arg(
|
||||||
Arg::new("set-terminal-title")
|
Arg::new("set-terminal-title")
|
||||||
.long("set-terminal-title")
|
.long("set-terminal-title")
|
||||||
|
.overrides_with("set-terminal-title")
|
||||||
.action(ArgAction::SetTrue)
|
.action(ArgAction::SetTrue)
|
||||||
.hide_short_help(true)
|
.hide_short_help(true)
|
||||||
.help("Sets terminal title to filenames when using a pager."),
|
.help("Sets terminal title to filenames when using a pager."),
|
||||||
|
|||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
--show-all
|
||||||
@@ -646,6 +646,30 @@ fn piped_output_with_default_style_flag() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn repeated_boolean_flag_is_accepted() {
|
||||||
|
// A flag in the config file is prepended to the command line, so a user
|
||||||
|
// who has `--show-all` in their config and also types `-A` ends up passing
|
||||||
|
// it twice. That must not be an error.
|
||||||
|
bat()
|
||||||
|
.arg("empty_lines.txt")
|
||||||
|
.arg("--show-all")
|
||||||
|
.arg("--show-all")
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn boolean_flag_in_config_and_on_command_line() {
|
||||||
|
bat_with_config()
|
||||||
|
.env("BAT_CONFIG_PATH", "bat-show-all.conf")
|
||||||
|
.arg("empty_lines.txt")
|
||||||
|
.arg("--show-all")
|
||||||
|
.arg("--paging=never")
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn squeeze_blank() {
|
fn squeeze_blank() {
|
||||||
bat()
|
bat()
|
||||||
|
|||||||
Reference in new issue
Block a user