From ab9b093c1004a1ce03e1bee579d1b7b7217913bd Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Mon, 6 Nov 2017 10:55:19 +0300 Subject: refactor GetDescription --- test.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index eddf7fd..a9991fc 100644 --- a/test.cxx +++ b/test.cxx @@ -599,11 +599,11 @@ TEST_CASE("Hidden options are excluded from help", "[args]") args::ValueFlag foo1(group, "foo", "foo", {'f', "foo"}, args::Options::Hidden); args::ValueFlag bar2(group, "bar", "bar", {'b'}); - auto desc = parser1.GetDescription("", "", "", "", 0); + auto desc = parser1.GetDescription(parser1.helpParams, 0); REQUIRE(desc.size() == 3); - REQUIRE(std::get<0>(desc[0]) == "b[bar]"); + REQUIRE(std::get<0>(desc[0]) == "-b[bar]"); REQUIRE(std::get<0>(desc[1]) == "group"); - REQUIRE(std::get<0>(desc[2]) == "b[bar]"); + REQUIRE(std::get<0>(desc[2]) == "-b[bar]"); } TEST_CASE("Implicit values work as expected", "[args]") -- cgit v1.2.1 From ff6f09803274b41d695e9e632db41b380d9e9c99 Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Mon, 6 Nov 2017 10:57:00 +0300 Subject: add description for commands --- test.cxx | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index a9991fc..e95786e 100644 --- a/test.cxx +++ b/test.cxx @@ -746,6 +746,36 @@ TEST_CASE("Subparser commands with kick-out flags work as expected", "[args]") REQUIRE((kickedOut == std::vector{"A", "B", "C", "D"})); } +TEST_CASE("Subparser help works as expected", "[args]") +{ + args::ArgumentParser p("git-like parser"); + args::Flag g(p, "GLOBAL", "global flag", {'g'}, args::Options::Global); + + args::Command add(p, "add", "add file contents to the index", [&](args::Subparser &c) + { + args::Flag flag(c, "FLAG", "flag", {'f'}); + c.Parse(); + }); + + args::Command commit(p, "commit", "record changes to the repository", [&](args::Subparser &c) + { + args::Flag flag(c, "FLAG", "flag", {'f'}); + c.Parse(); + }); + + auto d = p.GetDescription(p.helpParams, 0); + REQUIRE(d.size() == 3); + REQUIRE(std::get<0>(d[0]) == "-g"); + REQUIRE(std::get<0>(d[1]) == "add"); + REQUIRE(std::get<0>(d[2]) == "commit"); + + p.ParseArgs(std::vector{"add"}); + d = p.GetDescription(p.helpParams, 0); + REQUIRE(d.size() == 2); + REQUIRE(std::get<0>(d[0]) == "add"); + REQUIRE(std::get<0>(d[1]) == "-f"); +} + #undef ARGS_HXX #define ARGS_TESTNAMESPACE #define ARGS_NOEXCEPT -- cgit v1.2.1 From 3419d110deb32ef2b840cfc3094b89b9e02efe88 Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Mon, 6 Nov 2017 10:58:48 +0300 Subject: add help output for commands --- test.cxx | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index e95786e..18b8c69 100644 --- a/test.cxx +++ b/test.cxx @@ -763,17 +763,36 @@ TEST_CASE("Subparser help works as expected", "[args]") c.Parse(); }); + p.Prog("git"); + + std::ostringstream s; + auto d = p.GetDescription(p.helpParams, 0); - REQUIRE(d.size() == 3); - REQUIRE(std::get<0>(d[0]) == "-g"); - REQUIRE(std::get<0>(d[1]) == "add"); - REQUIRE(std::get<0>(d[2]) == "commit"); + s << p; + REQUIRE(s.str() == R"( git {OPTIONS} + + git-like parser + + OPTIONS: + + -g global flag + add add file contents to the index + commit record changes to the repository + +)"); p.ParseArgs(std::vector{"add"}); - d = p.GetDescription(p.helpParams, 0); - REQUIRE(d.size() == 2); - REQUIRE(std::get<0>(d[0]) == "add"); - REQUIRE(std::get<0>(d[1]) == "-f"); + s.str(""); + s << p; + REQUIRE(s.str() == R"( git add {OPTIONS} + + add file contents to the index + + OPTIONS: + + -f flag + +)"); } #undef ARGS_HXX -- cgit v1.2.1 From 3f6154ebeb153389ebf6ec1dded6a348dc3d9b58 Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Mon, 6 Nov 2017 11:02:34 +0300 Subject: add HelpParams::showCommandChildren and HelpParams::showCommandFullHelp --- test.cxx | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 18b8c69..597eaae 100644 --- a/test.cxx +++ b/test.cxx @@ -793,6 +793,69 @@ TEST_CASE("Subparser help works as expected", "[args]") -f flag )"); + + p.ParseArgs(std::vector{}); + s.str(""); + s << p; + REQUIRE(s.str() == R"( git {OPTIONS} + + git-like parser + + OPTIONS: + + -g global flag + add add file contents to the index + commit record changes to the repository + +)"); + + + p.helpParams.showCommandChildren = true; + p.ParseArgs(std::vector{}); + s.str(""); + s << p; + REQUIRE(s.str() == R"( git {OPTIONS} + + git-like parser + + OPTIONS: + + -g global flag + add add file contents to the index + -f flag + commit record changes to the repository + -f flag + +)"); + + commit.Epilog("epilog"); + p.helpParams.showCommandFullHelp = true; + p.ParseArgs(std::vector{}); + s.str(""); + s << p; + REQUIRE(s.str() == R"( git {OPTIONS} + + git-like parser + + OPTIONS: + + -g global flag + add {OPTIONS} + + add file contents to the index + + -f flag + + commit {OPTIONS} + + record changes to the repository + + -f flag + + epilog + +)"); + } #undef ARGS_HXX -- cgit v1.2.1 From 34c1a3bbfb094ac1e794a70d8e7d9e5d9b03900c Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Mon, 6 Nov 2017 13:58:51 +0300 Subject: add COMMAND to program line --- test.cxx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 597eaae..0726619 100644 --- a/test.cxx +++ b/test.cxx @@ -769,7 +769,7 @@ TEST_CASE("Subparser help works as expected", "[args]") auto d = p.GetDescription(p.helpParams, 0); s << p; - REQUIRE(s.str() == R"( git {OPTIONS} + REQUIRE(s.str() == R"( git [COMMAND] {OPTIONS} git-like parser @@ -797,7 +797,7 @@ TEST_CASE("Subparser help works as expected", "[args]") p.ParseArgs(std::vector{}); s.str(""); s << p; - REQUIRE(s.str() == R"( git {OPTIONS} + REQUIRE(s.str() == R"( git [COMMAND] {OPTIONS} git-like parser @@ -809,12 +809,11 @@ TEST_CASE("Subparser help works as expected", "[args]") )"); - p.helpParams.showCommandChildren = true; p.ParseArgs(std::vector{}); s.str(""); s << p; - REQUIRE(s.str() == R"( git {OPTIONS} + REQUIRE(s.str() == R"( git [COMMAND] {OPTIONS} git-like parser @@ -833,7 +832,7 @@ TEST_CASE("Subparser help works as expected", "[args]") p.ParseArgs(std::vector{}); s.str(""); s << p; - REQUIRE(s.str() == R"( git {OPTIONS} + REQUIRE(s.str() == R"( git [COMMAND] {OPTIONS} git-like parser -- cgit v1.2.1