瀏覽代碼

cmArgumentParser: Drop unused keywordsMissingValue argument to Parse()

All clients have been converted to encoding this requirement in their
bindings.
Brad King 3 年之前
父節點
當前提交
f95a5832c7

+ 1 - 2
Source/CTest/cmCTestHandlerCommand.cxx

@@ -83,8 +83,7 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args,
   // Process input arguments.
   std::vector<std::string> unparsedArguments;
   std::vector<cm::string_view> parsedKeywords;
-  this->Parse(args, &unparsedArguments, /*keywordsMissingValue=*/nullptr,
-              &parsedKeywords);
+  this->Parse(args, &unparsedArguments, &parsedKeywords);
   this->CheckArguments();
 
   std::sort(parsedKeywords.begin(), parsedKeywords.end());

+ 0 - 3
Source/cmArgumentParser.cxx

@@ -113,9 +113,6 @@ void Instance::FinishKeyword()
       this->ParseResults->AddKeywordError(this->Keyword,
                                           "  missing required value\n");
     }
-    if (this->KeywordsMissingValue != nullptr) {
-      this->KeywordsMissingValue->emplace_back(this->Keyword);
-    }
     if (this->Bindings.KeywordMissingValue) {
       this->Bindings.KeywordMissingValue(*this, this->Keyword);
     }

+ 3 - 10
Source/cmArgumentParser.h

@@ -115,13 +115,11 @@ class Instance
 public:
   Instance(ActionMap const& bindings, ParseResult* parseResult,
            std::vector<std::string>* unparsedArguments,
-           std::vector<cm::string_view>* keywordsMissingValue,
            std::vector<cm::string_view>* parsedKeywords,
            void* result = nullptr)
     : Bindings(bindings)
     , ParseResults(parseResult)
     , UnparsedArguments(unparsedArguments)
-    , KeywordsMissingValue(keywordsMissingValue)
     , ParsedKeywords(parsedKeywords)
     , Result(result)
   {
@@ -157,7 +155,6 @@ private:
   ActionMap const& Bindings;
   ParseResult* ParseResults = nullptr;
   std::vector<std::string>* UnparsedArguments = nullptr;
-  std::vector<cm::string_view>* KeywordsMissingValue = nullptr;
   std::vector<cm::string_view>* ParsedKeywords = nullptr;
   void* Result = nullptr;
 
@@ -193,25 +190,22 @@ public:
   template <typename Range>
   bool Parse(Result& result, Range const& args,
              std::vector<std::string>* unparsedArguments,
-             std::vector<cm::string_view>* keywordsMissingValue = nullptr,
              std::vector<cm::string_view>* parsedKeywords = nullptr) const
   {
     using ArgumentParser::AsParseResultPtr;
     ParseResult* parseResultPtr = AsParseResultPtr(result);
     Instance instance(this->Bindings, parseResultPtr, unparsedArguments,
-                      keywordsMissingValue, parsedKeywords, &result);
+                      parsedKeywords, &result);
     instance.Parse(args);
     return parseResultPtr ? static_cast<bool>(*parseResultPtr) : true;
   }
 
   template <typename Range>
   Result Parse(Range const& args, std::vector<std::string>* unparsedArguments,
-               std::vector<cm::string_view>* keywordsMissingValue = nullptr,
                std::vector<cm::string_view>* parsedKeywords = nullptr) const
   {
     Result result;
-    this->Parse(result, args, unparsedArguments, keywordsMissingValue,
-                parsedKeywords);
+    this->Parse(result, args, unparsedArguments, parsedKeywords);
     return result;
   }
 };
@@ -230,12 +224,11 @@ public:
   template <typename Range>
   ParseResult Parse(
     Range const& args, std::vector<std::string>* unparsedArguments,
-    std::vector<cm::string_view>* keywordsMissingValue = nullptr,
     std::vector<cm::string_view>* parsedKeywords = nullptr) const
   {
     ParseResult parseResult;
     Instance instance(this->Bindings, &parseResult, unparsedArguments,
-                      keywordsMissingValue, parsedKeywords);
+                      parsedKeywords);
     instance.Parse(args);
     return parseResult;
   }

