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
91
votes
4 answers

Required and Optional Arguments Using Boost Library Program Options

I'm using Boost Program Options Library to parse the command line arguments. I have the following requirements: Once "help" is provided, all the other options are optional; Once "help" is not provided, all the other options are required. How I can…
Peter Lee
  • 12,931
  • 11
  • 73
  • 100
52
votes
2 answers

Vector arguments in Boost Program Options

I have two related questions: What is the simplest way to allow passing a series of values, using Boost Program Options? My aim is to avoid prog --opt 1 --opt 2 --opt 3 and have prog --opt 1 2 3 instead. What is the simplest way to have an option…
Szabolcs
  • 24,728
  • 9
  • 85
  • 174
36
votes
3 answers

What is the difference between default_value and implicit_value in boost::program_options?

That's the question. Why would I use implicit_value over default_value and vice versa? Thanks!
shaz
  • 383
  • 3
  • 4
34
votes
2 answers

How to implement subcommands using Boost.Program_options?

I'd like to implement subcommands to my program. I also need the ability to have different argument options for different subcommands. What's the best way to do this using Boost.Program_options? Subcommands are used in programs like svn, git and…
Scintillo
  • 1,634
  • 1
  • 15
  • 29
34
votes
3 answers

Boost Program Options Examples

In the boost tutorials online for program options : http://www.boost.org/doc/libs/1_39_0/doc/html/program_options/tutorial.html#id2891824 It says that the complete code examples can be found at "BOOST_ROOT/libs/program_options/example" directory. I…
rayimag
  • 893
  • 3
  • 10
  • 18
29
votes
3 answers

boost-program-options: notifier for options with no value

One can use notifier for parsed options only if they have value_semantic. What is the best way for no-value options to be automatically handled by the given notifier? The simple approach is to make a dummy value_semantic with implicit assignment,…
Riga
  • 2,099
  • 1
  • 19
  • 27
29
votes
2 answers

How to use boost::program_options to accept an optional flag?

I need to implement an optional flag, say -f/--flag. Since this is a flag, there is no value associated. In my code I only need to know whether the flag was set or not. What's the proper way to do this using boost::program_options?
a06e
  • 18,594
  • 33
  • 93
  • 169
26
votes
2 answers

Boost Program Options Add Options Syntax

I am writing a program that uses Boost's Program Options library and I noticed the following syntax that has haunted me since I saw it: desc.add_options() ("help","produce help message") ( /* other flag, value, description pairs here…
paulrehkugler
  • 3,241
  • 24
  • 45
25
votes
1 answer

Boost Custom Validator for Enum

I am trying to validate command line input to an Enum that I've defined, but get compiler errors. I have used Handle complex options with Boost's program_options as an example to work from. namespace po = boost::program_options; namespace…
E-rich
  • 9,243
  • 11
  • 48
  • 79
24
votes
1 answer

How to have an optional option value in boost program options?

I am using the Boost program option and I want to offer an option which has three ways: If not define If defined but no value If defined with a value For example, I have a program that works on a file such as a.jpg, and I want to offer the user…
mans
  • 17,104
  • 45
  • 172
  • 321
24
votes
6 answers

When using boost::program_options, how does one set the name of the argument?

When using boost::program_options, how do I set the name of an argument for boost::program_options::value<>()? #include #include int main() { boost::program_options::options_description desc; …
Grumbel
  • 6,585
  • 6
  • 39
  • 50
23
votes
3 answers

Boost program options allowed set of input values

Is there a way to set an allowed set of input variables for parameters? For example parameter "arg" can have only string values like "cat" and "dog".
scdmb
  • 15,091
  • 21
  • 85
  • 128
23
votes
1 answer

How do I get default argument values with boost program options?

I want to use default values for some of my command line arguments. How do I tell program_options what the default option is, and, if the user doesn't supply the argument, how do I tell my program to use the default value? Say I want to have an…
flies
  • 2,017
  • 2
  • 24
  • 37
22
votes
1 answer

boost::program_options: undocumented "*" feature discovered, now need custom validator that writes to a map

I recently discovered an undocumented feature of boost::program_options, namely that it accepts "*" as a special wildcard that allows declaration of a group of options with the same prefix, like this: configOptions.add_options() ("item_*",…
user1876484
  • 610
  • 6
  • 16
21
votes
3 answers

Print help for both normal and positional args with boost::program_options

When you use Boost library program_options it is very easy to print help for your program: boost::program_options::variables_map options; boost::program_options::options_description optionsDesc; boost::program_options::positional_options_description…
nuoritoveri
  • 2,494
  • 1
  • 24
  • 28
1
2 3
25 26