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

Add example function in App struct #2668

Closed
2 tasks done
Ebedthan opened this issue Aug 7, 2021 · 3 comments
Closed
2 tasks done

Add example function in App struct #2668

Ebedthan opened this issue Aug 7, 2021 · 3 comments

Comments

@Ebedthan
Copy link

Ebedthan commented Aug 7, 2021

Please complete the following tasks

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

Clap Version

2.33

Describe your use case

Hi,
It would be great to have a function in the Arg struct that facilitates the addition of command-line examples when the help is printed. This is very often cited as a best practice in designing command-line tools.

Describe the solution you'd like

I believe that something like this will be really great

let m = App::new("prog")
    .author("Me, [email protected]")
    .version("1.0.2")
    .about("Explains in brief what the program does")
    .examples("prog -i myfile -o myout")
    .get_matches();

Alternatives, if applicable

Actually, as an alternative, I add examples into the about() function:

let m = App::new("prog")
    .author("Me, [email protected]")
    .version("1.0.2")
    .about(
          "Explains in brief what the program does\n\
           EXAMPLES:\n\
           \tprog -i myfile -o myout"
    )
    .get_matches();

But this does not come with the default clap color pattern for help.

Additional Context

No response

@pksunkara
Copy link
Member

But this does not come with the default clap color pattern for help.

Can you please explain that?

@Ebedthan
Copy link
Author

Ebedthan commented Aug 7, 2021

In the help text printed by clap, heading like USAGE, ARGS, FLAGS are colored in magenta/yellow, but not for the workaround I currently use. This can be added using color crates but I think directly implementing it in clap would be a really nice feature.

@pksunkara
Copy link
Member

That would be solved by #1790

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants