-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Argument::hidden() method to prevent an argument from appearing…
… in usage or help
- Loading branch information
Showing
4 changed files
with
80 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifdef WITH_MODULE | ||
import argparse; | ||
#else | ||
#include <argparse/argparse.hpp> | ||
#endif | ||
#include <doctest.hpp> | ||
|
||
using doctest::test_suite; | ||
|
||
TEST_CASE("Test setting a hidden argument" * test_suite("hidden_argument")) { | ||
argparse::ArgumentParser program("program"); | ||
program.add_argument("--hidden").flag().hidden(); | ||
program.add_argument("--regular").flag(); | ||
program.add_argument("regular_positional"); | ||
// only makes sense if last and optional... | ||
program.add_argument("hidden_positional").nargs(0, 1).hidden(); | ||
|
||
program.parse_args({"./test.exe", "--hidden", "--regular", | ||
"regular_positional_val", "hidden_positional_val"}); | ||
REQUIRE(program.get<bool>("--hidden") == true); | ||
REQUIRE(program.get<bool>("--regular") == true); | ||
REQUIRE(program.get<std::string>("regular_positional") == | ||
"regular_positional_val"); | ||
REQUIRE(program.get<std::string>("hidden_positional") == | ||
"hidden_positional_val"); | ||
|
||
REQUIRE(program.usage() == | ||
"Usage: program [--help] [--version] [--regular] regular_positional"); | ||
|
||
std::ostringstream s; | ||
s << program; | ||
// std::cout << "DEBUG:" << s.str() << std::endl; | ||
REQUIRE(s.str().find("hidden") == std::string::npos); | ||
REQUIRE(s.str().find("--regular") != std::string::npos); | ||
REQUIRE(s.str().find("regular_positional") != std::string::npos); | ||
} |