Skip to content

Option groups

Fernando Martin edited this page Feb 13, 2019 · 4 revisions

Options can be grouped, so that a subset of options can be printed in the help. To add options to a group, the function cxxopts::Options::add_options is called with a string, which is the name of the group. Then, every call to operator() in that statement will add the options to the specified group.

For example, if we have an object:

cxxopts::Options options("MyProgram", "One line description of MyProgram");

then the following adds options to the group "libraries":

options.add_options("libraries")
  ("shared", "Shared libraries")
  ("static", "Static libraries")
;

Printing help

By default, options.help() only gives the help for the default group (""). To print help for other groups, give help a vector of strings in the order that you want the groups to be printed. The default group must be specified if it is required. For example, to print the help for "", "libraries", and "GTK", in that order:

options.help({"", "libraries", "GTK"});

Note that there are no special options generated for help groups, such as --help-libraries in this example. If you wish to have such options, you must provide them yourself. The choice was also made to not do anything special when the --help option is seen, so that the application can choose how to display the help.

Clone this wiki locally