mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
commit
e9ae471ea4
@ -597,7 +597,7 @@ public:
|
|||||||
std::string get_inline_usage() const {
|
std::string get_inline_usage() const {
|
||||||
std::stringstream usage;
|
std::stringstream usage;
|
||||||
// Find the longest variant to show in the usage string
|
// 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) {
|
for (const auto &s : m_names) {
|
||||||
if (s.size() > longest_name.size()) {
|
if (s.size() > longest_name.size()) {
|
||||||
longest_name = s;
|
longest_name = s;
|
||||||
@ -758,6 +758,8 @@ private:
|
|||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
if (!m_used_name.empty()) {
|
if (!m_used_name.empty()) {
|
||||||
stream << m_used_name << ": ";
|
stream << m_used_name << ": ";
|
||||||
|
} else {
|
||||||
|
stream << m_names.front() << ": ";
|
||||||
}
|
}
|
||||||
if (m_num_args_range.is_exact()) {
|
if (m_num_args_range.is_exact()) {
|
||||||
stream << m_num_args_range.get_min();
|
stream << m_num_args_range.get_min();
|
||||||
@ -773,7 +775,7 @@ private:
|
|||||||
|
|
||||||
void throw_required_arg_not_used_error() const {
|
void throw_required_arg_not_used_error() const {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream << m_names[0] << ": required.";
|
stream << m_names.front() << ": required.";
|
||||||
throw std::runtime_error(stream.str());
|
throw std::runtime_error(stream.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1341,9 +1343,9 @@ public:
|
|||||||
|
|
||||||
// Add any options inline here
|
// Add any options inline here
|
||||||
for (const auto &argument : this->m_optional_arguments) {
|
for (const auto &argument : this->m_optional_arguments) {
|
||||||
if (argument.m_names[0] == "-v") {
|
if (argument.m_names.front() == "-v") {
|
||||||
continue;
|
continue;
|
||||||
} else if (argument.m_names[0] == "-h") {
|
} else if (argument.m_names.front() == "-h") {
|
||||||
stream << " [-h]";
|
stream << " [-h]";
|
||||||
} else {
|
} else {
|
||||||
stream << " " << argument.get_inline_usage();
|
stream << " " << argument.get_inline_usage();
|
||||||
|
@ -18,7 +18,7 @@ TEST_CASE("Missing expected positional argument" *
|
|||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("input");
|
program.add_argument("input");
|
||||||
REQUIRE_THROWS_WITH_AS(program.parse_args({"test"}),
|
REQUIRE_THROWS_WITH_AS(program.parse_args({"test"}),
|
||||||
"1 argument(s) expected. 0 provided.",
|
"input: 1 argument(s) expected. 0 provided.",
|
||||||
std::runtime_error);
|
std::runtime_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user