options_description desc; desc.add_options() ("foo", parameter<int>("arg"), "obscure option") ;
If you pass an address of int
variable as the second parameter of the parameter
function, that variable will be assigned the options's value.
Anyway, there's a version of the parse_command_line function which does not take an options_description instance. Also, the cmdline class ctor accepts an 'allow_unregistered' parameter. In both cases, all options will be allowed, and treated as if they have optional parameter.
Note that with the default style,
--foo bar
options_description
class somewhere near main
. All the modules will export their own options using other options_description
instances which can be added to the main one. After that, you'd parse command line and config files. The parsing results will be stored in one variables_map, which will be passed to all modules, which can work with their own options.
It's possible to give the module only the options that it has registered. First, the module provides an options_description instance which is added to the global one. Second the command line is parsed to produce an options_and_arguments instance. Lastly, the store
function is called. If passed the options_description instance previously returned by the module, it will store only options specified in that instance.
main
and used by all modules.This solution avoids all possible name clashes between modules. On the other hand, longer option names can be less user-friendly. This problem can be alleviated if module prefix is used only for less common option, needed for fine-tuning.