usage.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. ABSL_NAMESPACE_BEGIN
  27. namespace flags_internal {
  28. // The format to report the help messages in.
  29. enum class HelpFormat {
  30. kHumanReadable,
  31. };
  32. // Outputs the help message describing specific flag.
  33. void FlagHelp(std::ostream& out, const CommandLineFlag& flag,
  34. HelpFormat format = HelpFormat::kHumanReadable);
  35. // Produces the help messages for all flags matching the filter. A flag matches
  36. // the filter if it is defined in a file with a filename which includes
  37. // filter string as a substring. You can use '/' and '.' to restrict the
  38. // matching to a specific file names. For example:
  39. // FlagsHelp(out, "/path/to/file.");
  40. // restricts help to only flags which resides in files named like:
  41. // .../path/to/file.<ext>
  42. // for any extension 'ext'. If the filter is empty this function produces help
  43. // messages for all flags.
  44. void FlagsHelp(std::ostream& out, absl::string_view filter,
  45. HelpFormat format, absl::string_view program_usage_message);
  46. // --------------------------------------------------------------------
  47. // If any of the 'usage' related command line flags (listed on the bottom of
  48. // this file) has been set this routine produces corresponding help message in
  49. // the specified output stream and returns:
  50. // 0 - if "version" or "only_check_flags" flags were set and handled.
  51. // 1 - if some other 'usage' related flag was set and handled.
  52. // -1 - if no usage flags were set on a commmand line.
  53. // Non negative return values are expected to be used as an exit code for a
  54. // binary.
  55. int HandleUsageFlags(std::ostream& out,
  56. absl::string_view program_usage_message);
  57. } // namespace flags_internal
  58. ABSL_NAMESPACE_END
  59. } // namespace absl
  60. ABSL_DECLARE_FLAG(bool, help);
  61. ABSL_DECLARE_FLAG(bool, helpfull);
  62. ABSL_DECLARE_FLAG(bool, helpshort);
  63. ABSL_DECLARE_FLAG(bool, helppackage);
  64. ABSL_DECLARE_FLAG(bool, version);
  65. ABSL_DECLARE_FLAG(bool, only_check_args);
  66. ABSL_DECLARE_FLAG(std::string, helpon);
  67. ABSL_DECLARE_FLAG(std::string, helpmatch);
  68. #endif // ABSL_FLAGS_INTERNAL_USAGE_H_