summaryrefslogtreecommitdiffstats
path: root/Source/cmCommandLineArgument.h
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2021-05-19 15:05:17 (GMT)
committerRobert Maynard <rmaynard@nvidia.com>2021-05-19 15:07:16 (GMT)
commit372bf1bcc410f3e36397bae9834ec141a5fca7ec (patch)
treea10f416d9f68bc95f13a08df5534510049204de1 /Source/cmCommandLineArgument.h
parent1b8d409342ec0672ba04e15da13b2a37ec49071a (diff)
downloadCMake-372bf1bcc410f3e36397bae9834ec141a5fca7ec.zip
CMake-372bf1bcc410f3e36397bae9834ec141a5fca7ec.tar.gz
CMake-372bf1bcc410f3e36397bae9834ec141a5fca7ec.tar.bz2
cmCommandLineArgument: Understands which commands require partial matching
Allows us to provide better error messages when commands such as `--target` are passed invalid input.
Diffstat (limited to 'Source/cmCommandLineArgument.h')
-rw-r--r--Source/cmCommandLineArgument.h48
1 files changed, 46 insertions, 2 deletions
diff --git a/Source/cmCommandLineArgument.h b/Source/cmCommandLineArgument.h
index 5031c65..e269771 100644
--- a/Source/cmCommandLineArgument.h
+++ b/Source/cmCommandLineArgument.h
@@ -17,10 +17,17 @@ struct cmCommandLineArgument
OneOrMore
};
+ enum class RequiresSeparator
+ {
+ Yes,
+ No
+ };
+
std::string InvalidSyntaxMessage;
std::string InvalidValueMessage;
std::string Name;
Values Type;
+ RequiresSeparator SeparatorNeeded;
std::function<FunctionSignature> StoreCall;
template <typename FunctionType>
@@ -29,6 +36,19 @@ struct cmCommandLineArgument
, InvalidValueMessage(cmStrCat("Invalid value used with ", n))
, Name(std::move(n))
, Type(t)
+ , SeparatorNeeded(RequiresSeparator::Yes)
+ , StoreCall(std::forward<FunctionType>(func))
+ {
+ }
+
+ template <typename FunctionType>
+ cmCommandLineArgument(std::string n, Values t, RequiresSeparator s,
+ FunctionType&& func)
+ : InvalidSyntaxMessage(cmStrCat(" is invalid syntax for ", n))
+ , InvalidValueMessage(cmStrCat("Invalid value used with ", n))
+ , Name(std::move(n))
+ , Type(t)
+ , SeparatorNeeded(s)
, StoreCall(std::forward<FunctionType>(func))
{
}
@@ -40,14 +60,38 @@ struct cmCommandLineArgument
, InvalidValueMessage(std::move(failedMsg))
, Name(std::move(n))
, Type(t)
+ , SeparatorNeeded(RequiresSeparator::Yes)
+ , StoreCall(std::forward<FunctionType>(func))
+ {
+ }
+
+ template <typename FunctionType>
+ cmCommandLineArgument(std::string n, std::string failedMsg, Values t,
+ RequiresSeparator s, FunctionType&& func)
+ : InvalidSyntaxMessage(cmStrCat(" is invalid syntax for ", n))
+ , InvalidValueMessage(std::move(failedMsg))
+ , Name(std::move(n))
+ , Type(t)
+ , SeparatorNeeded(s)
, StoreCall(std::forward<FunctionType>(func))
{
}
bool matches(std::string const& input) const
{
- return (this->Type == Values::Zero) ? (input == this->Name)
- : cmHasPrefix(input, this->Name);
+ if (this->Type == Values::Zero) {
+ return input == this->Name;
+ } else if (this->SeparatorNeeded == RequiresSeparator::No) {
+ return cmHasPrefix(input, this->Name);
+ } else if (cmHasPrefix(input, this->Name)) {
+ if (input.size() == this->Name.size()) {
+ return true;
+ } else {
+ return (input[this->Name.size()] == '=' ||
+ input[this->Name.size()] == ' ');
+ }
+ }
+ return false;
}
template <typename T, typename... CallState>