Skip to content

Commit 8ea98b6

Browse files
committed
Let FromGlobalGflags take an explicit default.
New features and the code paths enabling them are often gated behind flags; initially, the defaults have these code paths disabled, i.e., the flags are off by default. That default value is statically defined in the flag's definition and FromGlobalGflags uses that static default. In order to change this when ramping up exposure to the new feature, we need to override this. Here, we add a new version of FromGlobalGflags that lets a default be explicitly specified, and change BoolFromGlobalGflags (only) to match.
1 parent dab33c7 commit 8ea98b6

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

base/cvd/cuttlefish/host/commands/assemble_cvd/flags/from_gflags.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ Result<std::string> ParseString(const std::string& value, const std::string&) {
3939
template <typename T>
4040
Result<std::vector<T>> FromGlobalGflags(
4141
const gflags::CommandLineFlagInfo& flag_info, const std::string& flag_name,
42+
T default_value,
4243
std::function<Result<T>(const std::string& value, const std::string& name)>
4344
parse_func) {
44-
T default_value = CF_EXPECT(parse_func(flag_info.default_value, flag_name));
45-
4645
std::vector<std::string> string_values =
4746
android::base::Split(flag_info.current_value, ",");
4847
std::vector<T> values(string_values.size());
@@ -57,6 +56,16 @@ Result<std::vector<T>> FromGlobalGflags(
5756
return std::move(values);
5857
}
5958

59+
template <typename T>
60+
Result<std::vector<T>> FromGlobalGflags(
61+
const gflags::CommandLineFlagInfo& flag_info, const std::string& flag_name,
62+
std::function<Result<T>(const std::string& value, const std::string& name)>
63+
parse_func) {
64+
T default_value = CF_EXPECT(parse_func(flag_info.default_value, flag_name));
65+
return std::move(FromGlobalGflags<T>(
66+
flag_info, flag_name, default_value, parse_func));
67+
}
68+
6069
} // namespace
6170

6271
Result<std::vector<bool>> BoolFromGlobalGflags(
@@ -65,6 +74,13 @@ Result<std::vector<bool>> BoolFromGlobalGflags(
6574
return CF_EXPECT(FromGlobalGflags<bool>(flag_info, flag_name, ParseBool));
6675
}
6776

77+
Result<std::vector<bool>> BoolFromGlobalGflags(
78+
const gflags::CommandLineFlagInfo& flag_info,
79+
const std::string& flag_name, bool default_value) {
80+
return CF_EXPECT(FromGlobalGflags<bool>(
81+
flag_info, flag_name, default_value, ParseBool));
82+
}
83+
6884
Result<std::vector<int>> IntFromGlobalGflags(
6985
const gflags::CommandLineFlagInfo& flag_info,
7086
const std::string& flag_name) {

base/cvd/cuttlefish/host/commands/assemble_cvd/flags/from_gflags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ namespace cuttlefish {
2727

2828
Result<std::vector<bool>> BoolFromGlobalGflags(
2929
const gflags::CommandLineFlagInfo& flag_info, const std::string& flag_name);
30+
Result<std::vector<bool>> BoolFromGlobalGflags(
31+
const gflags::CommandLineFlagInfo& flag_info, const std::string& flag_name, bool default_value);
3032
Result<std::vector<int>> IntFromGlobalGflags(
3133
const gflags::CommandLineFlagInfo& flag_info, const std::string& flag_name);
3234
Result<std::vector<std::string>> StringFromGlobalGflags(

0 commit comments

Comments
 (0)