summaryrefslogtreecommitdiff
path: root/absl/flags
diff options
context:
space:
mode:
authorGravatar Gennadiy Rozental <rogeeff@google.com>2023-02-27 12:18:10 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-02-27 12:19:03 -0800
commit0c1114c4fb83c844c7fd74708338cca1d3d9b0dc (patch)
tree70a30ff3e3860943201f2cf7f034509bddcde8fe /absl/flags
parent2d2801a315282e868d0695541d21f068cec22407 (diff)
Eliminate internal ArgvListAction enum.
PiperOrigin-RevId: 512697257 Change-Id: I828ac7a4ada482d60beba767ef9da6e2c0077c33
Diffstat (limited to 'absl/flags')
-rw-r--r--absl/flags/internal/parse.h8
-rw-r--r--absl/flags/parse.cc15
-rw-r--r--absl/flags/parse_test.cc67
3 files changed, 12 insertions, 78 deletions
diff --git a/absl/flags/internal/parse.h b/absl/flags/internal/parse.h
index 0a7012fc..b8c693c4 100644
--- a/absl/flags/internal/parse.h
+++ b/absl/flags/internal/parse.h
@@ -41,10 +41,16 @@ enum class OnUndefinedFlag {
};
std::vector<char*> ParseCommandLineImpl(int argc, char* argv[],
- ArgvListAction arg_list_act,
UsageFlagsAction usage_flag_act,
OnUndefinedFlag on_undef_flag);
+// To be removed
+inline std::vector<char*> ParseCommandLineImpl(
+ int argc, char* argv[], ArgvListAction /* arg_list_act */,
+ UsageFlagsAction usage_flag_act, OnUndefinedFlag on_undef_flag) {
+ return ParseCommandLineImpl(argc, argv, usage_flag_act, on_undef_flag);
+}
+
// --------------------------------------------------------------------
// Inspect original command line
diff --git a/absl/flags/parse.cc b/absl/flags/parse.cc
index 368248e3..768652d8 100644
--- a/absl/flags/parse.cc
+++ b/absl/flags/parse.cc
@@ -664,7 +664,6 @@ std::vector<std::string> GetMisspellingHints(const absl::string_view flag) {
// --------------------------------------------------------------------
std::vector<char*> ParseCommandLineImpl(int argc, char* argv[],
- ArgvListAction arg_list_act,
UsageFlagsAction usage_flag_act,
OnUndefinedFlag on_undef_flag) {
ABSL_INTERNAL_CHECK(argc > 0, "Missing argv[0]");
@@ -740,10 +739,6 @@ std::vector<char*> ParseCommandLineImpl(int argc, char* argv[],
continue;
}
- if (arg_from_argv && (arg_list_act == ArgvListAction::kKeepParsedArgs)) {
- output_args.push_back(argv[curr_list.FrontIndex()]);
- }
-
// 60. Split the current argument on '=' to figure out the argument
// name and value. If flag name is empty it means we've got "--". value
// can be empty either if there were no '=' in argument string at all or
@@ -784,18 +779,11 @@ std::vector<char*> ParseCommandLineImpl(int argc, char* argv[],
}
// 90. Deduce flag's value (from this or next argument)
- auto curr_index = curr_list.FrontIndex();
bool value_success = true;
std::tie(value_success, value) =
DeduceFlagValue(*flag, value, is_negative, is_empty_value, &curr_list);
success &= value_success;
- // If above call consumed an argument, it was a standalone value
- if (arg_from_argv && (arg_list_act == ArgvListAction::kKeepParsedArgs) &&
- (curr_index != curr_list.FrontIndex())) {
- output_args.push_back(argv[curr_list.FrontIndex()]);
- }
-
// 100. Set the located flag to a new new value, unless it is retired.
// Setting retired flag fails, but we ignoring it here while also reporting
// access to retired flag.
@@ -881,8 +869,7 @@ std::vector<char*> ParseCommandLineImpl(int argc, char* argv[],
std::vector<char*> ParseCommandLine(int argc, char* argv[]) {
return flags_internal::ParseCommandLineImpl(
- argc, argv, flags_internal::ArgvListAction::kRemoveParsedArgs,
- flags_internal::UsageFlagsAction::kHandleUsage,
+ argc, argv, flags_internal::UsageFlagsAction::kHandleUsage,
flags_internal::OnUndefinedFlag::kAbortIfUndefined);
}
diff --git a/absl/flags/parse_test.cc b/absl/flags/parse_test.cc
index 418b0e55..18a01377 100644
--- a/absl/flags/parse_test.cc
+++ b/absl/flags/parse_test.cc
@@ -854,41 +854,6 @@ TEST_F(ParseTest, TestReadingFlagsFromEnvMoxedWithRegularFlags) {
// --------------------------------------------------------------------
-TEST_F(ParseTest, TestKeepParsedArgs) {
- const char* in_args1[] = {
- "testbin", "arg1", "--bool_flag",
- "--int_flag=211", "arg2", "--double_flag=1.1",
- "--string_flag", "asd", "--",
- "arg3", "arg4",
- };
-
- auto out_args1 = InvokeParse(in_args1);
-
- EXPECT_THAT(
- out_args1,
- ElementsAreArray({absl::string_view("testbin"), absl::string_view("arg1"),
- absl::string_view("arg2"), absl::string_view("arg3"),
- absl::string_view("arg4")}));
-
- auto out_args2 = flags::ParseCommandLineImpl(
- 11, const_cast<char**>(in_args1), flags::ArgvListAction::kKeepParsedArgs,
- flags::UsageFlagsAction::kHandleUsage,
- flags::OnUndefinedFlag::kAbortIfUndefined);
-
- EXPECT_THAT(
- out_args2,
- ElementsAreArray({absl::string_view("testbin"),
- absl::string_view("--bool_flag"),
- absl::string_view("--int_flag=211"),
- absl::string_view("--double_flag=1.1"),
- absl::string_view("--string_flag"),
- absl::string_view("asd"), absl::string_view("--"),
- absl::string_view("arg1"), absl::string_view("arg2"),
- absl::string_view("arg3"), absl::string_view("arg4")}));
-}
-
-// --------------------------------------------------------------------
-
TEST_F(ParseTest, TestIgnoreUndefinedFlags) {
const char* in_args1[] = {
"testbin",
@@ -898,34 +863,13 @@ TEST_F(ParseTest, TestIgnoreUndefinedFlags) {
};
auto out_args1 = flags::ParseCommandLineImpl(
- 4, const_cast<char**>(in_args1), flags::ArgvListAction::kRemoveParsedArgs,
- flags::UsageFlagsAction::kHandleUsage,
+ 4, const_cast<char**>(in_args1), flags::UsageFlagsAction::kHandleUsage,
flags::OnUndefinedFlag::kIgnoreUndefined);
EXPECT_THAT(out_args1, ElementsAreArray({absl::string_view("testbin"),
absl::string_view("arg1")}));
EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 21);
-
- const char* in_args2[] = {
- "testbin",
- "arg1",
- "--undef_flag=aa",
- "--string_flag=AA",
- };
-
- auto out_args2 = flags::ParseCommandLineImpl(
- 4, const_cast<char**>(in_args2), flags::ArgvListAction::kKeepParsedArgs,
- flags::UsageFlagsAction::kHandleUsage,
- flags::OnUndefinedFlag::kIgnoreUndefined);
-
- EXPECT_THAT(
- out_args2,
- ElementsAreArray(
- {absl::string_view("testbin"), absl::string_view("--undef_flag=aa"),
- absl::string_view("--string_flag=AA"), absl::string_view("arg1")}));
-
- EXPECT_EQ(absl::GetFlag(FLAGS_string_flag), "AA");
}
// --------------------------------------------------------------------
@@ -945,8 +889,7 @@ TEST_F(ParseDeathTest, TestSimpleHelpFlagHandling) {
};
auto out_args2 = flags::ParseCommandLineImpl(
- 3, const_cast<char**>(in_args2), flags::ArgvListAction::kRemoveParsedArgs,
- flags::UsageFlagsAction::kIgnoreUsage,
+ 3, const_cast<char**>(in_args2), flags::UsageFlagsAction::kIgnoreUsage,
flags::OnUndefinedFlag::kAbortIfUndefined);
EXPECT_EQ(flags::GetFlagsHelpMode(), flags::HelpMode::kImportant);
@@ -962,8 +905,7 @@ TEST_F(ParseDeathTest, TestSubstringHelpFlagHandling) {
};
auto out_args1 = flags::ParseCommandLineImpl(
- 2, const_cast<char**>(in_args1), flags::ArgvListAction::kRemoveParsedArgs,
- flags::UsageFlagsAction::kIgnoreUsage,
+ 2, const_cast<char**>(in_args1), flags::UsageFlagsAction::kIgnoreUsage,
flags::OnUndefinedFlag::kAbortIfUndefined);
EXPECT_EQ(flags::GetFlagsHelpMode(), flags::HelpMode::kMatch);
@@ -972,8 +914,7 @@ TEST_F(ParseDeathTest, TestSubstringHelpFlagHandling) {
const char* in_args2[] = {"testbin", "--help", "some_positional_arg"};
auto out_args2 = flags::ParseCommandLineImpl(
- 3, const_cast<char**>(in_args2), flags::ArgvListAction::kRemoveParsedArgs,
- flags::UsageFlagsAction::kIgnoreUsage,
+ 3, const_cast<char**>(in_args2), flags::UsageFlagsAction::kIgnoreUsage,
flags::OnUndefinedFlag::kAbortIfUndefined);
EXPECT_EQ(flags::GetFlagsHelpMode(), flags::HelpMode::kImportant);