I am using boost::program_options like this:
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 command line parameter -I hithere it works, but it I pass /I hithere boost throws a boost::bad_any_cast with a what() of ” failed conversion using boost::any_cast”.
Is it possible to use program_options to parse either /-delimitted or --delimitted options? Bonus question, can it be configured so that / and - set the same option, but are binary opposites of each other? For example, /verbose might mean verbose logging while -verbose might mean less verbose logging.
To use
/and-, usecommand_line_parser‘sstyle()method with the appropriate combination of style_t flags. For example:(
allow_long_disguiselets/start a long option.)You could probably make
/and-opposites by adding your own additional parser; however, this would be very nonstandard and therefore potentially confusing to end users, so I’m not sure it’s a good idea.