Skip to content
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

Weird behavior when wrong option was given #461

Closed
patlecat opened this issue May 24, 2020 · 5 comments
Closed

Weird behavior when wrong option was given #461

patlecat opened this issue May 24, 2020 · 5 comments

Comments

@patlecat
Copy link

When I have defined a few options but NOT "-x" and then I call the program with "-x" then no error is given and my if() is never reached where I'm testing for mycli11.empty() with each defined option!

Request:
It would be good to have a count of given valid options/flags and a count of invalid options/flags after parsing.

@phlptp
Copy link
Collaborator

phlptp commented May 24, 2020

What operation are you using to check? I am not sure there is an empty() function on a CLI11::App? or are you doing it on each option separately?

count() will return if it is processed
count_all() will return the number or processed arguments.

if allow_extras() is set to true then the processing won't error when an unrecognized argument is passed. but it will be available in remaining()

@patlecat
Copy link
Author

patlecat commented May 24, 2020

Sure there is:
auto list = m_conf.add_flag("--list", "List all available xx with complete options");
And then ...

if (!list->empty())
 {
     this->f_listall = true;
 }

But like I said, the lib shows weird behaviour since code after the parsing in the try-catch block no code below is executed anymore.

@patlecat
Copy link
Author

remaining() doesn't seem to do what you said, I couldn't use it this way to get all unrecognised paramters, would be nice though, exactly what I need!

From the code: "This returns the missing options from the current subcommand"

@henryiii
Copy link
Collaborator

By default, extra options are not allowed. You have to set app.allow_extras(). Then, if you do, it collects and returns all the left over arguments (options or otherwise) that show up on the command line. Those are in remaining. If it's not working, can you post a minimal (not) working example (MWE)?

Since you mentioned the try-catch block, maybe you are forgetting to return app.exit(e)? Without enabling extras, the default behavior is to throw a parse exception.

@patlecat
Copy link
Author

I'm doing the app.exit and it doesn't seem to work. If I can find some time I'll do a simple example, but I can't promise.

@patlecat patlecat closed this as completed Jul 3, 2020
nksanthosh added a commit to EOSIO/eos that referenced this issue Aug 3, 2020
This CLI11 update from v1.9.0 to v1.9.1 provides the following improvements: 
- Support relative inclusion [#475](CLIUtils/CLI11#475)
- Fix cases where spaces in paths could break CMake support [#471](CLIUtils/CLI11#471)
- Fix an issue with string conversion [#421](CLIUtils/CLI11#421)
- Cross-compiling improvement for Conan.io [#430](CLIUtils/CLI11#430)
- Fix option group default propagation [#450](CLIUtils/CLI11#450)
- Fix for C++20 [#459](CLIUtils/CLI11#459)
- Support compiling with RTTI off [#461](CLIUtils/CLI11#461)
dimas1185 pushed a commit to EOSIO/eos that referenced this issue Aug 4, 2020
This CLI11 update from v1.9.0 to v1.9.1 provides the following improvements: 
- Support relative inclusion [#475](CLIUtils/CLI11#475)
- Fix cases where spaces in paths could break CMake support [#471](CLIUtils/CLI11#471)
- Fix an issue with string conversion [#421](CLIUtils/CLI11#421)
- Cross-compiling improvement for Conan.io [#430](CLIUtils/CLI11#430)
- Fix option group default propagation [#450](CLIUtils/CLI11#450)
- Fix for C++20 [#459](CLIUtils/CLI11#459)
- Support compiling with RTTI off [#461](CLIUtils/CLI11#461)
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

No branches or pull requests

3 participants