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

Function main

examples/doc_example2.cpp:13–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include <lyra/lyra.hpp>
12
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
20 // The parser with the multiple option arguments. They are composed
21 // together by the "|" operator.
22 auto cli
23 = lyra::opt(width, "width")
24 ["-w"]["--width"]("How wide should it be?")
25 | lyra::opt(name, "name")
26 ["-n"]["--name"]("By what name should I be known")
27 | lyra::opt(doIt)
28 ["-d"]["--doit"]("Do the thing");
29
30 // ...
31 // end::part1[]
32 // tag::part2[]
33 // ...
34
35 // Parse the program arguments:
36 auto result = cli.parse({ argc, argv });
37
38 // Check that the arguments where valid:
39 if (!result)
40 {
41 std::cerr << "Error in command line: " << result.message() << std::endl;
42 return 1;
43 }
44
45 std::cout << "width = " << width << ", name = " << name << ", doIt = " << doIt << "\n";
46 return 0;
47}
48// end::part2[]

Callers

nothing calls this directly

Calls 3

optClass · 0.50
parseMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected