parse.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 <string>
  18. #include <vector>
  19. #include "absl/base/config.h"
  20. #include "absl/flags/declare.h"
  21. #include "absl/strings/string_view.h"
  22. ABSL_DECLARE_FLAG(std::vector<std::string>, flagfile);
  23. ABSL_DECLARE_FLAG(std::vector<std::string>, fromenv);
  24. ABSL_DECLARE_FLAG(std::vector<std::string>, tryfromenv);
  25. ABSL_DECLARE_FLAG(std::vector<std::string>, undefok);
  26. namespace absl {
  27. ABSL_NAMESPACE_BEGIN
  28. namespace flags_internal {
  29. enum class ArgvListAction { kRemoveParsedArgs, kKeepParsedArgs };
  30. enum class UsageFlagsAction { kHandleUsage, kIgnoreUsage };
  31. enum class OnUndefinedFlag {
  32. kIgnoreUndefined,
  33. kReportUndefined,
  34. kAbortIfUndefined
  35. };
  36. std::vector<char*> ParseCommandLineImpl(int argc, char* argv[],
  37. ArgvListAction arg_list_act,
  38. UsageFlagsAction usage_flag_act,
  39. OnUndefinedFlag on_undef_flag);
  40. // --------------------------------------------------------------------
  41. // Inspect original command line
  42. // Returns true if flag with specified name was either present on the original
  43. // command line or specified in flag file present on the original command line.
  44. bool WasPresentOnCommandLine(absl::string_view flag_name);
  45. } // namespace flags_internal
  46. ABSL_NAMESPACE_END
  47. } // namespace absl
  48. #endif // ABSL_FLAGS_INTERNAL_PARSE_H_