00001 // 00002 // Copyright 2019 The Abseil Authors. 00003 // 00004 // Licensed under the Apache License, Version 2.0 (the "License"); 00005 // you may not use this file except in compliance with the License. 00006 // You may obtain a copy of the License at 00007 // 00008 // https://www.apache.org/licenses/LICENSE-2.0 00009 // 00010 // Unless required by applicable law or agreed to in writing, software 00011 // distributed under the License is distributed on an "AS IS" BASIS, 00012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 // See the License for the specific language governing permissions and 00014 // limitations under the License. 00015 // 00016 // ----------------------------------------------------------------------------- 00017 // File: usage_config.h 00018 // ----------------------------------------------------------------------------- 00019 // 00020 // This file defines the main usage reporting configuration interfaces and 00021 // documents Abseil's supported built-in usage flags. If these flags are found 00022 // when parsing a command-line, Abseil will exit the program and display 00023 // appropriate help messages. 00024 #ifndef ABSL_FLAGS_USAGE_CONFIG_H_ 00025 #define ABSL_FLAGS_USAGE_CONFIG_H_ 00026 00027 #include <functional> 00028 #include <string> 00029 00030 #include "absl/strings/string_view.h" 00031 00032 // ----------------------------------------------------------------------------- 00033 // Built-in Usage Flags 00034 // ----------------------------------------------------------------------------- 00035 // 00036 // Abseil supports the following built-in usage flags. When passed, these flags 00037 // exit the program and : 00038 // 00039 // * --help 00040 // Shows help on important flags for this binary 00041 // * --helpfull 00042 // Shows help on all flags 00043 // * --helpshort 00044 // Shows help on only the main module for this program 00045 // * --helppackage 00046 // Shows help on all modules in the main package 00047 // * --version 00048 // Shows the version and build info for this binary and exits 00049 // * --only_check_args 00050 // Exits after checking all flags 00051 // * --helpon 00052 // Shows help on the modules named by this flag value 00053 // * --helpmatch 00054 // Shows help on modules whose name contains the specified substring 00055 00056 namespace absl { 00057 00058 namespace flags_internal { 00059 using FlagKindFilter = std::function<bool (absl::string_view)>; 00060 } // namespace flags_internal 00061 00062 // FlagsUsageConfig 00063 // 00064 // This structure contains the collection of callbacks for changing the behavior 00065 // of the usage reporting routines in Abseil Flags. 00066 struct FlagsUsageConfig { 00067 // Returns true if flags defined in the given source code file should be 00068 // reported with --helpshort flag. For example, if the file 00069 // "path/to/my/code.cc" defines the flag "--my_flag", and 00070 // contains_helpshort_flags("path/to/my/code.cc") returns true, invoking the 00071 // program with --helpshort will include information about --my_flag in the 00072 // program output. 00073 flags_internal::FlagKindFilter contains_helpshort_flags; 00074 00075 // Returns true if flags defined in the filename should be reported with 00076 // --help flag. For example, if the file 00077 // "path/to/my/code.cc" defines the flag "--my_flag", and 00078 // contains_help_flags("path/to/my/code.cc") returns true, invoking the 00079 // program with --help will include information about --my_flag in the 00080 // program output. 00081 flags_internal::FlagKindFilter contains_help_flags; 00082 00083 // Returns true if flags defined in the filename should be reported with 00084 // --helppackage flag. For example, if the file 00085 // "path/to/my/code.cc" defines the flag "--my_flag", and 00086 // contains_helppackage_flags("path/to/my/code.cc") returns true, invoking the 00087 // program with --helppackage will include information about --my_flag in the 00088 // program output. 00089 flags_internal::FlagKindFilter contains_helppackage_flags; 00090 00091 // Generates std::string containing program version. This is the std::string reported 00092 // when user specifies --version in a command line. 00093 std::function<std::string()> version_string; 00094 00095 // Normalizes the filename specific to the build system/filesystem used. This 00096 // routine is used when we report the information about the flag definition 00097 // location. For instance, if your build resides at some location you do not 00098 // want to expose in the usage output, you can trim it to show only relevant 00099 // part. 00100 // For example: 00101 // normalize_filename("/my_company/some_long_path/src/project/file.cc") 00102 // might produce 00103 // "project/file.cc". 00104 std::function<std::string (absl::string_view)> normalize_filename; 00105 }; 00106 00107 // SetFlagsUsageConfig() 00108 // 00109 // Sets the usage reporting configuration callbacks. If any of the callbacks are 00110 // not set in usage_config instance, then the default value of the callback is 00111 // used. 00112 void SetFlagsUsageConfig(FlagsUsageConfig usage_config); 00113 00114 namespace flags_internal { 00115 00116 FlagsUsageConfig GetUsageConfig(); 00117 00118 void ReportUsageError(absl::string_view msg, bool is_fatal); 00119 00120 } // namespace flags_internal 00121 } // namespace absl 00122 00123 extern "C" { 00124 00125 // Additional report of fatal usage error message before we std::exit. Error is 00126 // fatal if is_fatal argument to ReportUsageError is true. 00127 void AbslInternalReportFatalUsageError(absl::string_view); 00128 00129 } // extern "C" 00130 00131 #endif // ABSL_FLAGS_USAGE_CONFIG_H_