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