diff --git a/CHANGELOG.md b/CHANGELOG.md index e0ec7f51..fee6615b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Syntax highlighting for Python files using uv as script runner in shebang #3689 (@janlarres) ## 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) - 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) diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index 7f76f51b..9d57fc92 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -52,6 +52,7 @@ pub fn build_app(interactive_output: bool) -> Command { .long("show-all") .alias("show-nonprintable") .short('A') + .overrides_with("show-all") .action(ArgAction::SetTrue) .conflicts_with("language") .help("Show non-printable characters (space, tab, newline, ..).") @@ -171,6 +172,7 @@ pub fn build_app(interactive_output: bool) -> Command { Arg::new("diff") .long("diff") .short('d') + .overrides_with("diff") .action(ArgAction::SetTrue) .conflicts_with("line-range") .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") .long("chop-long-lines") .short('S') + .overrides_with("chop-long-lines") .action(ArgAction::SetTrue) .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") .long("squeeze-blank") .short('s') + .overrides_with("squeeze-blank") .action(ArgAction::SetTrue) .help("Squeeze consecutive empty lines.") .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") .short('u') .long("unbuffered") + .overrides_with("unbuffered") .action(ArgAction::SetTrue) .help("Enable unbuffered input reading for streaming use cases.") .long_help( @@ -619,6 +624,7 @@ pub fn build_app(interactive_output: bool) -> Command { .arg( Arg::new("no-custom-assets") .long("no-custom-assets") + .overrides_with("no-custom-assets") .action(ArgAction::SetTrue) .hide(true) .help("Do not load custom assets"), @@ -699,6 +705,7 @@ pub fn build_app(interactive_output: bool) -> Command { Arg::new("quiet-empty") .long("quiet-empty") .short('E') + .overrides_with("quiet-empty") .action(ArgAction::SetTrue) .help("Produce no output when the input is empty.") .long_help( @@ -717,6 +724,7 @@ pub fn build_app(interactive_output: bool) -> Command { .arg( Arg::new("set-terminal-title") .long("set-terminal-title") + .overrides_with("set-terminal-title") .action(ArgAction::SetTrue) .hide_short_help(true) .help("Sets terminal title to filenames when using a pager."), diff --git a/tests/examples/bat-show-all.conf b/tests/examples/bat-show-all.conf new file mode 100644 index 00000000..e5dd9b4e --- /dev/null +++ b/tests/examples/bat-show-all.conf @@ -0,0 +1 @@ +--show-all diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index d3e6f2a9..3f15f281 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -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] fn squeeze_blank() { bat()