-
Notifications
You must be signed in to change notification settings - Fork 265
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
Rework/Enhance help and usage #187
Conversation
This will show in the help as e.g. --option METAVAR Description of option help
Also, add ArgumentParser.usage() method to get just the usage line.
- Indent lists of arguments - Separate argument names with ", " - Don't show "default" for implicit arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I like the feature. Thank you for your work.
I'd like to see a metavar-specific example added to README. This is a nice feature that should be pointed out in the docs.
usage << "["; | ||
} | ||
usage << longest_name; | ||
const std::string metavar = m_metavar.size() > 0 ? m_metavar : "VAR"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use !m_metavar.empty()
. There are three of these.
return 2 + m_metavar.size(); | ||
} else { | ||
// Indent and space-separated | ||
return 2 + names_size + (m_names.size() - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the else after return.
std::copy(std::begin(argument.m_names), std::end(argument.m_names), | ||
std::ostream_iterator<std::string>(name_stream, " ")); | ||
name_stream << " "; // indent | ||
if (argument.is_positional(argument.m_names.front())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_positional
is a static member function and does not need an instance.
Hi, just a note that I'm happy to make these changes and rework the README, I've just been a little busy and won't be able to get to it for a couple of weeks 😅 |
METAVAR, Improved help, Samples (Based on #187)
Refactored and merged as part of #206, including changes requested by @skrobinson. Thanks to both of you! |
Generally reworked help output to be a little more like what I expect (or, at least, like python's argparse)
--option VALUE Description of Option
instead of--option Description ...
.[options]
. AddedArgumentParser::usage()
to retreive this string alone (in case you wanted to, say, print usage if arguments incorrectly passed).[default: ...]
for implicit values. This seemed unusual. It might be better to rework the help system to recognise a placeholder (even python's%(default)s
) rather than try to magically get this right.I guess the biggest holes are:
Otherwise this... might not be how you want things. If you like these changes I'm happy to do some amount of reworking to get it up to scratch for merging - these changes work for my purposes, but it could be that you wanted all of this done some other way. I thought I'd at least try to polish them up if it was useful ;)
A slightly expanded version of the README second example:
Gives: