Skip to content
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
4 changes: 4 additions & 0 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,10 @@ DECLARE_MESSAGE(NonRangeArgs,
"{actual} is an integer",
"the command '{command_name}' requires between {lower} and {upper} arguments, inclusive, but {actual} "
"were provided")
DECLARE_MESSAGE(NonRangeArgsGreater,
(msg::command_name, msg::lower, msg::actual),
"{actual} is an integer",
"the command '{command_name}' requires at least {lower} arguments, but {actual} were provided")
DECLARE_MESSAGE(NonZeroOrOneRemainingArgs,
(msg::command_name),
"",
Expand Down
2 changes: 2 additions & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,8 @@
"_NonOneRemainingArgs.comment": "An example of {command_name} is install.",
"NonRangeArgs": "the command '{command_name}' requires between {lower} and {upper} arguments, inclusive, but {actual} were provided",
"_NonRangeArgs.comment": "{actual} is an integer An example of {command_name} is install. An example of {lower} is 42. An example of {upper} is 42.",
"NonRangeArgsGreater": "the command '{command_name}' requires at least {lower} arguments, but {actual} were provided",
"_NonRangeArgsGreater.comment": "{actual} is an integer An example of {command_name} is install. An example of {lower} is 42.",
"NonZeroOrOneRemainingArgs": "the command '{command_name}' requires zero or one arguments",
"_NonZeroOrOneRemainingArgs.comment": "An example of {command_name} is install.",
"NonZeroRemainingArgs": "the command '{command_name}' does not accept any additional arguments",
Expand Down
9 changes: 9 additions & 0 deletions src/vcpkg-test/cmd-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,15 @@ TEST_CASE ("Consume remaining args", "[cmd_parser]")
CHECK(uut.get_errors() == expected_errors);
CHECK(uut.get_remaining_args().empty());
}

{
CmdParser uut{std::vector<std::string>{"first-arg", "second-arg"}};
CHECK(uut.consume_remaining_args("command", 3, SIZE_MAX) == std::vector<std::string>{});
const auto expected_errors =
localized({"error: the command 'command' requires at least 3 arguments, but 2 were provided"});
CHECK(uut.get_errors() == expected_errors);
CHECK(uut.get_remaining_args().empty());
}
}

TEST_CASE ("delistify_conjoined_value", "[cmd_parser]")
Expand Down
21 changes: 16 additions & 5 deletions src/vcpkg/base/cmd-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,11 +964,22 @@ namespace vcpkg
bool error = consume_remaining_args_impl(results);
if (max_arity < results.size() || results.size() < min_arity)
{
errors.emplace_back(msg::format_error(msgNonRangeArgs,
msg::command_name = command_name,
msg::lower = min_arity,
msg::upper = max_arity,
msg::actual = results.size()));
if (max_arity == SIZE_MAX)
{
errors.emplace_back(msg::format_error(msgNonRangeArgsGreater,
msg::command_name = command_name,
msg::lower = min_arity,
msg::actual = results.size()));
}
else
{
errors.emplace_back(msg::format_error(msgNonRangeArgs,
msg::command_name = command_name,
msg::lower = min_arity,
msg::upper = max_arity,
msg::actual = results.size()));
}

for (std::size_t idx = max_arity; idx < results.size(); ++idx)
{
errors.emplace_back(msg::format_error(msgUnexpectedArgument, msg::option = results[idx]));
Expand Down
Loading