|
||||
File indexing completed on 2025-01-18 09:27:17
0001 // 0002 // Copyright 2019 The Abseil Authors. 0003 // 0004 // Licensed under the Apache License, Version 2.0 (the "License"); 0005 // you may not use this file except in compliance with the License. 0006 // You may obtain a copy of the License at 0007 // 0008 // https://www.apache.org/licenses/LICENSE-2.0 0009 // 0010 // Unless required by applicable law or agreed to in writing, software 0011 // distributed under the License is distributed on an "AS IS" BASIS, 0012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0013 // See the License for the specific language governing permissions and 0014 // limitations under the License. 0015 // 0016 // ----------------------------------------------------------------------------- 0017 // File: usage_config.h 0018 // ----------------------------------------------------------------------------- 0019 // 0020 // This file defines the main usage reporting configuration interfaces and 0021 // documents Abseil's supported built-in usage flags. If these flags are found 0022 // when parsing a command-line, Abseil will exit the program and display 0023 // appropriate help messages. 0024 #ifndef ABSL_FLAGS_USAGE_CONFIG_H_ 0025 #define ABSL_FLAGS_USAGE_CONFIG_H_ 0026 0027 #include <functional> 0028 #include <string> 0029 0030 #include "absl/base/config.h" 0031 #include "absl/strings/string_view.h" 0032 0033 // ----------------------------------------------------------------------------- 0034 // Built-in Usage Flags 0035 // ----------------------------------------------------------------------------- 0036 // 0037 // Abseil supports the following built-in usage flags. When passed, these flags 0038 // exit the program and : 0039 // 0040 // * --help 0041 // Shows help on important flags for this binary 0042 // * --helpfull 0043 // Shows help on all flags 0044 // * --helpshort 0045 // Shows help on only the main module for this program 0046 // * --helppackage 0047 // Shows help on all modules in the main package 0048 // * --version 0049 // Shows the version and build info for this binary and exits 0050 // * --only_check_args 0051 // Exits after checking all flags 0052 // * --helpon 0053 // Shows help on the modules named by this flag value 0054 // * --helpmatch 0055 // Shows help on modules whose name contains the specified substring 0056 0057 namespace absl { 0058 ABSL_NAMESPACE_BEGIN 0059 0060 namespace flags_internal { 0061 using FlagKindFilter = std::function<bool (absl::string_view)>; 0062 } // namespace flags_internal 0063 0064 // FlagsUsageConfig 0065 // 0066 // This structure contains the collection of callbacks for changing the behavior 0067 // of the usage reporting routines in Abseil Flags. 0068 struct FlagsUsageConfig { 0069 // Returns true if flags defined in the given source code file should be 0070 // reported with --helpshort flag. For example, if the file 0071 // "path/to/my/code.cc" defines the flag "--my_flag", and 0072 // contains_helpshort_flags("path/to/my/code.cc") returns true, invoking the 0073 // program with --helpshort will include information about --my_flag in the 0074 // program output. 0075 flags_internal::FlagKindFilter contains_helpshort_flags; 0076 0077 // Returns true if flags defined in the filename should be reported with 0078 // --help flag. For example, if the file 0079 // "path/to/my/code.cc" defines the flag "--my_flag", and 0080 // contains_help_flags("path/to/my/code.cc") returns true, invoking the 0081 // program with --help will include information about --my_flag in the 0082 // program output. 0083 flags_internal::FlagKindFilter contains_help_flags; 0084 0085 // Returns true if flags defined in the filename should be reported with 0086 // --helppackage flag. For example, if the file 0087 // "path/to/my/code.cc" defines the flag "--my_flag", and 0088 // contains_helppackage_flags("path/to/my/code.cc") returns true, invoking the 0089 // program with --helppackage will include information about --my_flag in the 0090 // program output. 0091 flags_internal::FlagKindFilter contains_helppackage_flags; 0092 0093 // Generates string containing program version. This is the string reported 0094 // when user specifies --version in a command line. 0095 std::function<std::string()> version_string; 0096 0097 // Normalizes the filename specific to the build system/filesystem used. This 0098 // routine is used when we report the information about the flag definition 0099 // location. For instance, if your build resides at some location you do not 0100 // want to expose in the usage output, you can trim it to show only relevant 0101 // part. 0102 // For example: 0103 // normalize_filename("/my_company/some_long_path/src/project/file.cc") 0104 // might produce 0105 // "project/file.cc". 0106 std::function<std::string(absl::string_view)> normalize_filename; 0107 }; 0108 0109 // SetFlagsUsageConfig() 0110 // 0111 // Sets the usage reporting configuration callbacks. If any of the callbacks are 0112 // not set in usage_config instance, then the default value of the callback is 0113 // used. 0114 void SetFlagsUsageConfig(FlagsUsageConfig usage_config); 0115 0116 namespace flags_internal { 0117 0118 FlagsUsageConfig GetUsageConfig(); 0119 0120 void ReportUsageError(absl::string_view msg, bool is_fatal); 0121 0122 } // namespace flags_internal 0123 ABSL_NAMESPACE_END 0124 } // namespace absl 0125 0126 extern "C" { 0127 0128 // Additional report of fatal usage error message before we std::exit. Error is 0129 // fatal if is_fatal argument to ReportUsageError is true. 0130 void ABSL_INTERNAL_C_SYMBOL(AbslInternalReportFatalUsageError)( 0131 absl::string_view); 0132 0133 } // extern "C" 0134 0135 #endif // ABSL_FLAGS_USAGE_CONFIG_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |