Boost logo

Boost Users :

Subject: Re: [Boost-users] [program_options] Limited multitoken
From: Dmitriy Matison (matison.d_at_[hidden])
Date: 2012-01-20 11:03:13


Hello, Brad:

What processing is done by your own parsing function?
Positional options after multitoken options are bad practice in
general. It's not an obvious and flexible approach. Imagine one of
your options changes tokens count, all users off your program will be
confused using their old command lines. If you like positionals, maybe
it's a workaround to use three positional values since your -j tokens
count is fixed? Multitoken options are commonly used in cases when you
have a variable length list of inputs, i.e. files.
If -j is optional, you can place it's values as positional after your
current positional option in your invocation scheme.

Regards,
Dmitriy.

On 20/01/2012, Bradley Jensen <bradley.jensen_at_[hidden]> wrote:
> Hello,
>
> I'm working on a personal project. Everything works using my own options
> processing function, but I am having a hard time implementing one specific
> aspect of my option processing code using the Boost program_options library.
>
> My program has a flag (-j) which takes in two doubles as arguments.
> Currently, I can invoke my program like so:
> ./foo -j 1.0 2.0 3
> where 3 is treated like a positional.
>
> Because the -j option must consume several tokens, it seemed natural that I
> should use multitoken, like so:
> vector<double> v;
> po::options_description desc("Allowed options");
> desc.add_options()
> ("jingle,j", po::value<vector<double> >(&v)->multitoken(), "Test thing");
>
> But this causes positional arguments to get eaten up and added to v when -j
> is the last flag option. So, in my example, v would contain 1.0, 2.0, and
> 3.0. I suppose I am looking for some way to indicate that the -j flag
> consumes exactly two tokens.
>
> I've looked over the documentation on the Boost website, but I couldn't find
> anything about this. Any help would be greatly appreciated.
>
> Thanks,
> -Brad
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
С уважением,
Матисон Дмитрий.

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