mirror of
https://github.com/CLIUtils/CLI11.git
synced 2026-01-19 04:52:08 +00:00
Fix the order of arguments in command-line parsing error message (#1158)
CLI11 code prints the command-line arguments in reversed order in the
error message.
Code to reproduce:
```c++
#include <string>
#include <CLI/CLI.hpp>
int main(int argc, const char **argv)
{
CLI::App app{"Bug report app"};
std::string foo;
app.add_option("--foo", foo, "Foo option");
CLI11_PARSE(app, argc, argv);
return 0;
}
```
Reproduction:
```
$ g++ -Wall -Wextra -I CLI11/include/ cli11-bug-order-in-error.cpp -o cli11-bug-order-in-error && ./cli11-bug-order-in-error --foo bar --fizz buzz
The following arguments were not expected: buzz --fizz
Run with --help for more information.
```
Expected result:
```
The following arguments were not expected: --fizz buzz
Run with --help for more information.
```
This commit is contained in:
committed by
GitHub
parent
c31476b01a
commit
1364746d4c
@@ -310,13 +310,13 @@ class ExtrasError : public ParseError {
|
||||
explicit ExtrasError(std::vector<std::string> args)
|
||||
: ExtrasError((args.size() > 1 ? "The following arguments were not expected: "
|
||||
: "The following argument was not expected: ") +
|
||||
detail::rjoin(args, " "),
|
||||
detail::join(args, " "),
|
||||
ExitCodes::ExtrasError) {}
|
||||
ExtrasError(const std::string &name, std::vector<std::string> args)
|
||||
: ExtrasError(name,
|
||||
(args.size() > 1 ? "The following arguments were not expected: "
|
||||
: "The following argument was not expected: ") +
|
||||
detail::rjoin(args, " "),
|
||||
detail::join(args, " "),
|
||||
ExitCodes::ExtrasError) {}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user