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

Function main

examples/config_app.cpp:11–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include <string>
10
11int main(int argc, char **argv) {
12
13 CLI::App app("configuration print example");
14
15 app.add_flag("-p,--print", "Print configuration and exit")->configurable(false); // NEW: print flag
16
17 std::string file;
18 CLI::Option *opt = app.add_option("-f,--file,file", file, "File name")
19 ->capture_default_str()
20 ->run_callback_for_default(); // NEW: capture_default_str()
21
22 int count{0};
23 CLI::Option *copt =
24 app.add_option("-c,--count", count, "Counter")->capture_default_str(); // NEW: capture_default_str()
25
26 int v{0};
27 CLI::Option *flag = app.add_flag("--flag", v, "Some flag that can be passed multiple times")
28 ->capture_default_str(); // NEW: capture_default_str()
29
30 double value{0.0}; // = 3.14;
31 app.add_option("-d,--double", value, "Some Value")->capture_default_str(); // NEW: capture_default_str()
32
33 app.get_config_formatter_base()->quoteCharacter('"', '"');
34
35 CLI11_PARSE(app, argc, argv);
36
37 if(app.get_option("--print")->as<bool>()) { // NEW: print configuration and exit
38 std::cout << app.config_to_str(true, false);
39 return 0;
40 }
41
42 std::cout << "Working on file: " << file << ", direct count: " << app.count("--file")
43 << ", opt count: " << opt->count() << '\n';
44 std::cout << "Working on count: " << count << ", direct count: " << app.count("--count")
45 << ", opt count: " << copt->count() << '\n';
46 std::cout << "Received flag: " << v << " (" << flag->count() << ") times\n";
47 std::cout << "Some value: " << value << '\n';
48
49 return 0;
50}

Callers

nothing calls this directly

Calls 4

add_flagMethod · 0.80
quoteCharacterMethod · 0.80
configurableMethod · 0.45
add_optionMethod · 0.45

Tested by

no test coverage detected