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
4
votes
1 answer

boost::program_options: how to get the application name?

Using Boost Program Options, how do you get the string equivalent of argv[0]?
sivabudh
  • 31,807
  • 63
  • 162
  • 228
4
votes
0 answers

Combining boost::program_options and JSON

I am currently using boost::program_options to parse command line and config-file arguments. However, recently I have realised I need to be able to pass my program a list of options which could be very easily summarised using e.g. JSON…
4
votes
1 answer

Disallow negative argument for unsigned value with boost::program_options

Suppose I have a program using boost::program_options to parse command line arguments, and one has an unsigned value: #include #include namespace po = boost::program_options; int main(int argc, char* argv[])…
Nick Matteo
  • 4,453
  • 1
  • 24
  • 35
4
votes
2 answers

Can I use Boost program_options to get multiple arbitrary-key-value pairs?

I'm writing a program using Boost's program_options library. Now, I want to allow it to extend with arbitrary code, which the configuration parser is not aware of - but which would still get some specific options passed to it. My idea was to…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
4
votes
1 answer

Boost.Program_options not linking correctly under Clang

The following initial example from the Boost.Program_options documentation // Copyright Vladimir Prus 2002-2004. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt // or copy at…
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
4
votes
3 answers

Can Boost Program_options separate comma separated argument values

If my command line is: > prog --mylist=a,b,c Can Boost's program_options be setup to see three distinct argument values for the mylist argument? I have configured program_options as: namespace po = boost::program_options; po::options_description…
Louis Marascio
  • 2,629
  • 24
  • 28
4
votes
1 answer

parsing command-line options with sequence containers?

This question has come up before, but it seems that none of the answers provide alternatives with boost-style generic programming. Like many I use boost:program_options to parse command line line options. My current project is a program to…
alle_meije
  • 2,424
  • 1
  • 19
  • 40
4
votes
1 answer

Using Custom Types with Boost Program Options

I am trying to use Boost ProgramOptions to parse a config file to initialize my own class type Dataset (code below) I am adding the option as: config_.add_options()("dataset", po::value()->required(),"Dataset"); My Dataset class is…
iNFINITEi
  • 1,504
  • 16
  • 23
4
votes
1 answer

Specifying levels (e.g. --verbose) using Boost program_options

Some of my options have multiple levels, e.g. of "verbosity". I would like my users to choose between the following two equivalent styles: // no argument: verbosity of 1 my_program -v // count the 'v's: verbosity of 4 my_program -vv…
Leo Goodstadt
  • 2,519
  • 1
  • 23
  • 23
4
votes
1 answer

what can and can't I do with boost.program_options?

I currently use some old C library for getting program options and would like to replace that with some proper C++ (mainly to become independent of that library, which is a real burden). I was looking into using boost.program_options, but am not…
Walter
  • 44,150
  • 20
  • 113
  • 196
4
votes
2 answers

Boost program_options with composing() and implicit_value() are not "composed"

I am having a problem with boost program_options (v1_49) in the case of an option defined as composing() and also implicit(). My intent is to implement a -D option similar to the way perl does, so that you can do -D or -Dname and use it multiple…
user9645
  • 6,286
  • 6
  • 29
  • 43
3
votes
0 answers

Allow only `--option=arg` argument style with boost::program_options

Using boost::program_options, I'd like to allow only --option=arg style for arguments and forbid the space separated --option arg which is sometimes ambiguous when arguments are optional. Looks kind of possible. Having a look at cmdline.hpp source…
3
votes
3 answers

boost program_options values with different types

How can I provide an option to the boost program_options, which will accept 3 values with different types: [int, int, float]? For example: ./app_name --check-integrity 1 2.2 --do_something 2 2 2.5 I've tried to achieve that with a vector of…
user3193620
  • 173
  • 1
  • 11
3
votes
2 answers

How to store data in boost::program_options::variable_map?

I am currently trying to rework some code that was handed down to me. The original point of the code is to read a configuration file, and to set up the different options in the file in a boost::program_options::variable_map, which is then read…
Pfrances
  • 107
  • 1
  • 11
3
votes
2 answers

Using boost::program_options with own template class possible?

I'm currently start using boost::program_options for parsing command line options as well as configuration files. Is it possible to use own template classes as option arguments? That means, something like #include #include…
Aeon512
  • 33
  • 2