abseil-cpp/absl/flags/usage_config.h
Go to the documentation of this file.
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 // -----------------------------------------------------------------------------
17 // File: usage_config.h
18 // -----------------------------------------------------------------------------
19 //
20 // This file defines the main usage reporting configuration interfaces and
21 // documents Abseil's supported built-in usage flags. If these flags are found
22 // when parsing a command-line, Abseil will exit the program and display
23 // appropriate help messages.
24 #ifndef ABSL_FLAGS_USAGE_CONFIG_H_
25 #define ABSL_FLAGS_USAGE_CONFIG_H_
26 
27 #include <functional>
28 #include <string>
29 
30 #include "absl/base/config.h"
31 #include "absl/strings/string_view.h"
32 
33 // -----------------------------------------------------------------------------
34 // Built-in Usage Flags
35 // -----------------------------------------------------------------------------
36 //
37 // Abseil supports the following built-in usage flags. When passed, these flags
38 // exit the program and :
39 //
40 // * --help
41 // Shows help on important flags for this binary
42 // * --helpfull
43 // Shows help on all flags
44 // * --helpshort
45 // Shows help on only the main module for this program
46 // * --helppackage
47 // Shows help on all modules in the main package
48 // * --version
49 // Shows the version and build info for this binary and exits
50 // * --only_check_args
51 // Exits after checking all flags
52 // * --helpon
53 // Shows help on the modules named by this flag value
54 // * --helpmatch
55 // Shows help on modules whose name contains the specified substring
56 
57 namespace absl {
59 
60 namespace flags_internal {
62 } // namespace flags_internal
63 
64 // FlagsUsageConfig
65 //
66 // This structure contains the collection of callbacks for changing the behavior
67 // of the usage reporting routines in Abseil Flags.
69  // Returns true if flags defined in the given source code file should be
70  // reported with --helpshort flag. For example, if the file
71  // "path/to/my/code.cc" defines the flag "--my_flag", and
72  // contains_helpshort_flags("path/to/my/code.cc") returns true, invoking the
73  // program with --helpshort will include information about --my_flag in the
74  // program output.
76 
77  // Returns true if flags defined in the filename should be reported with
78  // --help flag. For example, if the file
79  // "path/to/my/code.cc" defines the flag "--my_flag", and
80  // contains_help_flags("path/to/my/code.cc") returns true, invoking the
81  // program with --help will include information about --my_flag in the
82  // program output.
84 
85  // Returns true if flags defined in the filename should be reported with
86  // --helppackage flag. For example, if the file
87  // "path/to/my/code.cc" defines the flag "--my_flag", and
88  // contains_helppackage_flags("path/to/my/code.cc") returns true, invoking the
89  // program with --helppackage will include information about --my_flag in the
90  // program output.
92 
93  // Generates string containing program version. This is the string reported
94  // when user specifies --version in a command line.
96 
97  // Normalizes the filename specific to the build system/filesystem used. This
98  // routine is used when we report the information about the flag definition
99  // location. For instance, if your build resides at some location you do not
100  // want to expose in the usage output, you can trim it to show only relevant
101  // part.
102  // For example:
103  // normalize_filename("/my_company/some_long_path/src/project/file.cc")
104  // might produce
105  // "project/file.cc".
107 };
108 
109 // SetFlagsUsageConfig()
110 //
111 // Sets the usage reporting configuration callbacks. If any of the callbacks are
112 // not set in usage_config instance, then the default value of the callback is
113 // used.
114 void SetFlagsUsageConfig(FlagsUsageConfig usage_config);
115 
116 namespace flags_internal {
117 
119 
120 void ReportUsageError(absl::string_view msg, bool is_fatal);
121 
122 } // namespace flags_internal
124 } // namespace absl
125 
126 extern "C" {
127 
128 // Additional report of fatal usage error message before we std::exit. Error is
129 // fatal if is_fatal argument to ReportUsageError is true.
132 
133 } // extern "C"
134 
135 #endif // ABSL_FLAGS_USAGE_CONFIG_H_
absl::FlagsUsageConfig::contains_help_flags
flags_internal::FlagKindFilter contains_help_flags
Definition: abseil-cpp/absl/flags/usage_config.h:83
absl::FlagsUsageConfig::contains_helppackage_flags
flags_internal::FlagKindFilter contains_helppackage_flags
Definition: abseil-cpp/absl/flags/usage_config.h:91
bool
bool
Definition: setup_once.h:312
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
absl::FlagsUsageConfig::normalize_filename
std::function< std::string(absl::string_view)> normalize_filename
Definition: abseil-cpp/absl/flags/usage_config.h:106
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
absl::flags_internal::FlagKindFilter
std::function< bool(absl::string_view)> FlagKindFilter
Definition: abseil-cpp/absl/flags/usage_config.h:61
absl::msg
const char * msg
Definition: abseil-cpp/absl/synchronization/mutex.cc:272
absl::FlagsUsageConfig::version_string
std::function< std::string()> version_string
Definition: abseil-cpp/absl/flags/usage_config.h:95
absl::SetFlagsUsageConfig
void SetFlagsUsageConfig(FlagsUsageConfig usage_config)
Definition: abseil-cpp/absl/flags/usage_config.cc:138
absl::flags_internal::ReportUsageError
void ReportUsageError(absl::string_view msg, bool is_fatal)
Definition: abseil-cpp/absl/flags/usage_config.cc:128
absl::FlagsUsageConfig
Definition: abseil-cpp/absl/flags/usage_config.h:68
ABSL_INTERNAL_C_SYMBOL
#define ABSL_INTERNAL_C_SYMBOL(x)
Definition: third_party/abseil-cpp/absl/base/config.h:172
AbslInternalReportFatalUsageError
void ABSL_INTERNAL_C_SYMBOL() AbslInternalReportFatalUsageError(absl::string_view)
Definition: abseil-cpp/absl/flags/usage_config.cc:38
string_view
absl::string_view string_view
Definition: attr.cc:22
absl::flags_internal::GetUsageConfig
FlagsUsageConfig GetUsageConfig()
Definition: abseil-cpp/absl/flags/usage_config.cc:113
absl::FlagsUsageConfig::contains_helpshort_flags
flags_internal::FlagKindFilter contains_helpshort_flags
Definition: abseil-cpp/absl/flags/usage_config.h:75
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:48