makes the return value of --help same as official abseil library

This commit is contained in:
Taku Kudo 2024-02-26 13:01:58 +00:00
parent 52a7f156a4
commit 725952d8b8
3 changed files with 31 additions and 1 deletions

View File

@ -18,6 +18,7 @@
#include "common.h" #include "common.h"
#include "third_party/absl/flags/flag.h" #include "third_party/absl/flags/flag.h"
#include "third_party/absl/flags/parse.h" #include "third_party/absl/flags/parse.h"
#include "third_party/absl/flags/usage.h"
#ifdef _USE_EXTERNAL_PROTOBUF #ifdef _USE_EXTERNAL_PROTOBUF
#include "google/protobuf/message_lite.h" #include "google/protobuf/message_lite.h"
@ -30,6 +31,7 @@ ABSL_DECLARE_FLAG(int32, minloglevel);
namespace sentencepiece { namespace sentencepiece {
inline void ParseCommandLineFlags(const char *usage, int *argc, char ***argv, inline void ParseCommandLineFlags(const char *usage, int *argc, char ***argv,
bool remove_arg = true) { bool remove_arg = true) {
absl::SetProgramUsageMessage(*argv[0]);
const auto unused_args = absl::ParseCommandLine(*argc, *argv); const auto unused_args = absl::ParseCommandLine(*argc, *argv);
if (remove_arg) { if (remove_arg) {

View File

@ -211,7 +211,7 @@ std::vector<char *> ParseCommandLine(int argc, char *argv[]) {
if (absl::GetFlag(FLAGS_help)) { if (absl::GetFlag(FLAGS_help)) {
std::cout << internal::PrintHelp(argv[0]); std::cout << internal::PrintHelp(argv[0]);
sentencepiece::error::Exit(0); sentencepiece::error::Exit(1);
} else if (absl::GetFlag(FLAGS_version)) { } else if (absl::GetFlag(FLAGS_version)) {
std::cout << PACKAGE_STRING << " " << VERSION << std::endl; std::cout << PACKAGE_STRING << " " << VERSION << std::endl;
sentencepiece::error::Exit(0); sentencepiece::error::Exit(0);

28
third_party/absl/flags/usage.h vendored Normal file
View File

@ -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 <vector>
#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_