diff --git a/CHANGELOG.md b/CHANGELOG.md index bac8f637..0dd98c0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ## Bugfixes - Fix crash with BusyBox `less` on Windows, see #3527 (@Anchal-T) +- Fix `bat cache --help` failing with 'unexpected argument' error, see #3580 and #3560 (@NORMAL-EX) - `--help` now correctly honors `--pager=builtin`. See #3516 (@keith-hall) - `--help` now correctly honors custom themes. See #3524 (@keith-hall) - Fixed test compatibility with future Cargo build directory changes, see #3550 (@nmacl) diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index 10bf7a8b..8ee3604e 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -1,7 +1,5 @@ use bat::style::StyleComponentList; -use clap::{ - crate_name, crate_version, value_parser, Arg, ArgAction, ArgGroup, ColorChoice, Command, -}; +use clap::{crate_name, crate_version, value_parser, Arg, ArgAction, ColorChoice, Command}; use once_cell::sync::Lazy; use std::env; use std::path::{Path, PathBuf}; @@ -694,11 +692,20 @@ pub fn build_app(interactive_output: bool) -> Command { Command::new("cache") .hide(true) .about("Modify the syntax-definition and theme cache") + .arg_required_else_help(true) + .arg( + Arg::new("help") + .short('h') + .long("help") + .action(ArgAction::Help) + .help("Print help"), + ) .arg( Arg::new("build") .long("build") .short('b') .action(ArgAction::SetTrue) + .conflicts_with("clear") .help("Initialize (or update) the syntax/theme cache.") .long_help( "Initialize (or update) the syntax/theme cache by loading from \ @@ -710,13 +717,9 @@ pub fn build_app(interactive_output: bool) -> Command { .long("clear") .short('c') .action(ArgAction::SetTrue) + .conflicts_with("build") .help("Remove the cached syntax definitions and themes."), ) - .group( - ArgGroup::new("cache-actions") - .args(["build", "clear"]) - .required(true), - ) .arg( Arg::new("source") .long("source") diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 7b4e2df4..7d0f69cd 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -3684,3 +3684,20 @@ fn quiet_empty_suppresses_output_on_empty_file() { .success() .stdout(""); } + +#[test] +fn cache_help_shows_help_message() { + // Test that `bat cache --help` works (fixes #3560) + // Run in cache_source directory which doesn't have a file named "cache" + bat_with_config() + .current_dir(Path::new(EXAMPLES_DIR).join("cache_source")) + .arg("cache") + .arg("--help") + .assert() + .success() + .stdout(predicate::str::contains( + "Modify the syntax-definition and theme cache", + )) + .stdout(predicate::str::contains("--build")) + .stdout(predicate::str::contains("--clear")); +}