Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default help and version message to infinitive form #2500

Closed
2 tasks done
ajeetdsouza opened this issue May 26, 2021 · 7 comments · Fixed by #2642
Closed
2 tasks done

Change default help and version message to infinitive form #2500

ajeetdsouza opened this issue May 26, 2021 · 7 comments · Fixed by #2642
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations 💸 $5

Comments

@ajeetdsouza
Copy link
Contributor

ajeetdsouza commented May 26, 2021

Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Describe your use case

There are two problems here.

  1. clap uses an unconventional sentence form in its auto-generated help messages (i.e. "Prints a help message" vs "Print a help message"). A lot of users (as shown in the links above) would like to change this, because practically every other UNIX program shows it in the infinitive form:
$ grep --help
-b, --byte-offset    print the byte offset with output lines

$ git init --help
--bare    create a bare repository

$ rg -h
--debug    Show debug messages.
  1. There's no way to set this help message manually if you use clap_derive.

Describe the solution you'd like

I'd like a way to set global_help_message and global_version_message in my app.

Alternatives, if applicable

app.mut_arg("help", |a| a.about("help info")) is a solution, but it does not work for apps using clap_derive.

Additional Context

There's plenty of demand for this feature:

@pksunkara
Copy link
Member

  1. We can change the default help string in clap.
  2. You can use mut_arg("help", |a| a.about("help info")) in clap_derive. Try pasting that on a struct in clap attribute.

@ajeetdsouza
Copy link
Contributor Author

  1. Would you be open to accepting a PR to change the default string?
  2. Perhaps I'm doing something wrong, but I wasn't able to get this working. I'm using this on a struct with AppSettings::DisableHelpSubcommand and I ran it with cargo run -- -h:
# mut_arg("-h", |a| a.about("help info"))
USAGE:
    app [-h] <SUBCOMMAND>

ARGS:
    <-h>    help info

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
# mut_arg("--help", |a| a.about("help info"))
USAGE:
    zoxide [--help] <SUBCOMMAND>

ARGS:
    <--help>    help info

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
# mut_arg("help", |a| a.about("help info"))
error: Found argument '-h' which wasn't expected, or isn't valid in this context

If you tried to supply `-h` as a PATTERN use `-- -h`

USAGE:
    zoxide [help] <SUBCOMMAND>

@pksunkara
Copy link
Member

pksunkara commented May 27, 2021 via email

@ajeetdsouza ajeetdsouza changed the title Bring back help_message and version_message Change default help and version message to infinitive form May 27, 2021
@ajeetdsouza
Copy link
Contributor Author

  1. Thanks! I tried doing a simple find-and-replace for this, but a couple of tests have started failing due to whitespace issues (which are impossible to track down due to the way they're printed). Have you considered using some diff library like pretty_assertions so that whitespace issues can be detected more easily?
  2. Just checked, this is fixed on master.

@pksunkara
Copy link
Member

pksunkara commented May 27, 2021

Make sure that you save without formatting the tests/help.rs while fixing the tests and it should be okay. We have an issue with no version printing blank space that's being tracked.

@ajeetdsouza
Copy link
Contributor Author

ajeetdsouza commented May 27, 2021

I did save without formatting, and then I disabled removing trailing whitespaces in the settings, but VS Code simply refused to stop formatting the line. It's probably a bug. I resorted to just using sed:

sed -i 's/Prints version information/Print version information/g'  **/*.*
sed -i 's/Prints help information/Print help information/g'  **/*.*
sed -i 's/Prints this message or the help of the given subcommand/Print this message or the help of the given subcommand/g'  **/*.*

Now, a lot more tests pass, but a few are still failing due to whitespace issues. I switched to pretty_assertions locally to see what was going on, apparently a bunch of random whitespace is being inserted towards the end of the help string, not sure why.

@pksunkara
Copy link
Member

As I said, We have an issue with no version printing blank space that's being tracked.

If you change only the messages without any whitespace changes, it should be fixed.

@pksunkara pksunkara added A-help Area: documentation, including docs.rs, readme, examples, etc... D: easy C-enhancement Category: Raise on the bar on expectations and removed T: new feature labels Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations 💸 $5
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants