clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
14.09k stars 1.03k forks source link

Multiple subcommand categories / `help_heading`s #1553

Open BrettMayson opened 4 years ago

BrettMayson commented 4 years ago

Feature Request Summary

It would be nice to be able to have multiple subcommand groupings.

Sample

An example of what I mean can be found at https://github.com/synixebrett/HEMTT/issues/195

epage commented 2 years ago

@pksunkara we were just talking about whether App::subcommand_help_heading should be supported in a way to allow individual subcommands to have their own help heading like args.

pksunkara commented 2 years ago

Looks like I didn't need to create an issue for what we were talking about.

epage commented 2 years ago

The question we need to resolve with this is how to handle naming

App::help_heading applies to future args

App::subcommand_help_heading globally applies to subcommands as if you called App::help_heading at the start and never called Arg::help_heading.

Maybe if we changed the behavior so that

This would be a breaking change and one that doesn't offer a transition path with deprecations. Any other ideas for how we could do this?

pksunkara commented 2 years ago

Bikeshedding on the name to make it more clear,

One concern with combining the arg and app help heading setting in one function is what to do when they have a common heading? How do we display the help?

epage commented 2 years ago

One option I had been considering that I forgot until your post is Command::next_help_heading.

I worry people will just refer to what help headings as groups or categories, so using a _group suffix I don't think will convey the intent of "all following are being grouped under the this heading" (which I'm assuming is the intent of the suggestion).

pksunkara commented 2 years ago

Yeah, I think I am trying to convey that the function sets help heading for both args and subcommands. Maybe it's better if we just divide them into args_help_heading and subcommands_help_heading. But I think next_help_heading is better than help_heading_group definitely.

epage commented 2 years ago

So to summarize the solution:

I guess the downside to the name next_help_heading is in derives. This is also getting me thinking that maybe we should provide some more flexibility by renaming our attribute from clap to clap::app and clap::arg. This would allow a user to set app settings in the middle of the derive. If that idea sounds like it has potential, I'll create a separate issue for further discussion.

epage commented 2 years ago

3414 changed App::help_heading -> App::next_help_heading. The rest of the work is reserved for clap 4.

epage commented 2 years ago

Think I'm going to push this out.

In working on this, I realized a problem we'd have is how to set the help heading for the implicit help subcommand and help/version flags.

milesj commented 1 year ago

Been a year now, has there been any movement on this?

YamatoSecurity commented 6 months ago

We would love this feature as well... only being able to have one group for commands is very limiting and makes for a bad UI for the user.