Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Apr 7, 2024
1 parent bbde80c commit 0c08fae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitpicker.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{
"user": "p-ranav",
"repo": "argparse",
"branch": "a1c41c5537c919c1a56661ec1cdf5a49b9e99af6",
"branch": "9550b0a88c85120a0bf456af935eed2956c73340",
"root": "include/argparse",
"file": [
"argparse.hpp"
Expand Down
30 changes: 30 additions & 0 deletions argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,20 @@ class Argument {
return *this;
}

auto &store_into(std::vector<int> &var) {
if (m_default_value.has_value()) {
var = std::any_cast<std::vector<int>>(m_default_value);
}
action([this, &var](const std::string &s) {
if (!m_is_used) {
var.clear();
}
m_is_used = true;
var.push_back(details::parse_number<int, details::radix_10>()(s));
});
return *this;
}

auto &append() {
m_is_repeatable = true;
return *this;
Expand Down Expand Up @@ -2322,6 +2336,22 @@ class ArgumentParser {
}
}
auto argument = positional_argument_it++;

// Deal with the situation of <positional_arg1>... <positional_arg2>
if (argument->m_num_args_range.get_min() == 1 &&
argument->m_num_args_range.get_max() == (std::numeric_limits<std::size_t>::max)() &&
positional_argument_it != std::end(m_positional_arguments) &&
std::next(positional_argument_it) == std::end(m_positional_arguments) &&
positional_argument_it->m_num_args_range.get_min() == 1 &&
positional_argument_it->m_num_args_range.get_max() == 1 ) {
if (std::next(it) != end) {
positional_argument_it->consume(std::prev(end), end);
end = std::prev(end);
} else {
throw std::runtime_error("Missing " + positional_argument_it->m_names.front());
}
}

it = argument->consume(it, end);
continue;
}
Expand Down

0 comments on commit 0c08fae

Please sign in to comment.