I am trying to get the following syntax with boost :: program_options:
a) $ a.out verbosity: 0 b) $ a.out -v verbosity: 1 c) $ a.out -v -v verbosity: 2 d) $ a.out -vv verbosity: 2 e) (optional) $ a.out -v3 verbosity: 3
My program:
#include <iostream> #include <boost/program_options.hpp> namespace po = boost::program_options; int main(int argc, char *argv[]) { po::options_description desc; desc.add_options() ("verbose,v", po::value<int>(), "verbose"); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(desc).run(), vm); po::notify(vm); std::cout << "verbosity: " << vm["verbose"].as<int>() << std::endl; return 0; }
This only works for e). If I change it to:
po::value<int>()->default_value(0)
works for a) and e). WITH
po::value<int>()->default_value(0)->implicit_value(1)
it works for a), b) and e).
How can I get him to analyze all the above cases?
I think I need a combination of a vector of values ββwith zero_tokens (), but I can't get it to work.
chris source share