|
goptions
|
GOptions : provides a unified framework to define, parse, validate, and persist configuration coming from YAML files and command-line arguments. It is designed to support:
The subsystem is built around:
Configuration sources are resolved in increasing precedence: schema defaults, YAML input, and finally command-line values. Dot-notation command-line updates replace one structured subkey without requiring the complete option value to be repeated.
A GSwitch : is a lightweight boolean flag:
Example:
A scalar GOption : stores exactly one value as a YAML scalar. Values can be supplied via:
A structured GOption : stores either:
A typical pattern is a sequence of maps where each entry represents one repeated item:
Equivalent command-line option (quotes are usually required so your shell does not split the string):
Structured options can be declared cumulative when at least one schema key uses goptions::REQUIRED : as its default value. That tells GOption : that:
Missing non-mandatory keys are back-filled from schema defaults so every entry becomes complete.
Some structured options are updated using dot-notation:
This updates a single subkey within a structured option via set_sub_option_value() .
This module defines two conventional structured options commonly used across the project:
Typical semantics used by classes that consume these settings:
Upcoming in the next release: the scalar language option defaults to auto, letting GLogger and the Qt GUI select the language without requiring a user option. An explicit -language=it or YAML language: it overrides GEMC_LANGUAGE and locale detection; -language=en forces English. Supported values are:
Automatic detection checks GEMC_LANGUAGE, LC_ALL, LC_MESSAGES, and LANG, then native settings or English. Regional tags such as it_IT.UTF-8 use the base language when a regional entry is missing. C and POSIX locales select English. Missing translations use the original English template, without changing numeric formatting. The startup/version banner shares these catalogs; paths, dates, citation, and author are parameters. -v -language=it honors overrides before or after the version flag. Version remains an early action without reading YAML; the normal startup banner uses the fully parsed command-line/YAML settings.
The following example program is provided with this module:
Frameworks or plugins can define their own options and switches, then merge them into the executable’s definition set using operator+=() (which internally calls addGOptions()).
Example:
YAML parsing is implemented using the yaml-cpp library. When a YAML file fails to parse, the option manager exits with a dedicated exit code so batch workflows can detect the failure mode.
The goptions module is maintained as part of GEMC and is intended to be: