On Fri, Apr 12, 2013 at 7:16 PM, Larry <lknain@nc.rr.com> wrote:
Not necessarily the best example in the world but the following works for me:
 
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;
 
    //-----------------------------------------------------------------------------
    // 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")
    ;
 
Question about the options_description: how about parsing with multiple sections?

For instance, I'd like to compose with a visible and hidden options strategy.

po::options_description visible;
//...
po::options_description temp("Temp options);
temp.add_options()
  ("myopt,m", "my option);
visible.add(temp);

Doesn't seem to parse. "myopt" falls through as unregistered.

I can simply populate visible for now I think. But eventually would like to group the options according to various business needs.

//-----------------------------------------------------------------------------
// 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
 
Sent: Friday, April 12, 2013 4:03 PM
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@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users