2

I would just like to allow my user to specify the verbosity level by using multiple times the flag -v or --verbose. For instance:

  • foobar -v : verbosity level is 1
  • foobar : verbosity level is 0
  • foobar -vvv : verbosity level is 3

My current setting is:

po::options_description desc("Options for this program");
desc.add_options()
    ("verbose,v", "Turn on verbose mode")
    ...
;

po::variables_map opts;
po::store(po::parse_command_line(argc, argv, desc), opts);
po::notify(opts);

const int verbosity = opts.count("verbose"); // Can be 0 or 1

How should I modify this code so to allow verbosity to be greater than 1?

(Of course I could allow an option like -v 2, but I prefer -vv in this case, which is quite common.)

Spiros
  • 2,156
  • 2
  • 23
  • 42

0 Answers0