Drew
Drew

Reputation: 537

boost program_option case insensitive parsing

Has anyone worked out how to get boost program options to parse case insensitive argument lists

In the boost documentation, it appears that it is supported. See http://www.boost.org/doc/libs/1_53_0/boost/program_options/cmdline.hpp

Namely, setting the style_t enum flag such as long_case_insensitive. However, I'm not sure how to do it. Eg how would you get the following code snippet to accept --Help or --help or --HELP

    po::options_description desc("Allowed options");
    desc.add_options()
        ("help", "produce help message")
        ("compression", po::value<double>(), "set compression level")
    ;

    po::variables_map vm;        
    po::store(po::parse_command_line(ac, av, desc), vm);
    po::notify(vm);    

    if (vm.count("help")) {
        cout << desc << "\n";
        return 0;
    }

Upvotes: 2

Views: 1403

Answers (1)

Andrew Prock
Andrew Prock

Reputation: 7117

You can modify the style when you call store. I believe this should work for you:

namespace po_style = boost::program_options::command_line_style;

po::variables_map vm;        
po::store(po::command_line_parser(argc, argv).options(desc)
          .style(po_style::unix_style|po_style::case_insensitive).run(), vm);
po::notify(vm);    

Upvotes: 7

Related Questions