Skip to content

Problem of parsing with additional optional arguments #1194

@najibprog

Description

@najibprog

Context

Hi, I'm using CLI11 in my project, and it's a very nice alternative to the Boost parser!

This is my variable parser:

CLI::App _cmdLineOptionsCLI;

I'm using the function _cmdLineOptionsCLI.parse(argc, argv) by giving a vector of options.
It may be that the options in argv are not in the options defined by add_options, so I added a

cmdLineOptionsCLI.allow_extras(true);

The problem

When I have for example "--nbVar ; 5" in my argv and are not defined in add_options, "--nbVar" is considered by the classifier like a Classifier::LONG and "5" is considered like a Classifier::NONE, so with the first arguments, we pop correctly the option, but with 5 we reach this line of code

posOpt = opt.get(); in CLI11_INLINE bool App::_parse_positional

By reaching this line, it fills a variable containing options defined by add_options, which is incorrect.

A solution proposed

If we add some lines to pop_back the argument and the value if the classifier is SHORT, LONG, WINDOWS_STYLE, it solves the problem. We suppose that if we have extra args like this "--nbVar 5", we can remove two elements instead of only one.
Is it possible to add these lines of code like this?

        if(current_type == detail::Classifier::LONG || current_type == detail::Classifier::WINDOWS_STYLE ||
           current_type == detail::Classifier::SHORT ) {
                args.pop_back();
        }

App_inl.hpp line 2005.

Best regards,
Najib

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions