Boost logo

Boost Users :

Subject: Re: [Boost-users] program_options allow_unregistered and *nix style
From: Michael Powell (mwpowellhtx_at_[hidden])
Date: 2013-04-16 12:18:02


On Tue, Apr 16, 2013 at 9:38 AM, Michael Powell <mwpowellhtx_at_[hidden]>wrote:

>
>
>
> On Fri, Apr 12, 2013 at 7:16 PM, Larry <lknain_at_[hidden]> wrote:
>
>> Not necessarily the best example in the world but the following works
>> for me:
>>
>
> Thanks so much. It is sufficient.
>
> using namespace boost::program_options;
>> namespace po = boost::program_options;
>>
>> const int style(command_line_style::default_style +
>> command_line_style::allow_long_disguise +
>> command_line_style::allow_dash_for_short);
>> po::variables_map vm;
>> vector<string> unreg;
>>
>
I gather the unreg options includes the command line executable itself?
argv[0]?

>> //-----------------------------------------------------------------------------
>> // Set up options
>>
>> //-----------------------------------------------------------------------------
>>
>> po::options_description desc("Allowed options");
>> desc.add_options()
>> ("help,h", "produce help message")
>> ("input-file,i", po::value<vector<string> >(), "input file")
>> ("debug,d", po::value<string>(), "debug")
>> ("noupdates,x", po::value<string>(), "no updates")
>> ;
>>
>>
>> //-----------------------------------------------------------------------------
>> // Parse the command line
>>
>> //-----------------------------------------------------------------------------
>>
>> parsed_options parsed =
>> command_line_parser(argc,argv).style(style).options(desc).allow_unregistered().run();
>> unreg = collect_unrecognized(parsed.options,include_positional);
>> po::store(parsed, vm);
>> po::notify(vm);
>>
>>
>> Much of the style stuff is documented only if you wade through code.
>> unreg will contain the unrecognized items.
>>
>> Larry
>>
>> *From:* Michael Powell <mwpowellhtx_at_[hidden]>
>> *Sent:* Friday, April 12, 2013 4:03 PM
>> *To:* boost-users_at_[hidden]
>> *Subject:* [Boost-users] program_options allow_unregistered and *nix
>> style
>>
>> Hello,
>>
>> I would like to find a way to allow_unregistered program_options, as well
>> as specify cls::unix_style ^ cls::allow_short, where cls is
>> po::command_line_style.
>>
>> The code I've got here doesn't seem to like unrecognized ones:
>>
>> //vis_ are my visible options, vars_ is my variable map.
>> po::store(parse_command_line(argc, argv, vis_,
>> cls::unix_style ^ cls::allow_short), vars_);
>> po::notify(vars_);
>>
>> And then a slight variation with apparently a way to do this (untested),
>> how to specify that cls?
>>
>> //
>> http://stackoverflow.com/questions/10178525/how-to-handle-unsolicited-parameters-in-boostprogram-options
>> po::parsed_options parsed_ = po::command_line_parser(argc, argv)
>> .options(vis_).allow_unregistered().run();
>>
>> Possible? Thank ye...
>>
>> Regards,
>>
>> Michael Powell
>>
>> ------------------------------
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>>
>> _______________________________________________
>> 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