Clap: Add options to require `help` and `long_help`

Created on 21 Jan 2020  路  8Comments  路  Source: clap-rs/clap

I like to add help strings, and sometimes long_help strings to all of my arguments, but I often forget.

It would be nice if I could add options to make app creation fail if help and long help strings are accidentally omitted. Perhaps AppSettings::RequireHelp and AppSettings::RequireLongHelp.

So this would panic on the call to App::arg:

let app = App::new(env!("CARGO_PKG_NAME"))
  .setting(AppSettings::RequireHelp)
  .arg(
    Arg::with_name("foo") // no help :(
  );

And this would be ok:

let app = App::new(env!("CARGO_PKG_NAME"))
  .setting(AppSettings::RequireHelp)
  .arg(
    Arg::with_name("foo").help("It does foo stuff") // help :)
  );

App::arg doesn't return a Result, but I think panicking is okay, since this is intended to aid development, and should not be encountered by end users. It would also be possible to make AppSettings::RequireHelp a noop on release builds.

help message easy want to have good first issue help wanted

All 8 comments

Hi everybody, I just wanted to let you know that I started working on this. I will try to propose a solution via a pull request within the next 5 days. Since I am new to rust, clap, and the GitHub workflow, it will probably need some reviews and iterations.

Thanks @pksunkara for linking my pull request to this issue. Would I have been able to do this myself? Or do you need certain rights to link issues to pull requests?

@thomasfermi nope you don't.

@thomasfermi The easiest way to do that is to put Closes #ABCD line in your first comment. I'm not sure if it works with editing, why don't you try and see for yourself?

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#manually-linking-a-pull-request-to-an-issue

I originally tried with that tutorial, but the "link" thing was grayed out and not clickable.

@thomasfermi The easiest way to do that is to put Closes #ABCD line in your first comment. I'm not sure if it works with editing, why don't you try and see for yourself?

Thanks, that is indeed an easy solution! I edited my first comment in the pull request.

@thomasfermi The first line from this guide:

Anyone with write permissions to a repository can manually link a pull request to an issue.

You don't have write permissions :(

Was this page helpful?
0 / 5 - 0 ratings