Can force :: program_options Use a separator other than "-"?

I use boost :: program_options as follows:

namespace po = boost::program_options; po::options_description desc("Options"); desc.add_options() ("help,?", "Show Options") ("capture-file,I", po::value<string>(), "Capture File") ("capture-format,F", po::value<string>()->default_value("pcap"), "Capture File Format") ("output-file,O", po::value<string>()->default_value("CONOUT$"), "Output File"); po::variables_map vm; po::store(po::command_line_parser(ac, av).options(desc)./*positional(pd).*/run(), vm); 

If I pass the -I hithere command-line -I hithere , it works, but I pass /I hithere boost, throws a boost::bad_any_cast with what() from "failed conversion using boost :: any_cast".

Can I use program_options to parse the / -delimitted or - -delimitted options? The bonus question is, can it be configured so that / and - set the same option, but are binary opposites from each other? For example, /verbose may mean verbose logging, and -verbose may mean less verbose logging.

+6
c ++ boost-program-options
source share
1 answer

To use / and - , use the command_line_parser style() method with the appropriate combination of style_t flags. For example:

 po::store(po::command_line_parser(ac, av) .options(desc) .style(po::command_line_style::default_style | po::command_line_style::case_insensitive | po::command_line_style::allow_slash_for_short | po::command_line_style::allow_long_disguise) /*.positional(pd)*/ .run(), vm); 

( allow_long_disguise allows / to start a long option.)

Perhaps you could do the opposite / - by adding your own extra parser ; however, this would be very non-standard and therefore potentially confusing for end users, so I'm not sure if this is a good idea.

+9
source share

All Articles