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

Fix issue 208 #209

Merged
merged 2 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions include/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class Argument {
std::string get_inline_usage() const {
std::stringstream usage;
// Find the longest variant to show in the usage string
std::string longest_name = m_names[0];
std::string longest_name = m_names.front();
for (const auto &s : m_names) {
if (s.size() > longest_name.size()) {
longest_name = s;
Expand Down Expand Up @@ -758,6 +758,8 @@ class Argument {
std::stringstream stream;
if (!m_used_name.empty()) {
stream << m_used_name << ": ";
} else {
stream << m_names.front() << ": ";
}
if (m_num_args_range.is_exact()) {
stream << m_num_args_range.get_min();
Expand All @@ -773,7 +775,7 @@ class Argument {

void throw_required_arg_not_used_error() const {
std::stringstream stream;
stream << m_names[0] << ": required.";
stream << m_names.front() << ": required.";
throw std::runtime_error(stream.str());
}

Expand Down Expand Up @@ -1341,9 +1343,9 @@ class ArgumentParser {

// Add any options inline here
for (const auto &argument : this->m_optional_arguments) {
if (argument.m_names[0] == "-v") {
if (argument.m_names.front() == "-v") {
continue;
} else if (argument.m_names[0] == "-h") {
} else if (argument.m_names.front() == "-h") {
stream << " [-h]";
} else {
stream << " " << argument.get_inline_usage();
Expand Down
2 changes: 1 addition & 1 deletion test/test_positional_arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST_CASE("Missing expected positional argument" *
argparse::ArgumentParser program("test");
program.add_argument("input");
REQUIRE_THROWS_WITH_AS(program.parse_args({"test"}),
"1 argument(s) expected. 0 provided.",
"input: 1 argument(s) expected. 0 provided.",
std::runtime_error);
}

Expand Down