goptions
|
GOptions provides an unified framework to parse command-line arguments and YAML files. The main components are: GSwitch and GOption
A GSwitches is struct with a boolean flag and a description. It is initialized to false
by default and can be toggled to true
by specifying it on the command line. For example, the switch "gui" is activated if the command line contains:
A simple GOption is associated with a single value, which can be an integer, float, double, or string. It is represented as follows in a YAML configuration file:
The corresponding command-line option would be:
A structured GOption consists of multiple key-value pairs within a single tag. An example from a YAML file:
The equivalent command-line option:
Note the need of quotes in the command line to define.
Users can instantiate the GOptions class by calling its constructor:
GOptions(argc, argv, defineOptions())
argc | Number of command-line arguments passed from main . |
argv | Array of command-line arguments passed from main . |
defineOptions | Function that constructs and returns a GOptions object. |
The defineOptions function creates and returns an instance of GOptions with predefined command line switches and options.
Example with these options and switches:
log
to enable logging.runno
to set the run number with a default value.nthreads
to set the number of threads to use, with a default that uses all available threads.gparticle
to define generator particles with attributes such as name, multiplicity, momentum, and angles.Each framework or plugin can define its own options and switches. The user can then merge these with the main executable's. For example, in the gemc defineOptions function, the Goptions defined in the external libraries defineOptions and added, as in the code below:
The YAML parser used in this project is from the yaml-cpp library. It is included as a dependency and facilitates parsing complex YAML configurations.
The GOptions framework is continuously integrated and tested to ensure stability and reliability across updates.