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

python module giving boost::program_option like functionality

Is there any boost::program_options like module for python
Akhil
  • 2,269
  • 6
  • 32
  • 39
3
votes
2 answers

How to build Boost::program_options (on linux)

I'm trying to use boost::program_options following the official instruction: http://www.boost.org/doc/libs/1_36_0/more/getting_started/unix-variants.html#link-your-program-to-a-boost-library But it doesn't…
Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141
3
votes
1 answer

skipping unknown options without throwing with boost program options

These days I am playing with Boost program options for reading INI files. The code I have throws an exception once in the file there is a line with an unknown option. Do you know whether is possible and how to let the code below read the whole file?…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
3
votes
2 answers

Dealing with sections of INI files with Boost.Program_options

I am trying to parse configuration INI files in Linux. I would like to use Boost and someone pointed me the program options library. The thing is that I can read lines having the syntax field=value, but how to deal with different sections i.e.…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
3
votes
1 answer

Boost program options, empty string handling

I'm trying to port old command line tool to boost::program_options. The tool is used in lots of 3rd-party scripts, some of them I cannot update, so changing of command line interface (CLI) is not the way for me. I have one positional argument,…
ivaigult
  • 6,198
  • 5
  • 38
  • 66
3
votes
1 answer

Inheriting options with Boost.ProgramOptions

Is there a good way to chain inherit program options from another options_description object in boost? For example auto general_options = po::options_description{}; general_options.add_options() ("flag", "Information for --flag"); auto…
Curious
  • 20,870
  • 8
  • 61
  • 146
3
votes
1 answer

Why does boost::any exhibit undefined behaviour in boost::program_options?

Let's take an example directly from boost's documentation: #include #include #include int main(int const ac, char** const av){ // Declare the supported options. namespace po =…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
3
votes
1 answer

boost:bad_any_cast: failed conversion using boost:any_cast error

Running into an issue with Boost Program Options. I added a multiple use option let's call it "--opt". When I run the program.exe from the command line with two "--opt" I get the following error from boost. terminating with uncaught exception of…
MikeG
  • 63
  • 1
  • 7
3
votes
1 answer

option '--opt' cannot be specified more than once

Running into an error from boost program options. I am running a command such as prog --opt arg1 --opt arg2. It returns this error option '--opt' cannot be specified more than once. Is there a way to use the option name more than once?…
MikeG
  • 63
  • 1
  • 7
3
votes
1 answer

Custom validator doesn't allow default_value

I am trying to use a custom validator instead of overloading operator>> to support an enum type in my option parsing. I have done the following: #include #include enum class MyEnum { OneThing, …
David Doria
  • 9,873
  • 17
  • 85
  • 147
3
votes
1 answer

boost::program_options : how to declare and validate my own option type when it belongs to a namespace?

Using boost::program_options, I can not get my own option type to compile when it is declared inside a namespace. However outside of the namespace it compiles and works fine : #include using namespace boost; using…
Francois
  • 2,005
  • 21
  • 39
3
votes
1 answer

boost program options - append multitoken options from config file to command-line

Using boost program options I am trying to allow the user to set default values for a multitoken argument in a config file (.ini) that will append to their command-line selections. Example: Program Options: m_Desc.add_options() ("settings,s",…
3
votes
1 answer

Short argument in boost::program_options without long

Is it possible to specify an argument with boost::program_options with short option only? The answer given here is to use allow_long_disguise, which will result in long options being acceptable with a single dash. Is there any way to make some…
SU3
  • 5,064
  • 3
  • 35
  • 66
3
votes
0 answers

boost::program_options: option recognizes following option as an argument when no argument is provided

I have a program that takes a few options and I want to recognize when no argument is provided. This is what happen when I call my program without one option arg program -lib cout: the required argument for option '-lib' is missing That's ok, but…
dlavila
  • 1,204
  • 11
  • 25
3
votes
1 answer

partial ordering variadic template function clang

I am currently playing on a project using Boost.ProgramOptions and I had to create the following structure to add some constraints on an option: template struct restrictedValues { ... }; In order to validate…
Jiwan
  • 731
  • 4
  • 11