Registers configuration structure fields as CLI options.
This function iterates over the members of the provided configuration object using reflection and registers each member as a command-line option in the provided CLI application.
If the configuration object contains nested structures, field names are flattened using dot notation (e.g., parent.child.field).
If T is a Config<U> wrapper, it automatically unwraps the inner value and adds a footer note to the CLI application's help message indicating that options were auto-generated.
- Template Parameters
-
| T | The type of the configuration object. Can be a raw struct or a Config<Struct> wrapper. |
| CliApp | The type of the CLI application object. Must satisfy the IsCLIApp concept (e.g., CLI::App). |
- Parameters
-
| config | The configuration object to register. |
| app | The CLI application instance to add options to. |
| prefix | Optional prefix for option names. Used internally for recursion; usually omitted by the caller. |
- Examples
- Basic usage with CLI11:
#include "CLI/CLI.hpp"
struct MyOptions {
int verbosity = 0;
std::string input_file = "data.txt";
};
int main(int argc, char** argv) {
CLI::App app{"My Application"};
CLI11_PARSE(app, argc, argv);
return 0;
}
Wrapper class for managing strongly-typed configuration structures.
Definition base.h:113
Main entry point for the fourdst::config library.
void register_as_cli(T &config, CliApp &app, const std::string &prefix="")
Registers configuration structure fields as CLI options.
Definition cli.h:114
Nested structures:
struct Server {
int port = 8080;
std::string host = "localhost";
};
struct AppConfig {
Server server;
bool dry_run = false;
};