CommandLineParser::has() does not work when providing a value

asked 2015-03-06 04:58:14 -0600

I'm using opencv-3.0.0-beta on Slackware64, with the -std=c++11 flag to g++.

My program needs a command-line argument, and I have to check if the user has passed it (by the way, I don't know who's going to read this, but it would be nice if CommandLineParser supported required arguments to be checked with check()).

The problem is that has() does not seem to work unless the argument is passed "standalone" (i.e., as a boolean).

Here is my test program:

#include <opencv2/core.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
        // Initialize command-line parser
        string parser_keys = "{a arg |   | test argument}";
        CommandLineParser parser(argc, argv, parser_keys);
        // Check field
        if(!parser.has("a"))
        {
                cerr << "argument required" << endl;
        }
        else
        {
                cout << "ok" << endl;
        }
}

and here is my output:

$ ./test_parser_has
argument required
$ ./test_parser_has -a
ok
$ ./test_parser_has --a
ok
$ ./test_parser_has -a=1
argument required
$ ./test_parser_has --a=1
argument required

My expected result would be "ok" for the last two tests.

edit retag flag offensive close merge delete