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 #include <sstream>
11 #include <string>
12 
main()13 int main()
14 {
15 	using namespace lyra;
16 	bfg::mini_test::scope test;
17 
18 	{
19 		bool a = false;
20 		bool show_help = false;
21 		auto cli = lyra::cli() | opt(a)["-a"] | help(show_help);
22 		std::ostringstream help_text;
23 		auto result = cli.parse({ "TestApp", "-?" });
24 		help_text << cli;
25 		test(REQUIRE(result));
26 		test(REQUIRE(help_text.str().find("USAGE:") != std::string::npos));
27 	}
28 	{
29 		bool a = false;
30 		bool show_help = false;
31 		auto cli = lyra::cli() | opt(a)["-a"] | help(show_help);
32 		std::ostringstream help_text;
33 		auto result = cli.parse({ "", "-?" });
34 		help_text << cli;
35 		test(REQUIRE(result));
36 		test(REQUIRE(help_text.str().find("USAGE:") == std::string::npos));
37 	}
38 	{
39 		std::string named_required;
40 		auto opt_required
41 			= lyra::opt(named_required, "required-arg")["--required"](
42 				"You must supply this arg");
43 		test(REQUIRE(
44 			opt_required.get_usage_text(option_style::posix()).find("--required")
45 			!= std::string::npos));
46 		test(REQUIRE(
47 			opt_required.get_usage_text(option_style::posix()).find("<required-arg>")
48 			!= std::string::npos));
49 	}
50 
51 	return test;
52 }
53