+ 2 - 3
Source/cmFileCommand.cxx

@@ -2498,9 +2498,8 @@ bool HandleGenerateCommand(std::vector<std::string> const& args,
 
   std::vector<std::string> unparsedArguments;
   std::vector<cm::string_view> parsedKeywords;
-  Arguments const arguments =
-    parser.Parse(cmMakeRange(args).advance(1), &unparsedArguments,
-                 /*keywordsMissingValue=*/nullptr, &parsedKeywords);
+  Arguments const arguments = parser.Parse(
+    cmMakeRange(args).advance(1), &unparsedArguments, &parsedKeywords);
 
   if (arguments.MaybeReportError(status.GetMakefile())) {
     return true;

+ 7 - 17
Tests/CMakeLib/testArgumentParser.cxx

@@ -63,14 +63,10 @@ std::initializer_list<cm::string_view> const args = {
 };
 
 bool verifyResult(Result const& result,
-                  std::vector<std::string> const& unparsedArguments,
-                  std::vector<cm::string_view> const& keywordsMissingValue)
+                  std::vector<std::string> const& unparsedArguments)
 {
   static std::vector<std::string> const foobar = { "foo", "bar" };
   static std::vector<std::string> const barfoo = { "bar", "foo" };
-  static std::vector<cm::string_view> const missing = { "STRING_1"_s,
-                                                        "LIST_1"_s,
-                                                        "LIST_4"_s };
   static std::map<cm::string_view, std::string> const keywordErrors = {
     { "STRING_1"_s, "  missing required value\n" },
     { "LIST_1"_s, "  missing required value\n" },
@@ -117,7 +113,6 @@ bool verifyResult(Result const& result,
 
   ASSERT_TRUE(unparsedArguments.size() == 1);
   ASSERT_TRUE(unparsedArguments[0] == "bar");
-  ASSERT_TRUE(keywordsMissingValue == missing);
 
   ASSERT_TRUE(result.GetKeywordErrors().size() == keywordErrors.size());
   for (auto const& ke : result.GetKeywordErrors()) {
@@ -133,7 +128,6 @@ bool testArgumentParserDynamic()
 {
   Result result;
   std::vector<std::string> unparsedArguments;
-  std::vector<cm::string_view> keywordsMissingValue;
 
   static_cast<ArgumentParser::ParseResult&>(result) =
     cmArgumentParser<void>{}
@@ -153,9 +147,9 @@ bool testArgumentParserDynamic()
       .Bind("MULTI_2"_s, result.Multi2)
       .Bind("MULTI_3"_s, result.Multi3)
       .Bind("MULTI_4"_s, result.Multi4)
-      .Parse(args, &unparsedArguments, &keywordsMissingValue);
+      .Parse(args, &unparsedArguments);
 
-  return verifyResult(result, unparsedArguments, keywordsMissingValue);
+  return verifyResult(result, unparsedArguments);
 }
 
 static auto const parserStatic = //
@@ -181,20 +175,16 @@ static auto const parserStatic = //
 bool testArgumentParserStatic()
 {
   std::vector<std::string> unparsedArguments;
-  std::vector<cm::string_view> keywordsMissingValue;
-  Result const result =
-    parserStatic.Parse(args, &unparsedArguments, &keywordsMissingValue);
-  return verifyResult(result, unparsedArguments, keywordsMissingValue);
+  Result const result = parserStatic.Parse(args, &unparsedArguments);
+  return verifyResult(result, unparsedArguments);
 }
 
 bool testArgumentParserStaticBool()
 {
   std::vector<std::string> unparsedArguments;
-  std::vector<cm::string_view> keywordsMissingValue;
   Result result;
-  ASSERT_TRUE(parserStatic.Parse(result, args, &unparsedArguments,
-                                 &keywordsMissingValue) == false);
-  return verifyResult(result, unparsedArguments, keywordsMissingValue);
+  ASSERT_TRUE(parserStatic.Parse(result, args, &unparsedArguments) == false);
+  return verifyResult(result, unparsedArguments);
 }
 
 } // namespace