Skip to content

fix(cache): allow --help flag for cache subcommand#3580

Merged
keith-hall merged 9 commits intosharkdp:masterfrom
NORMAL-EX:fix/cache-help
Feb 9, 2026
Merged

fix(cache): allow --help flag for cache subcommand#3580
keith-hall merged 9 commits intosharkdp:masterfrom
NORMAL-EX:fix/cache-help

Conversation

@NORMAL-EX
Copy link
Contributor

Summary

Fixes #3560

Problem

bat cache --help currently fails with:

error: unexpected argument '--help' found

Usage: bat cache [OPTIONS] <--build|--clear>

This happens because the cache-actions ArgGroup is set to required(true), which causes clap to validate required arguments before processing the --help flag.

Solution

Remove .required(true) from the cache-actions ArgGroup. The behavior remains the same (users must specify either --build or --clear when running the cache subcommand) because clap will still show an error if neither is provided. However, now --help is processed first, allowing users to view the help message.

Testing

# Before: error
$ bat cache --help
error: unexpected argument '--help' found

# After: shows help
$ bat cache --help
Modify the syntax-definition and theme cache
...

This is a resubmission of #3573 with cargo fmt applied.

@NORMAL-EX
Copy link
Contributor Author

The cargo audit failure is unrelated to this PR - it's caused by a newly published security advisory RUSTSEC-2026-0009 (published 2026-02-05) affecting the time crate dependency.

This affects all PRs until the upstream dependency is updated in the main branch.

Copy link
Collaborator

@keith-hall keith-hall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the cache_help_shows_help_message integration test from the original PR got omitted?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erm, the changelog entry being repeated for every version of bat ever released is a bit... odd... we can't go back in time / backport the fix and republish old versions with the same version number it originally had... I suggest just to keep the entry in the unreleased section...

@NORMAL-EX
Copy link
Contributor Author

Fixed both issues:

  1. Reverted CHANGELOG.md to only have the entry in the unreleased section — sorry about that!
  2. Added the cache_help_shows_help_message integration test from the original PR

Thanks for catching these!

@NORMAL-EX
Copy link
Contributor Author

Updated the fix to match the approach from #3573:

  • Added .arg_required_else_help(true) to the cache subcommand
  • Replaced the ArgGroup with .conflicts_with() on each arg
  • Removed unused ArgGroup import

Just removing .required(true) from the group wasn't enough — --help was still rejected. The full removal of the ArgGroup + arg_required_else_help is needed for clap to properly handle --help.

@NORMAL-EX
Copy link
Contributor Author

Found the root cause of the test failure: the parent command sets .disable_help_flag(true) (line 37), which propagates to the cache subcommand. This means --help is not recognized on bat cache regardless of the ArgGroup changes.

Added .disable_help_flag(false) to the cache subcommand to override the parent setting. Also fixed cargo fmt (import line formatting).

@keith-hall keith-hall merged commit cb8b637 into sharkdp:master Feb 9, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"bat cache --help" error: unexpected argument '--help' found

2 participants