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

Output default value with help text #88

Closed
PhilippPaetzold opened this issue Nov 24, 2020 · 3 comments
Closed

Output default value with help text #88

PhilippPaetzold opened this issue Nov 24, 2020 · 3 comments

Comments

@PhilippPaetzold
Copy link

Hi @p-ranav,

I think it would be nice, if you could print default values specified by "default_value" method when outputting the help text:

    program
        .add_argument("n")
        .help("Number of iterations to be performed")
        .default_value("10");

->

...
Positional arguments:
n               Number of messages to be sent (default: 10)

this would be really useful

Best regards
Philipp

@rysson
Copy link
Contributor

rysson commented Nov 30, 2020

Nice idea, optional of course.

@mishmish-dev
Copy link
Contributor

Hey, I made a PR
#92

I'm not sure if I should include some extra tests/demos.

Under the hood it uses details::repr function to get string representation of default argument, which uses to << operator to std::ostream. It also works with basic STL-like containers, printing not more than details::repr_max_container_size elements (hardcoded to 5).

Basically, it solves the issue, but still, I haven't figured out what to do with long strings as well as those containing newlines and special symbols.

@p-ranav
Copy link
Owner

p-ranav commented Dec 15, 2020

I've approved the PR but yes, a few tests are required, e.g.,

  • default arg that is integral
  • default arg that is float
  • default arg that is string
  • default arg that is vector
  • default arg that is bool
  • default arg that is optional

p-ranav added a commit that referenced this issue Dec 15, 2020
Show default value for arg in help message
@p-ranav p-ranav closed this as completed Mar 23, 2021
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

4 participants