mirror of
https://github.com/Kitware/CMake.git
synced 2026-11-06 05:16:58 +00:00
ctest: Factor out command line argument table lookup
The preset pre-pass and the main argument loop both searched an argument table for a match and parsed it. Share that logic through a local helper.
This commit is contained in:
1 parent
42ab537fb1
commit
62f2e49c7e
1 file changed
+20
-17
+20
-17
@@ -2597,17 +2597,25 @@ int cmCTest::Run(std::vector<std::string> const& args)
|
||||
} },
|
||||
};
|
||||
|
||||
// Parse `arg` using the first entry of `table` that matches it. Returns
|
||||
// nothing if no entry matches, or the result of parsing otherwise.
|
||||
auto const tryParse = [&args](std::vector<CommandArgument> const& table,
|
||||
std::string const& arg,
|
||||
size_t& i) -> cm::optional<bool> {
|
||||
for (auto const& m : table) {
|
||||
if (m.matches(arg)) {
|
||||
return m.parse(arg, i, args);
|
||||
}
|
||||
}
|
||||
return cm::nullopt;
|
||||
};
|
||||
|
||||
// Process command line arguments for presets first, since other arguments
|
||||
// can override those settings.
|
||||
for (size_t i = 1; i < args.size(); ++i) {
|
||||
std::string const& arg = args[i];
|
||||
for (auto const& m : presetArguments) {
|
||||
if (m.matches(arg)) {
|
||||
if (!m.parse(arg, i, args)) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
cm::optional<bool> const parsed = tryParse(presetArguments, args[i], i);
|
||||
if (parsed && !parsed.value()) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2636,16 +2644,11 @@ int cmCTest::Run(std::vector<std::string> const& args)
|
||||
break;
|
||||
}
|
||||
|
||||
bool matched = false;
|
||||
for (auto const& m : arguments) {
|
||||
if (m.matches(arg)) {
|
||||
matched = true;
|
||||
if (!m.parse(arg, i, args)) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
cm::optional<bool> const parsed = tryParse(arguments, arg, i);
|
||||
if (parsed && !parsed.value()) {
|
||||
return 1;
|
||||
}
|
||||
bool matched = parsed.has_value();
|
||||
if (!matched && arg == "--build-options"_s) {
|
||||
matched = true;
|
||||
while (i + 1 < args.size() && args[i + 1] != "--build-target"_s &&
|
||||
|
||||
Reference in new issue
Block a user