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

Function main

examples/doc_example2_alt.cpp:13–42  ·  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 = lyra::cli();
23 cli.add_argument(lyra::opt(width, "width")
24 .name("-w").name("--width").help("How wide should it be?"));
25 cli.add_argument(lyra::opt(name, "name")
26 .name("-n").name("--name").help("By what name should I be known"));
27 cli.add_argument(lyra::opt(doIt)
28 .name("-d").name("--doit").help("Do the thing"));
29
30 // Parse the program arguments:
31 auto result = cli.parse({ argc, argv });
32
33 // Check that the arguments where valid:
34 if (!result)
35 {
36 std::cerr << "Error in command line: " << result.message() << std::endl;
37 return 1;
38 }
39
40 std::cout << "width = " << width << ", name = " << name << ", doIt = " << doIt << "\n";
41 return 0;
42}
43// end::doc[]

Callers

nothing calls this directly

Calls 6

cliClass · 0.50
optClass · 0.50
helpMethod · 0.45
nameMethod · 0.45
parseMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected