Skip to content

Commit

Permalink
Final renaming
Browse files Browse the repository at this point in the history
Signed-off-by: Lydia Buntrock <[email protected]>
  • Loading branch information
Irallia committed Aug 31, 2020
1 parent 8c756aa commit 85ee726
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 52 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Note that 3.1.0 will be the first API stable release and interfaces in this rele
* `seqan3::argument_parser::add_line`
* `seqan3::argument_parser::add_list_item`
Note that other `seqan3::argument_parser::option_spec`s like `REQUIRED` are ignored.
* We expanded the `seqan3::output_file_validator`, with a parameter `seqan3::output_file_open_mode` to allow overwriting
* We expanded the `seqan3::output_file_validator`, with a parameter `seqan3::output_file_open_options` to allow overwriting
output files ([\#2009](https://github.com/seqan/seqan3/pull/2009)).

#### I/O
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/argument_parser/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ of the parsed option value.
The validator throws a seqan3::validation_error exception whenever a given filename's extension is not in the
given list of valid extensions. In addition, the seqan3::input_file_validator checks if the file exists, is a regular
file and is readable.
Moreover, you have to add an additional flag seqan3::output_file_open_mode to the seqan3::output_file_validator,
Moreover, you have to add an additional flag seqan3::output_file_open_options to the seqan3::output_file_validator,
which you can use to indicate whether you want to allow the output files to be overwritten.

\note If you want to allow any extension just use a default constructed file validator.
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/read_mapper/read_mapper_indexer_step1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments
seqan3::input_file_validator{{"fa","fasta"}});
parser.add_option(args.index_path, 'o', "output", "The output index file path.",
seqan3::option_spec::DEFAULT,
seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"index"}});
seqan3::output_file_validator{seqan3::output_file_open_options::create_new, {"index"}});
}

//![main]
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/read_mapper/read_mapper_indexer_step2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments
seqan3::input_file_validator{{"fa","fasta"}});
parser.add_option(args.index_path, 'o', "output", "The output index file path.",
seqan3::option_spec::DEFAULT,
seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"index"}});
seqan3::output_file_validator{seqan3::output_file_open_options::create_new, {"index"}});
}

int main(int argc, char const ** argv)
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/read_mapper/read_mapper_indexer_step3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments
seqan3::input_file_validator{{"fa","fasta"}});
parser.add_option(args.index_path, 'o', "output", "The output index file path.",
seqan3::option_spec::DEFAULT,
seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"index"}});
seqan3::output_file_validator{seqan3::output_file_open_options::create_new, {"index"}});
}

int main(int argc, char const ** argv)
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/read_mapper/read_mapper_step1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments
seqan3::input_file_validator{{"index"}});
parser.add_option(args.sam_path, 'o', "output", "The output SAM file path.",
seqan3::option_spec::DEFAULT,
seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sam"}});
seqan3::output_file_validator{seqan3::output_file_open_options::create_new, {"sam"}});
parser.add_option(args.errors, 'e', "error", "Maximum allowed errors.",
seqan3::option_spec::DEFAULT,
seqan3::arithmetic_range_validator{0, 4});
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/read_mapper/read_mapper_step2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments
seqan3::input_file_validator{{"index"}});
parser.add_option(args.sam_path, 'o', "output", "The output SAM file path.",
seqan3::option_spec::DEFAULT,
seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sam"}});
seqan3::output_file_validator{seqan3::output_file_open_options::create_new, {"sam"}});
parser.add_option(args.errors, 'e', "error", "Maximum allowed errors.",
seqan3::option_spec::DEFAULT,
seqan3::arithmetic_range_validator{0, 4});
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/read_mapper/read_mapper_step3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments
seqan3::input_file_validator{{"index"}});
parser.add_option(args.sam_path, 'o', "output", "The output SAM file path.",
seqan3::option_spec::DEFAULT,
seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sam"}});
seqan3::output_file_validator{seqan3::output_file_open_options::create_new, {"sam"}});
parser.add_option(args.errors, 'e', "error", "Maximum allowed errors.",
seqan3::option_spec::DEFAULT,
seqan3::arithmetic_range_validator{0, 4});
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/read_mapper/read_mapper_step4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments
seqan3::input_file_validator{{"index"}});
parser.add_option(args.sam_path, 'o', "output", "The output SAM file path.",
seqan3::option_spec::DEFAULT,
seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"sam"}});
seqan3::output_file_validator{seqan3::output_file_open_options::create_new, {"sam"}});
parser.add_option(args.errors, 'e', "error", "Maximum allowed errors.",
seqan3::option_spec::DEFAULT,
seqan3::arithmetic_range_validator{0, 4});
Expand Down
18 changes: 9 additions & 9 deletions include/seqan3/argument_parser/validators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,12 @@ class input_file_validator : public file_validator_base
};

