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

Function main

examples/subcommands.cpp:11–34  ·  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("K3Pi goofit fitter");
14 app.set_help_all_flag("--help-all", "Expand all help");
15 app.add_flag("--random", "Some random flag");
16 CLI::App *start = app.add_subcommand("start", "A great subcommand");
17 CLI::App *stop = app.add_subcommand("stop", "Do you really want to stop?");
18 app.require_subcommand(); // 1 or more
19
20 std::string file;
21 start->add_option("-f,--file", file, "File name");
22
23 CLI::Option *s = stop->add_flag("-c,--count", "Counter");
24
25 CLI11_PARSE(app, argc, argv);
26
27 std::cout << "Working on --file from start: " << file << '\n';
28 std::cout << "Working on --count from stop: " << s->count() << ", direct count: " << stop->count("--count") << '\n';
29 std::cout << "Count of --random flag: " << app.count("--random") << '\n';
30 for(auto *subcom : app.get_subcommands())
31 std::cout << "Subcommand: " << subcom->get_name() << '\n';
32
33 return 0;
34}

Callers

nothing calls this directly

Calls 7

set_help_all_flagMethod · 0.80
add_flagMethod · 0.80
require_subcommandMethod · 0.80
get_subcommandsMethod · 0.80
get_nameMethod · 0.80
add_subcommandMethod · 0.45
add_optionMethod · 0.45

Tested by

no test coverage detected