Skip to content

Commit

Permalink
[MISC] argument parser: Refine get_help_page_message for in/output fi…
Browse files Browse the repository at this point in the history
…le validators.
  • Loading branch information
smehringer committed Apr 6, 2020
1 parent 93de9c7 commit ddeebfc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
17 changes: 10 additions & 7 deletions include/seqan3/argument_parser/validators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ class file_validator_base
}

protected:

/*!\brief Validates the given filename path based on the specified extensions.
* \param path The filename path.
* \throws seqan3::validation_error if the specified extensions don't match the given path, or
Expand Down Expand Up @@ -445,6 +444,12 @@ class file_validator_base
file_guard.remove();
}

//!\brief Returns the information of valid file formats.
std::string valid_extensions_help_page_message() const
{
return detail::to_string("Valid file formats are: [", extensions | views::join(std::string{", "}), "].");
}

//!\brief Stores the extensions.
std::vector<std::string> extensions{};
};
Expand Down Expand Up @@ -561,9 +566,8 @@ class input_file_validator : public file_validator_base
//!\brief Returns a message that can be appended to the (positional) options help page info.
std::string get_help_page_message() const
{
return detail::to_string("Valid input file formats: [",
extensions | views::join(std::string{", "}),
"]");
return "The input file must exist and read permissions must be granted. " +
valid_extensions_help_page_message();
}
};

Expand Down Expand Up @@ -664,9 +668,8 @@ class output_file_validator : public file_validator_base
//!\brief Returns a message that can be appended to the (positional) options help page info.
std::string get_help_page_message() const
{
return detail::to_string("Valid output file formats: [",
extensions | views::join(std::string{", "}),
"]");
return "The output file must not exist already and write permissions must be granted. " +
valid_extensions_help_page_message();
}
};

Expand Down
17 changes: 11 additions & 6 deletions test/unit/argument_parser/format_parse_validators_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ TEST(validator_test, input_file)
"\n"
"POSITIONAL ARGUMENTS\n"
" ARGUMENT-1 (std::filesystem::path)\n"
" desc Valid input file formats: [fa, sam, fasta]\n"
" desc The input file must exist and read permissions must be granted.\n"
" Valid file formats are: [fa, sam, fasta].\n"
"\n"} +
basic_options_str +
"\n" +
Expand All @@ -191,7 +192,8 @@ TEST(validator_test, input_file_ext_from_file)
// Give as a template argument the seqan3 file type to get all valid extensions for this file.
seqan3::input_file_validator<dummy_file> validator{};

EXPECT_EQ(validator.get_help_page_message(), "Valid input file formats: [fa, fasta, sam, bam]");
EXPECT_EQ(validator.get_help_page_message(), "The input file must exist and read permissions must be granted. "
"Valid file formats are: [fa, fasta, sam, bam].");
}

TEST(validator_test, output_file)
Expand Down Expand Up @@ -281,7 +283,8 @@ TEST(validator_test, output_file)
"\n"
"POSITIONAL ARGUMENTS\n"
" ARGUMENT-1 (std::filesystem::path)\n"
" desc Valid output file formats: [fa, sam, fasta]\n"
" desc The output file must not exist already and write permissions\n"
" must be granted. Valid file formats are: [fa, sam, fasta].\n"
"\n"} +
basic_options_str +
"\n" +
Expand All @@ -295,7 +298,8 @@ TEST(validator_test, output_file_ext_from_file)
// Give as a template argument the seqan3 file type to get all valid extensions for this file.
seqan3::output_file_validator<dummy_file> validator{};

EXPECT_EQ(validator.get_help_page_message(), "Valid output file formats: [fa, fasta, sam, bam]");
EXPECT_EQ(validator.get_help_page_message(), "The output file must not exist already and write permissions must be granted. "
"Valid file formats are: [fa, fasta, sam, bam].");
}

TEST(validator_test, input_directory)
Expand Down Expand Up @@ -1157,8 +1161,9 @@ TEST(validator_test, chaining_validators)
basic_options_str +
" -s, --string-option (std::string)\n"
" desc Default: . Value must match the pattern '(/[^/]+)+/.*\\.[^/\\.]+$'.\n"
" Valid output file formats: [sa, so] Value must match the pattern\n"
" '.*'.\n"
" The output file must not exist already and write permissions must be\n"
" granted. Valid file formats are: [sa, so]. Value must match the\n"
" pattern '.*'.\n"
"\n"} +
basic_version_str;
EXPECT_EQ(my_stdout, expected);
Expand Down

0 comments on commit ddeebfc

Please sign in to comment.