feat(CLI): CLI integration with CLI11
libconfig can automatically generate command line interfaces using CLI11 based on some schema
This commit is contained in:
33
examples/cli_example.cpp
Normal file
33
examples/cli_example.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "CLI/CLI.hpp"
|
||||
#include "fourdst/config/config.h"
|
||||
|
||||
#include <string>
|
||||
#include <print>
|
||||
#include <optional>
|
||||
|
||||
struct SubConfig{
|
||||
int a = 0;
|
||||
double b = 1.0;
|
||||
std::string c = "default";
|
||||
};
|
||||
|
||||
struct MainConfig {
|
||||
std::string name = "example";
|
||||
SubConfig subconfig;
|
||||
double value = 3.14;
|
||||
std::optional<std::string> help = std::nullopt;
|
||||
};
|
||||
|
||||
|
||||
int main(const int argc, char** argv) {
|
||||
fourdst::config::Config<MainConfig> config;
|
||||
CLI::App app("Example CLI Application with Config");
|
||||
|
||||
fourdst::config::register_as_cli(config, app, "cfg");
|
||||
|
||||
app.parse(argc, argv);
|
||||
|
||||
std::println("Configuration: \n{}", config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
executable('simple_config_test', 'simple.cpp', dependencies: [config_dep])
|
||||
executable('cli_example', 'cli_example.cpp', dependencies: [config_dep, cli11_dep])
|
||||
|
||||
if meson.is_cross_build() and host_machine.system() == 'wasm'
|
||||
executable('simple_config_wasm_test', 'wasm.cpp', dependencies: [config_dep])
|
||||
|
||||
Reference in New Issue
Block a user