Skip to content

how to enable -h / --help (short help) + --help-all (long help) #4687

@asottile

Description

@asottile

Please complete the following tasks

Clap Version

4.1.4

Describe your use case

I've found #3405 which hints at the same idea, but I wasn't able to follow whether this was implemented or not

I have this, which is close but doesn't satisfy the "--help gives short help" (mostly, I find clap's choice of -h and --help an odd one, and not one I've found precedence for elsewhere, the more common approach I've seen is --help-all or --help-full or --help-{thing} to give additional help for specific areas).

use clap::Parser;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
#[clap(disable_help_flag = true)]
struct Cli {
    /// Should always be shown in all helps
    #[arg(long)]
    someopt: String,
    /// Secret option, should only be shown in --help-all
    #[arg(long, hide_short_help = true)]
    wacky: String,
    /// Print help
    #[arg(short, long, action = clap::ArgAction::Help)]
    help: bool,
    /// Print help, including uncommon options
    #[arg(long, action = clap::ArgAction::Help)]
    help_all: bool,
}


fn main() {
    let args = Cli::parse();
    println!("Hello, world!, {:?}", args);
}

Describe the solution you'd like

maybe something like this?

    /// Print help
    #[arg(short, long, action = clap::ArgAction::HelpShort)]
    help: bool,
    /// Print help, including uncommon options
    #[arg(long, action = clap::ArgAction::HelpLong)]
    help_all: bool,

(HelpShort / HelpLong)

Alternatives, if applicable

I am very new to clap, so I'd be happy enough if there's already a solution to this

Additional Context

for example, python's help:

$ python3.12 --help
usage: python3.12 [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options (and corresponding environment variables):
-b     : issue warnings about str(bytes_instance), str(bytearray_instance)
         and comparing bytes/bytearray with str. (-bb: issue errors)
...
--help-env      : print help about Python environment variables and exit
--help-xoptions : print help about implementation-specific -X options and exit
--help-all      : print complete help information and exit
Arguments:
file   : program read from script file
-      : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-helpArea: documentation, including docs.rs, readme, examples, etc...C-enhancementCategory: Raise on the bar on expectationsS-waiting-on-decisionStatus: Waiting on a go/no-go before implementing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions