From 725952d8b861c1d17069505de38be1e3524d4502 Mon Sep 17 00:00:00 2001 From: Taku Kudo Date: Mon, 26 Feb 2024 13:01:58 +0000 Subject: [PATCH] makes the return value of --help same as official abseil library --- src/init.h | 2 ++ third_party/absl/flags/flag.cc | 2 +- third_party/absl/flags/usage.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 third_party/absl/flags/usage.h diff --git a/src/init.h b/src/init.h index 6ae047e..5d1c487 100644 --- a/src/init.h +++ b/src/init.h @@ -18,6 +18,7 @@ #include "common.h" #include "third_party/absl/flags/flag.h" #include "third_party/absl/flags/parse.h" +#include "third_party/absl/flags/usage.h" #ifdef _USE_EXTERNAL_PROTOBUF #include "google/protobuf/message_lite.h" @@ -30,6 +31,7 @@ ABSL_DECLARE_FLAG(int32, minloglevel); namespace sentencepiece { inline void ParseCommandLineFlags(const char *usage, int *argc, char ***argv, bool remove_arg = true) { + absl::SetProgramUsageMessage(*argv[0]); const auto unused_args = absl::ParseCommandLine(*argc, *argv); if (remove_arg) { diff --git a/third_party/absl/flags/flag.cc b/third_party/absl/flags/flag.cc index 5d6642a..6b85400 100644 --- a/third_party/absl/flags/flag.cc +++ b/third_party/absl/flags/flag.cc @@ -211,7 +211,7 @@ std::vector ParseCommandLine(int argc, char *argv[]) { if (absl::GetFlag(FLAGS_help)) { std::cout << internal::PrintHelp(argv[0]); - sentencepiece::error::Exit(0); + sentencepiece::error::Exit(1); } else if (absl::GetFlag(FLAGS_version)) { std::cout << PACKAGE_STRING << " " << VERSION << std::endl; sentencepiece::error::Exit(0); diff --git a/third_party/absl/flags/usage.h b/third_party/absl/flags/usage.h new file mode 100644 index 0000000..a2e5260 --- /dev/null +++ b/third_party/absl/flags/usage.h @@ -0,0 +1,28 @@ +// Copyright 2016 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License.! + +#ifndef ABSL_FLAGS_USAGE_H_ +#define ABSL_FLAGS_USAGE_H_ + +#include + +#include "third_party/absl/strings/string_view.h" + +namespace absl { + +inline void SetProgramUsageMessage(absl::string_view new_usage_message) {} + +} // namespace absl + +#endif // ABSL_FLAGS_USAGE_H_