MCPcopy Create free account
hub / github.com/CLIUtils/CLI11 / main

Function main

examples/custom_validator.cpp:38–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36};
37
38int main(int argc, char **argv) {
39 /* this application creates custom validator which is a range center+/- range The center and range can be defined by
40 * other command line options and are updated dynamically
41 */
42 CLI::App app("custom range validator");
43
44 std::string value;
45 auto dr = std::make_shared<DeltaRange<int>>(7, 3);
46 app.add_option("--number", value, "enter value in the related range")->check(dr)->required();
47
48 app.add_option_function<int>("--center", [&dr](int new_center) { dr->center(new_center); })->trigger_on_parse();
49 app.add_option_function<int>("--range", [&dr](int new_range) { dr->range(new_range); })->trigger_on_parse();
50
51 CLI11_PARSE(app, argc, argv);
52
53 std::cout << "number " << value << " in range = " << dr->center() << " +/- " << dr->range() << '\n';
54
55 return 0;
56}

Callers

nothing calls this directly

Calls 5

centerMethod · 0.80
rangeMethod · 0.80
requiredMethod · 0.45
checkMethod · 0.45
add_optionMethod · 0.45

Tested by

no test coverage detected