aboutsummaryrefslogtreecommitdiff
path: root/test.cxx
diff options
context:
space:
mode:
authorPavel Belikov <pavel.fuchs.belikov@gmail.com>2017-11-06 10:57:00 +0300
committerPavel Belikov <pavel.fuchs.belikov@gmail.com>2017-11-06 10:57:00 +0300
commitff6f09803274b41d695e9e632db41b380d9e9c99 (patch)
tree6caa0241fc7b1f38f03815c74d0fd280a75989da /test.cxx
parentrefactor GetDescription (diff)
downloadargs.hxx-ff6f09803274b41d695e9e632db41b380d9e9c99.tar.xz
add description for commands
Diffstat (limited to 'test.cxx')
-rw-r--r--test.cxx30
1 files changed, 30 insertions, 0 deletions
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<std::string>{"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<std::string>{"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