1 /*
2 Copyright 2020-2022 René Ferdinand Rivera Morell
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt)
6 */
7
8 #include "mini_test.hpp"
9 #include <lyra/lyra.hpp>
10
main(int,const char **)11 int main(int, const char **)
12 {
13 using namespace lyra;
14 bfg::mini_test::scope test;
15
16 {
17 auto cli = lyra::cli()
18 | group().add_argument(literal("one"))
19 | group().add_argument(literal("two"));
20 test
21 (REQUIRE(cli.parse({ "TestApp", "one" })))
22 (REQUIRE(cli.parse({ "TestApp", "two" })))
23 (REQUIRE(cli.parse({ "TestApp" })));
24 }
25 {
26 std::string one = "one";
27 int two = 2;
28 auto cli = lyra::cli()
29 | group().sequential().add_argument(literal("one")).add_argument(arg(one, "one"))
30 | group().sequential().add_argument(literal("two")).add_argument(arg(two, "two"));
31 test
32 (REQUIRE(cli.parse({ "TestApp", "one" })))
33 (REQUIRE(cli.parse({ "TestApp", "two" })))
34 (REQUIRE(cli.parse({ "TestApp", "one", "ONE" })))
35 (REQUIRE(cli.parse({ "TestApp", "two", "3" })))
36 (REQUIRE(!cli.parse({ "TestApp", "one", "OnE", "TwO" })))
37 (REQUIRE(!cli.parse({ "TestApp", "two", "3", "4" })))
38 (REQUIRE(cli.parse({ "TestApp" })));
39 }
40 {
41 bool a = false;
42 bool b = false;
43 bool c = false;
44 bool d = false;
45 auto cli = lyra::cli()
46 | group()
47 .sequential()
48 .add_argument(literal("one"))
49 .add_argument(group()
50 .add_argument(opt(a, "a").name("--a").optional())
51 .add_argument(opt(b, "b").name("--b").optional()))
52 | group()
53 .sequential()
54 .add_argument(literal("two"))
55 .add_argument(group()
56 .add_argument(opt(c, "c").name("--c").optional())
57 .add_argument(opt(d, "d").name("--d").optional()))
58 ;
59 test
60 (REQUIRE(cli.parse({ "TestApp", "one", "--a=1" })))
61 (REQUIRE(cli.parse({ "TestApp", "two", "--c=1" })))
62 (REQUIRE(cli.parse({ "TestApp" })));
63 }
64
65 return test;
66 }
67