//!\brief Mode of an output file: Determines whether an existing file is accepted for writing.
enum output_file_open_mode
enum output_file_open_options
{
//!\brief Allow to overwrite the output file
overwritable,
open_or_create,
//!\brief Forbid overwriting the output file
exclusive
create_new
};

/*!\brief A validator that checks if a given path is a valid output file.
Expand Down Expand Up @@ -611,7 +611,7 @@ class output_file_validator : public file_validator_base
{
private:
//!\brief Stores the current mode of whether it is valid to overwrite the output file.
output_file_open_mode mode;
output_file_open_options mode;

public:
static_assert(std::same_as<file_t, void> || detail::has_type_valid_formats<file_t>,
Expand Down Expand Up @@ -639,7 +639,7 @@ class output_file_validator : public file_validator_base
* This constructor is only available if `file_t` does not name a valid seqan3 file type that contains a
* static member `valid_formats`.
*/
explicit output_file_validator(output_file_open_mode const mode) : file_validator_base{}, mode{mode}
explicit output_file_validator(output_file_open_options const mode) : file_validator_base{}, mode{mode}
{
if constexpr (!std::same_as<file_t, void>)
file_validator_base::extensions = detail::valid_file_extensions<typename file_t::valid_formats>();
Expand All @@ -654,7 +654,7 @@ class output_file_validator : public file_validator_base
* This constructor is only available if `file_t` does not name a valid seqan3 file type that contains a
* static member `valid_formats`.
*/
explicit output_file_validator(output_file_open_mode const mode, std::vector<std::string> extensions)
explicit output_file_validator(output_file_open_options const mode, std::vector<std::string> extensions)
//!\cond
requires std::same_as<file_t, void>
//!\endcond
Expand All @@ -679,7 +679,7 @@ class output_file_validator : public file_validator_base
{
try
{
if ((mode == exclusive) && std::filesystem::exists(file))
if ((mode == create_new) && std::filesystem::exists(file))
throw validation_error{detail::to_string("The file ", file, " already exists!")};

// Check if file has any write permissions.
Expand All @@ -700,9 +700,9 @@ 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
{
if (mode == overwritable)
if (mode == open_or_create)
return "Write permissions must be granted." + valid_extensions_help_page_message();
else // mode == exclusive
else // mode == create_new
return "The output file must not exist already and write permissions must be granted." +
valid_extensions_help_page_message();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main(int argc, const char ** argv)

myparser.add_option(mydir, 'd', "dir", "The output directory for storing the files.",
seqan3::option_spec::DEFAULT,
seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive});
seqan3::output_file_validator{seqan3::output_file_open_options::create_new});
//! [validator_call]

// an exception will be thrown if the user specifies a directory that cannot be created by the filesystem either
Expand Down
6 changes: 3 additions & 3 deletions test/snippet/argument_parser/validators_output_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ int main(int argc, const char ** argv)
//! [validator_call]
std::filesystem::path myfile{};

// Add the output_file_open_mode, to allow overwriting existing files, or to avoid this.
// Add the output_file_open_options, to allow overwriting existing files, or to avoid this.
myparser.add_option(myfile,'f',"file","Output file containing the processed sequences.",
seqan3::option_spec::DEFAULT,
seqan3::output_file_validator{seqan3::output_file_open_mode::overwritable, {"fa","fasta"}});
seqan3::output_file_validator{seqan3::output_file_open_options::open_or_create, {"fa","fasta"}});
// or
// seqan3::output_file_validator{seqan3::output_file_open_mode::exclusive, {"fa","fasta"}});
// seqan3::output_file_validator{seqan3::output_file_open_options::create_new, {"fa","fasta"}});
//! [validator_call]

// an exception will be thrown if the user specifies a filename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
int main(int argc, const char ** argv)
{
// Default constructed validator has an empty extension list.
seqan3::output_file_validator validator1{seqan3::output_file_open_mode::exclusive};
seqan3::output_file_validator validator1{seqan3::output_file_open_options::create_new};
seqan3::debug_stream << validator1.get_help_page_message() << "\n";

// Specify your own extensions for the output file.
seqan3::output_file_validator validator2{seqan3::output_file_open_mode::exclusive,
seqan3::output_file_validator validator2{seqan3::output_file_open_options::create_new,
std::vector{std::string{"exe"}, std::string{"fasta"}}};
seqan3::debug_stream << validator2.get_help_page_message() << "\n";

// Give the seqan3 file type as a template argument to get all valid extensions for this file.
seqan3::output_file_validator<seqan3::sequence_file_output<>> validator3{seqan3::output_file_open_mode::exclusive};
seqan3::output_file_validator<seqan3::sequence_file_output<>> validator3{
seqan3::output_file_open_options::create_new
};
seqan3::debug_stream << validator3.get_help_page_message() << "\n";

return 0;
Expand Down
Loading

0 comments on commit 85ee726

Please sign in to comment.