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

Function main

examples/option_groups.cpp:11–46  ·  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("data output specification");
14 app.set_help_all_flag("--help-all", "Expand all help");
15
16 auto *format = app.add_option_group("output_format", "formatting type for output");
17 auto *target = app.add_option_group("output target", "target location for the output");
18 bool csv{false};
19 bool human{false};
20 bool binary{false};
21 format->add_flag("--csv", csv, "specify the output in csv format");
22 format->add_flag("--human", human, "specify the output in human readable text format");
23 format->add_flag("--binary", binary, "specify the output in binary format");
24 // require one of the options to be selected
25 format->require_option(1);
26 std::string fileLoc;
27 std::string networkAddress;
28 target->add_option("-o,--file", fileLoc, "specify the file location of the output");
29 target->add_option("--address", networkAddress, "specify a network address to send the file");
30
31 // require at most one of the target options
32 target->require_option(0, 1);
33 CLI11_PARSE(app, argc, argv);
34
35 std::string format_type = (csv) ? std::string("CSV") : ((human) ? "human readable" : "binary");
36 std::cout << "Selected " << format_type << " format\n";
37 if(!fileLoc.empty()) {
38 std::cout << " sent to file " << fileLoc << '\n';
39 } else if(!networkAddress.empty()) {
40 std::cout << " sent over network to " << networkAddress << '\n';
41 } else {
42 std::cout << " sent to std::cout\n";
43 }
44
45 return 0;
46}

Callers

nothing calls this directly

Calls 5

set_help_all_flagMethod · 0.80
add_option_groupMethod · 0.80
add_flagMethod · 0.80
require_optionMethod · 0.80
add_optionMethod · 0.45

Tested by

no test coverage detected