Skip to content

Fix the order of arguments in command-line parsing error message #1158

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

Conversation

agalanin-at-nvidia
Copy link
Contributor

CLI11 code prints the command-line arguments in reversed order in the error message.

Code to reproduce:

#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.

@agalanin-at-nvidia agalanin-at-nvidia changed the title Fix the order of argument in command-line parsing error message Fix the order of arguments in command-line parsing error message May 5, 2025
Copy link

codecov bot commented May 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e4ee3af) to head (9e85fc6).
Report is 91 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##              main     #1158     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files           17        17             
  Lines         4546      5042    +496     
  Branches         0      1024   +1024     
===========================================
+ Hits          4546      5042    +496     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@phlptp
Copy link
Collaborator

phlptp commented May 6, 2025

I think there are a couple spots where calling the ExtrasError was correct with the rjoin so we are probably going to have to either reverse those vectors or the calls where this change is now correct. I think we will also want a couple test cases that check for this error in the various situations ExtrasError arises. I can help with the test cases if needed but might be a few days.

@phlptp
Copy link
Collaborator

phlptp commented May 9, 2025

Going to merge this, I will add a few tests and checks on some other situations soon

@phlptp phlptp merged commit 1364746 into CLIUtils:main May 9, 2025
58 checks passed
phlptp added a commit that referenced this pull request May 9, 2025
Adds tests and checks for Extras Error 
Builds on #1158

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants