Skip to content

Weird behavior when wrong option was given #461

Closed

Description

@patlecat

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.

Activity

  1. phlptp commented on May 24, 2020

    @phlptp
    Collaborator

    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()

  2. patlecat commented on May 24, 2020

    @patlecat
    Author

    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.

  3. patlecat commented on May 24, 2020

    @patlecat
    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"

  4. henryiii commented on May 25, 2020

    @henryiii
    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.

  5. patlecat commented on May 25, 2020

    @patlecat
    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.

  6. added a commit that references this issue on Aug 3, 2020
  7. added a commit that references this issue on Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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