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

boost program options - how to conditionally type positional args?

I'm using boost program options, and I want to interpret some positional arguments as either strings, or ints, based on a user specified command line switch. For example: foo -asint outputfile 10 11 12 foo -asstr outputfile 10 11 12 would list…
Andrew B.
  • 1,010
  • 6
  • 19
3
votes
1 answer

Why is boost::program_options accepting chopped words?

I have the following program: #include bool check_options(int argc, char** argv) { using namespace boost::program_options; variables_map vm; // Command line options std::string cfg_file_name; …
Emiliano
  • 22,232
  • 11
  • 45
  • 59
3
votes
1 answer

Compilation fail in Boost librairies (program_options)

Today I rebuilt my C++ application and the compilation failed. Nothing has changed though. The first error was in my class List which inherits from std::vector (private inheritance) here: template void List::append(const T& value) { …
lesenk
  • 793
  • 1
  • 8
  • 22
2
votes
1 answer

boost::program_options read an integer array from console

I want to read an integer array from console using boost::program_options. The length of the array is not known and I don't want to read all the data in one attempt. How can I do that? What I am doing now is $ ./foo --array "1, 2, 3" and then…
Akash Agrawal
  • 4,711
  • 5
  • 28
  • 26
2
votes
1 answer

How to overload operator<< for use with boost::program_options default value output?

I am using boost::program_options and want to pass "domain"-like options to my program. Such a domain is simply: template struct CDomain { CDomain(T min = -1, T max = 1) {_min = min; _max = max;}; T _min; T _max; }; I have written…
Christoph
  • 1,040
  • 3
  • 14
  • 29
2
votes
2 answers

Boost.program_options: implicit_value and Unicode results in compile-time error

I am using Boost.program_options library and need to specify implicit_value with Unicode support. For ansi-string this code works fine po::options_description desc("Usage"); desc.add_options() ("help,h", "produce help message") ("-option,o",…
user10101
  • 1,704
  • 2
  • 20
  • 49
2
votes
3 answers

boost program options parse_config_file

I want to save the settings (in a file) of my application in boost program_options way This is my function void MainWindow::saveSettings() { po::options_description desc("Allowed options"); desc.add_options() …
Poka Yoke
  • 373
  • 3
  • 8
  • 27
2
votes
0 answers

boost::program_options conditionally required option

My executable has two modes of operation which are selectable via --mode=foo or --mode=bar. If mode=foo, then --abc option should be required and --xyz should not be specified. If mode=bar, then --xyz option should be required and --abc should not…
Paul Grinberg
  • 1,184
  • 14
  • 37
2
votes
1 answer

What's the best way to pass an empty string as argument to boost::program_options?

I have a program that use boost::program_options to parse a command line. One of the parameter is the name of an AMQP exchange, and a default value is provided. For testing purposes, I would like to override this AMQP exchange name with an empty…
2
votes
2 answers

boost program_options: Read required parameter from config file

I want to use boost_program_options as follows: get name of an optional config file as a program option read mandatory options either from command line or the config file The problem is: The variable containing the config file name is not…
Åsmund
  • 1,332
  • 1
  • 15
  • 26
2
votes
1 answer

boost::program_options : how to add a program description text

I would like that a text is printed before the description of the allowed options when I print my options_description. Something like : This program counts from 1 to 10. <--- this is what is missing Generic options: -h [ --help ] Produce…
Barth
  • 15,135
  • 20
  • 70
  • 105
2
votes
1 answer

Q: Boost Program Options using std::filesystem::path as option fails when the given path contains spaces

I have a windows command line program using Boost.Program_Options. One option uses a std::filesystem::path variable. namespace fs = std::filesystem; namespace po = boost::program_options; fs::path optionsFile; po::options_description desc(…
2
votes
0 answers

Parsing an std::vector option in a config file with Boost.Program_options

It's already known that Boost.Program_options does not handle multitoken options in config files (separated by spaces) conveniently like when dealing with command-line options. The main solution that I found involves defining custom validators. As…
Wout12345
  • 91
  • 5
2
votes
2 answers

Boost program_options partial key match

I'm trying to read config files with Boost::program_options. The config files look like: hier.arch.y.option_name = 0x5 another.hier.archy.setting_name = 0x1E I want to be able to search by just "option_name" or "setting_name". I'm not worried too…
jkang
  • 483
  • 7
  • 19
2
votes
1 answer

Split value for vector option in boost program_options

I am working on an application that reads some options through a config file. The code uses boost program_options library to read the options. The application code has a class that does the following tasks related to reading the option…
Anil
  • 111
  • 6