You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

usage.h 4.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_USAGE_H_
  16. #define ABSL_FLAGS_INTERNAL_USAGE_H_
  17. #include <iosfwd>
  18. #include <string>
  19. #include "absl/base/config.h"
  20. #include "absl/flags/commandlineflag.h"
  21. #include "absl/flags/declare.h"
  22. #include "absl/strings/string_view.h"
  23. // --------------------------------------------------------------------
  24. // Usage reporting interfaces
  25. namespace absl
  26. {
  27. ABSL_NAMESPACE_BEGIN
  28. namespace flags_internal
  29. {
  30. // The format to report the help messages in.
  31. enum class HelpFormat
  32. {
  33. kHumanReadable,
  34. };
  35. // Streams the help message describing `flag` to `out`.
  36. // The default value for `flag` is included in the output.
  37. void FlagHelp(std::ostream& out, const CommandLineFlag& flag, HelpFormat format = HelpFormat::kHumanReadable);
  38. // Produces the help messages for all flags matching the filter. A flag matches
  39. // the filter if it is defined in a file with a filename which includes
  40. // filter string as a substring. You can use '/' and '.' to restrict the
  41. // matching to a specific file names. For example:
  42. // FlagsHelp(out, "/path/to/file.");
  43. // restricts help to only flags which resides in files named like:
  44. // .../path/to/file.<ext>
  45. // for any extension 'ext'. If the filter is empty this function produces help
  46. // messages for all flags.
  47. void FlagsHelp(std::ostream& out, absl::string_view filter, HelpFormat format, absl::string_view program_usage_message);
  48. // --------------------------------------------------------------------
  49. // If any of the 'usage' related command line flags (listed on the bottom of
  50. // this file) has been set this routine produces corresponding help message in
  51. // the specified output stream and returns:
  52. // 0 - if "version" or "only_check_flags" flags were set and handled.
  53. // 1 - if some other 'usage' related flag was set and handled.
  54. // -1 - if no usage flags were set on a commmand line.
  55. // Non negative return values are expected to be used as an exit code for a
  56. // binary.
  57. int HandleUsageFlags(std::ostream& out, absl::string_view program_usage_message);
  58. // --------------------------------------------------------------------
  59. // Globals representing usage reporting flags
  60. enum class HelpMode
  61. {
  62. kNone,
  63. kImportant,
  64. kShort,
  65. kFull,
  66. kPackage,
  67. kMatch,
  68. kVersion,
  69. kOnlyCheckArgs
  70. };
  71. // Returns substring to filter help output (--help=substr argument)
  72. std::string GetFlagsHelpMatchSubstr();
  73. // Returns the requested help mode.
  74. HelpMode GetFlagsHelpMode();
  75. // Returns the requested help format.
  76. HelpFormat GetFlagsHelpFormat();
  77. // These are corresponding setters to the attributes above.
  78. void SetFlagsHelpMatchSubstr(absl::string_view);
  79. void SetFlagsHelpMode(HelpMode);
  80. void SetFlagsHelpFormat(HelpFormat);
  81. // Deduces usage flags from the input argument in a form --name=value or
  82. // --name. argument is already split into name and value before we call this
  83. // function.
  84. bool DeduceUsageFlags(absl::string_view name, absl::string_view value);
  85. } // namespace flags_internal
  86. ABSL_NAMESPACE_END
  87. } // namespace absl
  88. #endif // ABSL_FLAGS_INTERNAL_USAGE_H_