Questions tagged [boost-program-options]

Boost.Program_options is a C++ library that allows program developers to obtain (name, value) pairs from the user via conventional methods such as command line and config file.

Boost.Program_options is a C++ library that allows program developers to obtain program options, that is (name, value) pairs from the user, via conventional methods such as command line and config file.

Why would you use such a library, and why is it better than parsing your command line by straightforward hand-written code?

  • It's easier. The syntax for declaring options is simple, and the library itself is small. Things like conversion of option values to desired type and storing into program variables are handled automatically.
  • Error reporting is better. All the problems with the command line are reported, while hand-written code can just misparse the input. In addition, the usage message can be automatically generated, to avoid falling out of sync with the real list of options.
  • Options can be read from anywhere. Sooner or later the command line will be not enough for your users, and you'll want config files or maybe even environment variables. These can be added without significant effort on your part.
381 questions
5
votes
0 answers

Reload option values in boost::program_options from new source

I'm just starting to dig into boost::program_options for the first time. I like it quite a bit. However, what I'm trying to accomplish with it doesn't seem to be something its designers have accounted for. I want to use boost::program_options to…
Stephen
  • 3,515
  • 5
  • 27
  • 33
5
votes
2 answers

Boost program options- crash on parsing command line

I have the following boost::program_options program. boost::program_options::options_description opts("Allowed options"); opts.add_options() ("help", "produce help message"), ("mingw", boost::program_options::value(), "Set the…
Puppy
  • 144,682
  • 38
  • 256
  • 465
5
votes
1 answer

How to display commandline operand description in --help output

I am using Boost.program_options to parse commandlines for my implementation of POSIX utilities. As a simple example, take cmp. Now I would like to have an extra argument --help which shows a description of all arguments, which is important in this…
rubenvb
  • 74,642
  • 33
  • 187
  • 332
5
votes
2 answers

boost::program_options for single-byte variables

*emphasized text*How can I use Boost program options to accept single-byte variables from the command line? Command line parameters of --id1=1 --id2=1 results in values of id1=49 (or '1', 0x31) and id2=1. #include #include…
Jim Fred
  • 1,076
  • 13
  • 27
5
votes
2 answers

how do I get the non-flag and non-option tokens after boost::program_options parses my command line args

In python, I can construct my optparse instance such that it will automatically filter out the options and non-option/flags into two different buckets: (options, args) = parser.parse_args() With boost::program_options, how do I retrieve a list of…
Ross Rogers
  • 23,523
  • 27
  • 108
  • 164
5
votes
2 answers

How does one extract the sequence of parsed options using Boost Program Options?

I'm building a graph generator using Boost Graph and Program Options. There are, for example, two types of components C and W, each with 1 source, 1 sink and some additional parameters to specify topology in between. I'd like to be able to stitch…
scribbleink
  • 355
  • 2
  • 7
5
votes
1 answer

Parsing a configuration file with boost::program_options

Good day, i wrote a class to parse a configuration file via boost::program_options. Here is what I have (shortened): namespace nsProOp = boost::program_options; nsProOp::variables_map m_variableMap; nsProOp::options_description m_description; //…
Anonymous
  • 4,617
  • 9
  • 48
  • 61
5
votes
1 answer

boost program options choices

Is there a simple way to check if the argument of an option is inside a set of predefined choices? "Simple" here means without defining an ad-hoc class. Suppose I have the option --myoption which must have value "myvalue1" or "myvalue2" For example…
Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141
4
votes
1 answer

Is there a parser that interprets colon and comma notation?

I'm new to using Using boost::program_options, and I'd like to parse a numeric command line argument with colon and comma notation. For example i'd like to have this kind of argument: myprogram --numbers 1:100,200,300 Produce a vector with the…
2NinerRomeo
  • 2,687
  • 4
  • 29
  • 35
4
votes
1 answer

setprecision for boost::program_options

Is there a way to change how boost::program_options formats the default value of the options in the help text of a program_options::options_description (that one can obtains through cout << description)? In particular I have default values which…
antony
  • 2,877
  • 4
  • 31
  • 43
4
votes
2 answers

How to use and link boost on macOS using CMake?

Thank you for all who helped! What finally worked was changing: set(CMAKE_CXX_COMPILER "gcc-10") set(CMAKE_C_COMPILER "g++-10") to: set(CMAKE_CXX_COMPILER "/usr/local/opt/llvm/bin/clang") set(CMAKE_C_COMPILER "/usr/local/opt/llvm/bin/clang++") I…
adisidev
  • 162
  • 1
  • 15
4
votes
2 answers

Use boost::program_options to specify multiple flags

I want to use boost::program_options to specify the required verbosity as is pretty common. E.g. ./test -v # verbosity = 1 ./test -vvv # verbosity = 3 ./test -v blah blah -v # verbosity = 2 I know how to do multiple occurences of options that…
4
votes
2 answers

boost::program_options vector of values with zero_token

I'm trying to get the following syntax parsed 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 so…
chris
  • 3,986
  • 1
  • 26
  • 32
4
votes
1 answer

autocomplete boost program options

after hours of search I ended up writing my first stackoverflow question. I want to create a completion function for a bash script, so far so good ;). This bash script calls other executables that have their own autocompletion. Example: $ my_script…
4
votes
1 answer

Why does bcp calculate such a large dependency list for Boost program_options?

I'm writing a small program using boost/program_options to handle options from command line. Now I want to distribute my code to systems where in general Boost is not installed. So I used the bcp utility. I tried it on the example from Boost called…
Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141