Boost logo

Boost Users :

Subject: Re: [Boost-users] [Program Options] terminate parsing after first positional argument
From: Stuart Pook (stuart8763_at_[hidden])
Date: 2012-07-05 07:10:03


On 04/07/2012 18:37, Evan Driscoll wrote:
> On 01/-10/-28163 01:59 PM, Stuart Pook wrote:

that's a weird date!

>> How can I tell Boost Program Options to stop parsing the arguments
>> as soon as it finds a positional argument?
> I asked this question a few weeks ago and filed a feature request:
> https://svn.boost.org/trac/boost/ticket/6991

I guess that the short answer is that you cannot. You cannot write env(1), sudo(1), xargs(1) ... using boost::program_options

Thanks for your answer. I'm sorry that I missed your question and spent so long looking for a solution :-(

I rewrote my program using getopts. I lost the long option names but I got the behaviour I need: the parsing stops as soon it finds a non-option argument.

I can now write:

  gaingroup -g w-navicell-gp date -u

instead of

  gaingroup -g w-navicell-gp -- date -u

    for (int opt; (opt = getopt(argc, argv, "+hqivg:")) != -1; )
    {
        switch (opt)
        {
        case 'h':
            std::cout << desc;
            exit(0);
            break;

        case 'v':
            *verbose = true;
            break;

        case 'i':
            *ignore = true;
            break;

        case 'q':
            *quiet = true;
            break;

        case 'g':
            *group = optarg;
            break;

        default: /* '?' */
            std::cerr << desc;
            exit(exit_codes::usage);
        }
    }
    *command = argv + optind;

Stuart


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net