parse.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #ifndef ABSL_FLAGS_INTERNAL_PARSE_H_
  16. #define ABSL_FLAGS_INTERNAL_PARSE_H_
  17. #include <iostream>
  18. #include <ostream>
  19. #include <string>
  20. #include <vector>
  21. #include "absl/base/config.h"
  22. #include "absl/flags/declare.h"
  23. #include "absl/flags/internal/usage.h"
  24. #include "absl/strings/string_view.h"
  25. ABSL_DECLARE_FLAG(std::vector<std::string>, flagfile);
  26. ABSL_DECLARE_FLAG(std::vector<std::string>, fromenv);
  27. ABSL_DECLARE_FLAG(std::vector<std::string>, tryfromenv);
  28. ABSL_DECLARE_FLAG(std::vector<std::string>, undefok);
  29. namespace absl {
  30. ABSL_NAMESPACE_BEGIN
  31. namespace flags_internal {
  32. enum class UsageFlagsAction { kHandleUsage, kIgnoreUsage };
  33. enum class OnUndefinedFlag {
  34. kIgnoreUndefined,
  35. kReportUndefined,
  36. kAbortIfUndefined
  37. };
  38. // This is not a public interface. This interface exists to expose the ability
  39. // to change help output stream in case of parsing errors. This is used by
  40. // internal unit tests to validate expected outputs.
  41. // When this was written, `EXPECT_EXIT` only supported matchers on stderr,
  42. // but not on stdout.
  43. std::vector<char*> ParseCommandLineImpl(
  44. int argc, char* argv[], UsageFlagsAction usage_flag_action,
  45. OnUndefinedFlag undef_flag_action,
  46. std::ostream& error_help_output = std::cout);
  47. // --------------------------------------------------------------------
  48. // Inspect original command line
  49. // Returns true if flag with specified name was either present on the original
  50. // command line or specified in flag file present on the original command line.
  51. bool WasPresentOnCommandLine(absl::string_view flag_name);
  52. // Return existing flags similar to the parameter, in order to help in case of
  53. // misspellings.
  54. std::vector<std::string> GetMisspellingHints(absl::string_view flag);
  55. } // namespace flags_internal
  56. ABSL_NAMESPACE_END
  57. } // namespace absl
  58. #endif // ABSL_FLAGS_INTERNAL_PARSE_H_