parse.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. // -----------------------------------------------------------------------------
  17. // File: parse.h
  18. // -----------------------------------------------------------------------------
  19. //
  20. // This file defines the main parsing function for Abseil flags:
  21. // `absl::ParseCommandLine()`.
  22. #ifndef ABSL_FLAGS_PARSE_H_
  23. #define ABSL_FLAGS_PARSE_H_
  24. #include <vector>
  25. #include "absl/base/config.h"
  26. #include "absl/flags/internal/parse.h"
  27. namespace absl {
  28. ABSL_NAMESPACE_BEGIN
  29. // ParseCommandLine()
  30. //
  31. // Parses the set of command-line arguments passed in the `argc` (argument
  32. // count) and `argv[]` (argument vector) parameters from `main()`, assigning
  33. // values to any defined Abseil flags. (Any arguments passed after the
  34. // flag-terminating delimiter (`--`) are treated as positional arguments and
  35. // ignored.)
  36. //
  37. // Any command-line flags (and arguments to those flags) are parsed into Abseil
  38. // Flag values, if those flags are defined. Any undefined flags will either
  39. // return an error, or be ignored if that flag is designated using `undefok` to
  40. // indicate "undefined is OK."
  41. //
  42. // Any command-line positional arguments not part of any command-line flag (or
  43. // arguments to a flag) are returned in a vector, with the program invocation
  44. // name at position 0 of that vector. (Note that this includes positional
  45. // arguments after the flag-terminating delimiter `--`.)
  46. //
  47. // After all flags and flag arguments are parsed, this function looks for any
  48. // built-in usage flags (e.g. `--help`), and if any were specified, it reports
  49. // help messages and then exits the program.
  50. std::vector<char*> ParseCommandLine(int argc, char* argv[]);
  51. ABSL_NAMESPACE_END
  52. } // namespace absl
  53. #endif // ABSL_FLAGS_PARSE_H_