MCPcopy Create free account
hub / github.com/bfgroup/Lyra / main

Function main

examples/doc_example3.cpp:13–56  ·  view source on GitHub ↗

tag::part1[]

Source from the content-addressed store, hash-verified

11
12// tag::part1[]
13int main(int argc, const char** argv)
14{
15 // Where we read in the argument values:
16 int width = 0;
17 std::string name;
18 bool doIt = false;
19 bool show_help = false; // <1>
20
21 // The parser with the multiple option arguments and help option.
22 auto cli
23 = lyra::help(show_help) // <2>
24 | lyra::opt(width, "width")
25 ["-w"]["--width"]("How wide should it be?")
26 | lyra::opt(name, "name")
27 ["-n"]["--name"]("By what name should I be known")
28 | lyra::opt(doIt)
29 ["-d"]["--doit"]("Do the thing");
30
31 // ...
32 // end::part1[]
33 // tag::part2[]
34 // ...
35
36 // Parse the program arguments:
37 auto result = cli.parse({ argc, argv });
38
39 // Check that the arguments where valid:
40 if (!result)
41 {
42 std::cerr << "Error in command line: " << result.message() << std::endl;
43 std::cerr << cli << "\n"; // <1>
44 return 1;
45 }
46
47 // Show the help when asked for.
48 if (show_help) // <2>
49 {
50 std::cout << cli << "\n";
51 return 0;
52 }
53
54 std::cout << "width = " << width << ", name = " << name << ", doIt = " << doIt << "\n";
55 return 0;
56}
57// end::part2[]

Callers

nothing calls this directly

Calls 4

helpClass · 0.50
optClass · 0.50
parseMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected