31 "show help on important flags for this binary [tip: all flags can " 33 ABSL_FLAG(
bool, helpfull,
false,
"show help on all flags");
35 "show help on only the main module for this program");
37 "show help on all modules in the main package");
39 ABSL_FLAG(
bool, only_check_args,
false,
"exit after checking all flags");
41 "show help on the modules named by this flag value");
43 "show help on modules whose name contains the specified substr");
46 namespace flags_internal {
60 const XMLElement& xml_elem) {
61 out <<
"<" << xml_elem.tag_ <<
">";
63 for (
auto c : xml_elem.txt_) {
86 return out <<
"</" << xml_elem.tag_ <<
">";
97 class FlagHelpPrettyPrinter {
101 FlagHelpPrettyPrinter(
int max_line_len, std::ostream* out)
109 if (str.
empty())
return;
111 std::vector<absl::string_view> tokens;
116 tokens.push_back(str);
119 for (
auto token : tokens) {
162 void FlagHelpHumanReadable(
const flags_internal::CommandLineFlag& flag,
164 FlagHelpPrettyPrinter printer(80, out);
170 printer.Write(
absl::StrCat(
"(", flag.Help(),
");"),
true);
173 if (!flag.IsAbseilFlag() && !flag.IsRetired()) {
174 printer.Write(
absl::StrCat(
"type: ", flag.Typename(),
";"));
181 std::string dflt_val = flag.DefaultValue();
182 if (flag.IsOfType<std::string>()) {
185 printer.Write(
absl::StrCat(
"default: ", dflt_val,
";"));
188 std::string curr_val = flag.CurrentValue();
189 if (flag.IsOfType<std::string>()) {
192 printer.Write(
absl::StrCat(
"currently: ", curr_val,
";"));
210 out <<
"<?xml version=\"1.0\"?>\n" 224 std::map<std::string,
225 std::map<std::string,
226 std::vector<const flags_internal::CommandLineFlag*>>>
232 std::string flag_filename = flag->Filename();
235 if (flag->IsRetired())
return;
241 if (!filter_cb || !filter_cb(flag_filename))
return;
251 for (
const auto& package : matching_flags) {
253 out << package_separator;
254 package_separator =
"\n\n";
258 for (
const auto& flags_in_file : package.second) {
260 out << file_separator <<
" Flags from " << flags_in_file.first
262 file_separator =
"\n";
265 for (
const auto* flag : flags_in_file.second) {
272 if (filter_cb && matching_flags.empty()) {
273 out <<
" No modules matched: use -helpfull\n";
277 out <<
"</AllFlags>\n";
293 if (flags_internal::program_usage_message !=
nullptr) {
298 program_usage_message =
new std::string(new_usage_message);
308 return program_usage_message !=
nullptr 310 :
"Warning: SetProgramUsageMessage() never called";
318 flags_internal::FlagHelpHumanReadable(flag, &out);
328 flags_internal::FlagsHelpImpl(out, filter_cb, format);
336 flags_internal::FlagsHelpImpl(
360 flags_internal::FlagsHelpImpl(
363 out <<
"\nTry --helpfull to get a list of all flags.\n";
369 flags_internal::FlagsHelpImpl(
372 out <<
"\nTry --helpfull to get a list of all flags.\n";
void SetProgramUsageMessage(absl::string_view new_usage_message)
void FlagHelp(std::ostream &out, const flags_internal::CommandLineFlag &flag, HelpFormat format)
static constexpr size_type npos
absl::string_view Package(absl::string_view filename)
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
std::ostream & operator<<(std::ostream &os, absl::LogSeverity s)
void FlagsHelp(std::ostream &out, absl::string_view filter, HelpFormat format)
std::function< bool(absl::string_view)> FlagKindFilter
strings_internal::Splitter< typename strings_internal::SelectDelimiter< Delimiter >::type, AllowEmpty > StrSplit(strings_internal::ConvertibleToStringView text, Delimiter d)
#define ABSL_INTERNAL_LOG(severity, message)
ABSL_FLAG(bool, help, false, "show help on important flags for this binary [tip: all flags can " "have two dashes]")
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
int HandleUsageFlags(std::ostream &out)
const char kStrippedFlagHelp[]
FlagsUsageConfig GetUsageConfig()
absl::string_view ProgramUsageMessage()
constexpr bool empty() const noexcept
std::string ShortProgramInvocationName()
std::function< std::string()> version_string
static ABSL_CONST_INIT std::string *program_name GUARDED_BY(program_name_guard)
T GetFlag(const absl::Flag< T > &flag)
absl::Mutex * InitFlagIfNecessary(CommandLineFlag *flag) LOCK_RETURNED(flag -> locks->primary_mu)
void ForEachFlag(std::function< void(CommandLineFlag *)> visitor)