![]() |
CLI11 2.7.1
C++11 Command Line Interface Parser
|
The library was designed to bind to existing variables without requiring typed classes or inheritance. This is accomplished through lambda functions.
This looks like:
Obviously, you can't access T after the add_ method is over. To store the string representation of the default value, call capture_default_str() on the option (or use always_capture_default() to do this for every option). Only the low-level add_option overload taking a raw callback_t still accepts a defaulted bool argument.
Parsing follows the following procedure:
The parsing phase is the most interesting:
The _process procedure runs the following steps; each step is recursive and completes all subcommands before moving to the next step. This ensures that interactions between options and subcommand options is consistent.
Option callbacks can be executed at many different stages depending on the priority specified. The default is Normal so they will execute after processing requirements. The default for help and version flags is to execute First. Both can be changed to execute in different steps of the process.
The library immediately returns a C++ exception when it detects a problem, such as an incorrect construction or a malformed command line. Errors from config processing are delayed until after other processing, to give priority to any help or version flags, or other types of callback errors.