Clap: Selectively hide arguments from '-h' text (but not '--help')

Created on 11 Oct 2017  路  5Comments  路  Source: clap-rs/clap

I really like clap's feature to distinguish between a short and concise help text via -h and a longer and detailed help text via --help (see Arg::long_help).

It would be great if whole arguments (e.g. options that are not commonly used) could be hidden from the -h text but still show up on the detailed --help text.

I propose to add a method like Arg::short_hidden(self, h: bool) or Arg::long_visible(self, v: bool) that could be used to configure this behavior.

help message settings easy nice to have new setting 2.x mentored

Most helpful comment

Awesome, thanks for the guidance! I鈥檒l start digging and hopefully have something soon.

All 5 comments

@kbknapp I'd like to add this, I'm just having trouble spotting where the help and long_help from Base are used when showing the help output.

@stevepentland awesome! I'm on mobile so I can't give a super comprehensive answer at the moment, but look in the implementation of AnyArg for the respective Arg types (flag, positional, and opt), and they're in used help.rs which does all the help message printing.

Once I get to a computer I can give a better answer

In src/app/help.rs:445 is where decides which version of the help to display, notice the use_long in the branch.

In src/app/help.rs:205 Is where it decides which args to display/hide.

I would recommend adding two methods to the Arg struct such as Arg::hidden_long_help and Arg::hidden_short_help using Arg::hidden as a guide.

This will require also creating corresponding ArgSettings variants in src/args/settings.rs, again using ArgSettings::Hidden as a guide.

The way I envision this working is setting Arg::hidden(true) is effectively the same as setting both Arg::hidden_long_help and Arg::hidden_short_help, so the docs should reflect that.

Awesome, thanks for the guidance! I鈥檒l start digging and hopefully have something soon.

Closed with #1235 thanks to @stevepentland

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kbknapp picture kbknapp  路  22Comments

neysofu picture neysofu  路  41Comments

jojva picture jojva  路  18Comments

joshtriplett picture joshtriplett  路  75Comments

CAD97 picture CAD97  路  21Comments