Options: change in_place to contain bool

This should minify conditional statements to just one, after finishing
work, whether to move the path_out back to the original file.
This commit is contained in:
rr- 2016-03-16 12:31:43 +01:00
parent be3984423f
commit 7f7766f175
3 changed files with 17 additions and 9 deletions

View File

@ -60,7 +60,8 @@ Options opustags::parse_args(const int argc, char **argv)
break;
case 'i':
options.in_place = arg.empty() ? ".otmp" : arg;
options.path_out = arg.empty() ? ".otmp" : arg;
options.in_place = true;
break;
case 'y':

View File

@ -15,7 +15,7 @@ namespace opustags
bool overwrite;
bool set_all;
std::string in_place;
bool in_place;
std::string path_out;
CompositeTagsHandler tags_handler;

View File

@ -62,13 +62,20 @@ TEST_CASE("option parsing", "[options]")
}
SECTION("--in-place") {
REQUIRE(retrieve_options({"-i"}).in_place == ".otmp");
REQUIRE(retrieve_options({"--in-place"}).in_place == ".otmp");
REQUIRE(retrieve_options({"--in-place=ABC"}).in_place == "ABC");
REQUIRE(retrieve_options({"-iABC"}).in_place == "ABC");
REQUIRE(retrieve_options({"--in-place", "ABC"}).in_place == ".otmp");
REQUIRE(retrieve_options({"-i", "ABC"}).in_place == ".otmp");
REQUIRE(retrieve_options({}).in_place.empty());
REQUIRE(!retrieve_options({}).in_place);
REQUIRE(retrieve_options({}).path_out.empty());
REQUIRE(retrieve_options({"--in-place", "ABC"}).in_place);
REQUIRE(retrieve_options({"--in-place", "ABC"}).path_out == ".otmp");
REQUIRE(retrieve_options({"--in-place"}).in_place);
REQUIRE(retrieve_options({"--in-place"}).path_out == ".otmp");
REQUIRE(retrieve_options({"--in-place=ABC"}).in_place);
REQUIRE(retrieve_options({"--in-place=ABC"}).path_out == "ABC");
REQUIRE(retrieve_options({"-i", "ABC"}).in_place);
REQUIRE(retrieve_options({"-i", "ABC"}).path_out == ".otmp");
REQUIRE(retrieve_options({"-i"}).in_place);
REQUIRE(retrieve_options({"-i"}).path_out == ".otmp");
REQUIRE(retrieve_options({"-iABC"}).in_place);
REQUIRE(retrieve_options({"-iABC"}).path_out == "ABC");
}
SECTION("--output") {