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

Function main

tests/command_run_test.cpp:11–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include <lyra/lyra.hpp>
10
11int main(int, const char **)
12{
13 using namespace lyra;
14 bfg::mini_test::scope test;
15
16 {
17 auto cli = lyra::cli()
18 | command("one")
19 | command("two");
20 test(REQUIRE(cli.parse({ "TestApp", "one" })));
21 test(REQUIRE(cli.parse({ "TestApp", "two" })));
22 test(REQUIRE(cli.parse({ "TestApp" })));
23 }
24 {
25 std::string one = "one";
26 int two = 2;
27 auto cli = lyra::cli()
28 | command("one").add_argument(arg(one, "one"))
29 | command("two").add_argument(arg(two, "two"));
30 test(REQUIRE(cli.parse({ "TestApp", "one" })));
31 test(REQUIRE(cli.parse({ "TestApp", "two" })));
32 test(REQUIRE(cli.parse({ "TestApp", "one", "ONE" })));
33 test(REQUIRE(cli.parse({ "TestApp", "two", "3" })));
34 test(REQUIRE(!cli.parse({ "TestApp", "one", "OnE", "TwO" })));
35 test(REQUIRE(!cli.parse({ "TestApp", "two", "3", "4" })));
36 test(REQUIRE(cli.parse({ "TestApp" })));
37 }
38 {
39 bool a = false;
40 bool b = false;
41 bool c = false;
42 bool d = false;
43 auto cli = lyra::cli()
44 | command("one")
45 .add_argument(opt(a, "a").name("--a").optional())
46 .add_argument(opt(b, "b").name("--b").optional())
47 | command("two")
48 .add_argument(opt(c, "c").name("--c").optional())
49 .add_argument(opt(d, "d").name("--d").optional())
50 ;
51 test(REQUIRE(cli.parse({ "TestApp", "one", "--a=1" })));
52 test(REQUIRE(cli.parse({ "TestApp", "two", "--c=1" })));
53 test(REQUIRE(cli.parse({ "TestApp" })));
54 }
55
56 return test;
57}

Callers

nothing calls this directly

Calls 7

cliClass · 0.50
commandClass · 0.50
argClass · 0.50
optClass · 0.50
parseMethod · 0.45
optionalMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected