summaryrefslogtreecommitdiff
path: root/absl/flags
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2019-10-16 15:51:11 -0700
committerGravatar Andy Soffer <asoffer@google.com>2019-10-17 14:43:24 -0400
commita15364ce4d88534ae2295127e5d8e32aefb6b446 (patch)
treec01afa5f859f563b7bfd8cfdafa6b6fd1fed3aa6 /absl/flags
parentab3552a18964e7063c8324f45b3896a6a20b08a8 (diff)
Export of internal Abseil changes
-- d35c72d705155dcd89a92835103540f14c643d10 by Gennadiy Rozental <rogeeff@google.com>: helpxml changed to report types of flags with built-in value type. PiperOrigin-RevId: 275131440 -- f3478792943d7dd40a6ef6083a8e5d374f43a65e by Abseil Team <absl-team@google.com>: Add space padding tests for hex conversions. PiperOrigin-RevId: 275120155 -- 7c2e4725403e173660f33f94af686a75d3722936 by Andy Soffer <asoffer@google.com>: Fix https://github.com/abseil/abseil-cpp/issues/379 by renaming `roundup` to `round_up` PiperOrigin-RevId: 275106110 -- 84cb30d6ee509961ac4359cfdda1360973b9527d by Laramie Leavitt <lar@google.com>: Move random_internal::wide_multiply into a file by the same name. PiperOrigin-RevId: 275059359 -- 06d691a8c187b5d899e7863784b23bdcfd580cb2 by Abseil Team <absl-team@google.com>: Add missing "return" keyword. PiperOrigin-RevId: 275036408 GitOrigin-RevId: d35c72d705155dcd89a92835103540f14c643d10 Change-Id: Id837b4de6c9cfe18f0a088363754bfe389df985b
Diffstat (limited to 'absl/flags')
-rw-r--r--absl/flags/flag.h2
-rw-r--r--absl/flags/internal/usage.cc26
2 files changed, 26 insertions, 2 deletions
diff --git a/absl/flags/flag.h b/absl/flags/flag.h
index 4927757b..85900ef8 100644
--- a/absl/flags/flag.h
+++ b/absl/flags/flag.h
@@ -121,7 +121,7 @@ class Flag {
bool IsModified() const { return GetImpl()->IsModified(); }
void SetModified(bool is_modified) { GetImpl()->SetModified(is_modified); }
bool IsSpecifiedOnCommandLine() const {
- GetImpl()->IsSpecifiedOnCommandLine();
+ return GetImpl()->IsSpecifiedOnCommandLine();
}
absl::string_view Typename() const { return GetImpl()->Typename(); }
std::string Filename() const { return GetImpl()->Filename(); }
diff --git a/absl/flags/internal/usage.cc b/absl/flags/internal/usage.cc
index 03048514..181c35c6 100644
--- a/absl/flags/internal/usage.cc
+++ b/absl/flags/internal/usage.cc
@@ -47,6 +47,27 @@ namespace absl {
namespace flags_internal {
namespace {
+absl::string_view TypenameForHelp(const flags_internal::CommandLineFlag& flag) {
+ // Only report names of v1 built-in types
+#define HANDLE_V1_BUILTIN_TYPE(t) \
+ if (flag.IsOfType<t>()) { \
+ return #t; \
+ }
+
+ HANDLE_V1_BUILTIN_TYPE(bool);
+ HANDLE_V1_BUILTIN_TYPE(int32_t);
+ HANDLE_V1_BUILTIN_TYPE(int64_t);
+ HANDLE_V1_BUILTIN_TYPE(uint64_t);
+ HANDLE_V1_BUILTIN_TYPE(double);
+#undef HANDLE_V1_BUILTIN_TYPE
+
+ if (flag.IsOfType<std::string>()) {
+ return "string";
+ }
+
+ return "";
+}
+
// This class is used to emit an XML element with `tag` and `text`.
// It adds opening and closing tags and escapes special characters in the text.
// For example:
@@ -186,7 +207,7 @@ void FlagHelpHumanReadable(const flags_internal::CommandLineFlag& flag,
// Flag data type (for V1 flags only).
if (!flag.IsAbseilFlag() && !flag.IsRetired()) {
- printer.Write(absl::StrCat("type: ", flag.Typename(), ";"));
+ printer.Write(absl::StrCat("type: ", TypenameForHelp(flag), ";"));
}
// The listed default value will be the actual default from the flag
@@ -223,6 +244,9 @@ void FlagsHelpImpl(std::ostream& out, flags_internal::FlagKindFilter filter_cb,
} else {
// XML schema is not a part of our public API for now.
out << "<?xml version=\"1.0\"?>\n"
+ << "<!-- This output should be used with care. We do not report type "
+ "names for flags with user defined types -->\n"
+ << "<!-- Prefer flag only_check_args for validating flag inputs -->\n"
// The document.
<< "<AllFlags>\n"
// The program name and usage.