Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dash usable for subcommand #2306

Merged
merged 2 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ If possible, provide tooling that performs the changes, e.g. a shell-script.
* The `seqan3::argument_parser` has a new member function `seqan3::argument_parser::is_option_set` that
checks whether an option, identified by its long or short name, was set on the command line by the user
([\#1859](https://github.com/seqan/seqan3/pull/1859)).
* The subcommand of the `seqan3::argument_parser` may contain a dash
([\#2306](https://github.com/seqan/seqan3/pull/2306)).

#### Search

Expand Down
16 changes: 12 additions & 4 deletions include/seqan3/argument_parser/argument_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,20 @@ class argument_parser
subcommands{std::move(subcommands)}
{
if (!std::regex_match(app_name, app_name_regex))
throw design_error{"The application name must only contain alpha-numeric characters or '_' and '-' "
"(regex: \"^[a-zA-Z0-9_-]+$\")."};
{
throw design_error{("The application name must only contain alpha-numeric characters or '_' and '-' "
"(regex: \"^[a-zA-Z0-9_-]+$\").")};
}

for (auto & sub : this->subcommands)
if (!std::regex_match(sub, std::regex{"^[a-zA-Z0-9_]+$"}))
throw design_error{"The subcommand name must only contain alpha-numeric characters or '_'."};
{
if (!std::regex_match(sub, app_name_regex))
{
throw design_error{"The subcommand name must only contain alpha-numeric characters or '_' and '-' "
"(regex: \"^[a-zA-Z0-9_-]+$\")."};
}
}


info.app_name = std::move(app_name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ TEST(parse_test, subcommand_argument_parser_error)
argv,
seqan3::update_notifications::off,
{"with space"}}), seqan3::design_error);
EXPECT_THROW((seqan3::argument_parser{"top_level",
2,
argv,
seqan3::update_notifications::off,
{"-dash"}}), seqan3::design_error);
}

// no positional/options are allowed
Expand Down
11 changes: 10 additions & 1 deletion test/unit/argument_parser/format_parse_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,8 @@ TEST(parse_test, subcommand_argument_parser_success)
}

// incorrect sub command
const char * argv[]{"./top_level", "subiddysub", "-f"};
{ // see issue https://github.com/seqan/seqan3/issues/2172
const char * argv[]{"./top_level", "subiddysub", "-f"};
seqan3::argument_parser top_level_parser{"top_level",
3,
argv,
Expand All @@ -942,6 +942,15 @@ TEST(parse_test, subcommand_argument_parser_success)

EXPECT_THROW(top_level_parser.parse(), seqan3::argument_parser_error);
}

// sub command can contain dash, see https://github.com/seqan/product_backlog/issues/234
{
EXPECT_NO_THROW((seqan3::argument_parser{"top_level",
2,
argv,
seqan3::update_notifications::off,
{"-dash"}}));
}
}

TEST(parse_test, issue1544)
Expand Down