Commit 1bd60dca by Gennadiy Rozental Committed by Copybara-Service

Add a call to handle usage flags in case of unrecognized flags

PiperOrigin-RevId: 519090305
Change-Id: Ic97a36da33e1e0681765a913f3c54c3d818eebdc
parent b6de7b80
......@@ -706,7 +706,10 @@ std::vector<char*> ParseCommandLineImpl(int argc, char* argv[],
(undef_flag_action == OnUndefinedFlag::kAbortIfUndefined));
if (undef_flag_action == OnUndefinedFlag::kAbortIfUndefined) {
if (!unrecognized_flags.empty()) { std::exit(1); }
if (!unrecognized_flags.empty()) {
flags_internal::HandleUsageFlags(std::cerr, ProgramUsageMessage());
std::exit(1);
}
}
}
......@@ -891,7 +894,7 @@ HelpMode ParseAbseilFlagsOnlyImpl(
flags_internal::ReportUsageError(
"NOTE: command line flags are disabled in this build", true);
#else
flags_internal::HandleUsageFlags(std::cout, ProgramUsageMessage());
flags_internal::HandleUsageFlags(std::cerr, ProgramUsageMessage());
#endif
return HelpMode::kFull; // We just need to make sure the exit with
// code 1.
......
......@@ -17,10 +17,8 @@
#include <stdlib.h>
#include <cstddef>
#include <fstream>
#include <string>
#include <utility>
#include <vector>
#include "gmock/gmock.h"
......@@ -1061,4 +1059,17 @@ TEST_F(ParseTest, AllUndefOkFlagsAreIgnored) {
// --------------------------------------------------------------------
TEST_F(ParseDeathTest, ExitOnUnrecognizedFlagPrintsHelp) {
const char* in_args[] = {
"testbin",
"--undef_flag1",
"--help=int_flag",
};
EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args),
"Try --helpfull to get a list of all flags");
}
// --------------------------------------------------------------------
} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment