1 // 2 // Copyright 2019 The Abseil Authors. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // https://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 #ifndef ABSL_FLAGS_INTERNAL_PARSE_H_ 17 #define ABSL_FLAGS_INTERNAL_PARSE_H_ 18 19 #include <iostream> 20 #include <ostream> 21 #include <string> 22 #include <vector> 23 24 #include "absl/base/config.h" 25 #include "absl/flags/declare.h" 26 #include "absl/flags/internal/usage.h" 27 #include "absl/strings/string_view.h" 28 29 ABSL_DECLARE_FLAG(std::vector<std::string>, flagfile); 30 ABSL_DECLARE_FLAG(std::vector<std::string>, fromenv); 31 ABSL_DECLARE_FLAG(std::vector<std::string>, tryfromenv); 32 ABSL_DECLARE_FLAG(std::vector<std::string>, undefok); 33 34 namespace absl { 35 ABSL_NAMESPACE_BEGIN 36 namespace flags_internal { 37 38 enum class UsageFlagsAction { kHandleUsage, kIgnoreUsage }; 39 enum class OnUndefinedFlag { 40 kIgnoreUndefined, 41 kReportUndefined, 42 kAbortIfUndefined 43 }; 44 45 // This is not a public interface. This interface exists to expose the ability 46 // to change help output stream in case of parsing errors. This is used by 47 // internal unit tests to validate expected outputs. 48 // When this was written, `EXPECT_EXIT` only supported matchers on stderr, 49 // but not on stdout. 50 std::vector<char*> ParseCommandLineImpl( 51 int argc, char* argv[], UsageFlagsAction usage_flag_action, 52 OnUndefinedFlag undef_flag_action, 53 std::ostream& error_help_output = std::cout); 54 55 // -------------------------------------------------------------------- 56 // Inspect original command line 57 58 // Returns true if flag with specified name was either present on the original 59 // command line or specified in flag file present on the original command line. 60 bool WasPresentOnCommandLine(absl::string_view flag_name); 61 62 // Return existing flags similar to the parameter, in order to help in case of 63 // misspellings. 64 std::vector<std::string> GetMisspellingHints(absl::string_view flag); 65 66 } // namespace flags_internal 67 ABSL_NAMESPACE_END 68 } // namespace absl 69 70 #endif // ABSL_FLAGS_INTERNAL_PARSE_H_ 71