summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2022-01-18 19:47:39 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2022-01-18 20:52:01 (GMT)
commit7d26baff46072055e4cdf56a52634c9e7ff4ee50 (patch)
tree8dbde08b2aaaa179373485aae69c793ffefb7f6b /Source
parenta2e42a577b08dc65ba801e18e5c8be163df83455 (diff)
downloadCMake-7d26baff46072055e4cdf56a52634c9e7ff4ee50.zip
CMake-7d26baff46072055e4cdf56a52634c9e7ff4ee50.tar.gz
CMake-7d26baff46072055e4cdf56a52634c9e7ff4ee50.tar.bz2
cmDefinePropertyCommand: Refactor to use cmArgumentParser
Diffstat (limited to 'Source')
-rw-r--r--Source/cmDefinePropertyCommand.cxx53
1 files changed, 21 insertions, 32 deletions
diff --git a/Source/cmDefinePropertyCommand.cxx b/Source/cmDefinePropertyCommand.cxx
index 4e2d9b0..ca43a11 100644
--- a/Source/cmDefinePropertyCommand.cxx
+++ b/Source/cmDefinePropertyCommand.cxx
@@ -2,6 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmDefinePropertyCommand.h"
+#include <cm/string_view>
+#include <cmext/string_view>
+
+#include "cmArgumentParser.h"
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmProperty.h"
@@ -44,37 +48,21 @@ bool cmDefinePropertyCommand(std::vector<std::string> const& args,
// Parse remaining arguments.
bool inherited = false;
std::string PropertyName;
- std::string BriefDocs;
- std::string FullDocs;
- enum Doing
- {
- DoingNone,
- DoingProperty,
- DoingBrief,
- DoingFull
- };
- Doing doing = DoingNone;
- for (unsigned int i = 1; i < args.size(); ++i) {
- if (args[i] == "PROPERTY") {
- doing = DoingProperty;
- } else if (args[i] == "BRIEF_DOCS") {
- doing = DoingBrief;
- } else if (args[i] == "FULL_DOCS") {
- doing = DoingFull;
- } else if (args[i] == "INHERITED") {
- doing = DoingNone;
- inherited = true;
- } else if (doing == DoingProperty) {
- doing = DoingNone;
- PropertyName = args[i];
- } else if (doing == DoingBrief) {
- BriefDocs += args[i];
- } else if (doing == DoingFull) {
- FullDocs += args[i];
- } else {
- status.SetError(cmStrCat("given invalid argument \"", args[i], "\"."));
- return false;
- }
+ std::vector<std::string> BriefDocs;
+ std::vector<std::string> FullDocs;
+
+ cmArgumentParser<void> parser;
+ parser.Bind("PROPERTY"_s, PropertyName);
+ parser.Bind("BRIEF_DOCS"_s, BriefDocs);
+ parser.Bind("FULL_DOCS"_s, FullDocs);
+ parser.Bind("INHERITED"_s, inherited);
+ std::vector<std::string> invalidArgs;
+
+ parser.Parse(cmMakeRange(args).advance(1), &invalidArgs);
+ if (!invalidArgs.empty()) {
+ status.SetError(
+ cmStrCat("given invalid argument \"", invalidArgs.front(), "\"."));
+ return false;
}
// Make sure a property name was found.
@@ -95,7 +83,8 @@ bool cmDefinePropertyCommand(std::vector<std::string> const& args,
// Actually define the property.
status.GetMakefile().GetState()->DefineProperty(
- PropertyName, scope, BriefDocs, FullDocs, inherited);
+ PropertyName, scope, cmJoin(BriefDocs, ""), cmJoin(FullDocs, ""),
+ inherited);
return true;
}