clap icon indicating copy to clipboard operation
clap copied to clipboard

feat: add command headings feature

Open jerusdp opened this issue 2 months ago • 10 comments

Implementing issue #1553

Scope of this PR

The objective for this PR is to provide a facility for the user to place their commands under a custom header to allow the grouping of commands such as might be seen in git --help.

The PR will not implement CommandAction which would be required to permit the user to replace the help command with a custom user help command which could be place under a custom header. The user can place help under a custom header by amending the default title using Command::subcommand_help_heading placing the help command and the updated section at the top of the list of commands.

The will not change the scope of the Command::next_help_heading to include processing for commands as this is a breaking change.

Design Statements

Statement Comment
MUST provide API to specify a custom section header for a user command The key objective of the change
MUST keep commands with the same header together
MUST display commands with no custom header under the default header
MUST display help command under the standard header To amend this the user should change the default header
WILL NOT change scope of Command::next_help_heading to include subcommands
WILL NOT deprecate Command::subcommand_help_heading It can be used to generate custom section heading for help
WILL NOT implement custom replacement of help Future solution requiring CommandAction

jerusdp avatar Nov 17 '25 12:11 jerusdp

Please clean up the commits for how they should be reviewed and merged.

  • there are extra commits from master that were rewritten
  • builds are failing on early commits

epage avatar Nov 18 '25 13:11 epage

there are extra commits from master that were rewritten

These commits are still around

epage avatar Nov 18 '25 14:11 epage

Also, be sure to ping me when force-pushing; github doesn't send notifications for it.

epage avatar Nov 18 '25 14:11 epage

@epage dropped the commits and force pushed

jerusdp avatar Nov 18 '25 15:11 jerusdp

Please clean up commits for how they should be reviewed and merged and not for how this was implemented

epage avatar Nov 19 '25 21:11 epage

@epage Amended and test for flatten introduced; changes introduced to ensure test passes

jerusdp avatar Nov 21 '25 13:11 jerusdp

@epage comprehensive test suite added and valid. Flattened designed to place help at the end but non-flattened does not to allow the workaround of placing help under a renamed default heading. Rebased and force-pushed.

For a consistent approach of keeping the help at the end of the list of commands we will need to implement a solution that allows the user to specifically update the "help" command's heading. (Which, aligning with arg, is the Action solution).

jerusdp avatar Nov 26 '25 22:11 jerusdp

@epage dropped the commits and force pushed

Please rebase against the latest master and drop the unrelated commits

epage avatar Nov 26 '25 22:11 epage

@epage dropped the commits and force pushed

Please rebase against the latest master and drop the unrelated commits

Please see https://github.com/clap-rs/clap/pull/6183/commits for what I'm referring to

epage avatar Dec 02 '25 16:12 epage

@epage dropped the commits and force pushed

Please rebase against the latest master and drop the unrelated commits

Please see https://github.com/clap-rs/clap/pull/6183/commits for what I'm referring to

@epage done.

jerusdp avatar Dec 03 '25 12:12 jerusdp