Skip to content

Commit

Permalink
Merge pull request #93 from cekc/nicer-message-for-required
Browse files Browse the repository at this point in the history
nicer usage text for required arg
  • Loading branch information
p-ranav authored Dec 15, 2020
2 parents 68fb9f1 + ed06438 commit 9903a22
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,14 @@ class Argument {
std::copy(std::begin(argument.mNames), std::end(argument.mNames),
std::ostream_iterator<std::string>(nameStream, " "));
stream << nameStream.str() << "\t" << argument.mHelp;
if (argument.mIsRequired && !argument.mDefaultValue.has_value())
stream << "[Required]";
if (argument.mDefaultValue.has_value()) {
if (!argument.mHelp.empty())
stream << " ";
stream << "[default: " << argument.mDefaultValueRepr << "]";
} else if (argument.mIsRequired) {
if (!argument.mHelp.empty())
stream << " ";
stream << "[required]";
}
stream << "\n";
return stream;
Expand Down

0 comments on commit 9903a22

Please sign in to comment.