mirror of
https://github.com/fmang/opustags.git
synced 2025-03-14 08:30:08 +01:00
Options: throw an error for extra arguments
This commit is contained in:
parent
8f5a6bb534
commit
f726eaeb91
@ -124,9 +124,12 @@ Options opustags::parse_args(const int argc, char **argv)
|
||||
throw ArgumentError("Missing input path");
|
||||
}
|
||||
|
||||
options.path_in = argv[optind];
|
||||
options.path_in = argv[optind++];
|
||||
if (options.path_in.empty())
|
||||
throw ArgumentError("Input path cannot be empty");
|
||||
|
||||
if (optind < argc)
|
||||
throw ArgumentError("Extra argument: " + std::string(argv[optind]));
|
||||
|
||||
return options;
|
||||
}
|
||||
|
@ -67,14 +67,15 @@ TEST_CASE("option parsing", "[options]")
|
||||
SECTION("--in-place") {
|
||||
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", "ABC"}, false).in_place);
|
||||
REQUIRE(
|
||||
retrieve_options({"--in-place", "ABC"}, false).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", "ABC"}, false).in_place);
|
||||
REQUIRE(retrieve_options({"-i", "ABC"}, false).path_out == ".otmp");
|
||||
REQUIRE(retrieve_options({"-i"}).in_place);
|
||||
REQUIRE(retrieve_options({"-i"}).path_out == ".otmp");
|
||||
REQUIRE(retrieve_options({"-iABC"}).in_place);
|
||||
@ -85,6 +86,7 @@ TEST_CASE("option parsing", "[options]")
|
||||
REQUIRE_THROWS(retrieve_options({}, false));
|
||||
REQUIRE_THROWS(retrieve_options({""}, false));
|
||||
REQUIRE(retrieve_options({"input"}, false).path_in == "input");
|
||||
REQUIRE_THROWS(retrieve_options({"input", "extra argument"}, false));
|
||||
}
|
||||
|
||||
SECTION("--output") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user