This commit is contained in:
Pranav Srinivas Kumar 2019-11-21 10:25:41 -06:00
parent f9ab33d1a6
commit c707bcc1c4
2 changed files with 8 additions and 1 deletions

View File

@ -321,7 +321,7 @@ private:
// If an argument starts with "-" or "--", then it's optional
static bool is_optional(const std::string &aName) {
return (!aName.empty() && aName[0] == '-' && !is_integer(aName) &&
return (aName.size() > 1 && aName[0] == '-' && !is_integer(aName) &&
!is_float(aName));
}

View File

@ -12,6 +12,13 @@ DOCTEST_TEST_CASE("Parse toggle arguments with default value [optional_arguments
REQUIRE(program["--verbose"] == false);
}
DOCTEST_TEST_CASE("Argument '-' is not an optional argument [optional_arguments]") {
argparse::ArgumentParser program("test");
program.add_argument("input");
program.parse_args({ "./test.exe", "-"});
REQUIRE(program.get<std::string>("input") == "-");
}
DOCTEST_TEST_CASE("Parse toggle arguments with implicit value [optional_arguments]") {
argparse::ArgumentParser program("test");
program.add_argument("--verbose")