Skip to content

Commit

Permalink
Make dash usable for subcommand (#2306)
Browse files Browse the repository at this point in the history
* [FEATURE] Make dash usable for subcommand

* Apply requested changes 2
  • Loading branch information
MitraDarja authored Dec 17, 2020
1 parent 8d69abf commit f048ef6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
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

0 comments on commit f048ef6

Please sign in to comment.