This is an automated email from the ASF dual-hosted git repository.

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 60bcc3fa Print version as kvrocks in kvrocks2redis (#1649)
60bcc3fa is described below

commit 60bcc3fac32d0df45e9a06ca0616d9d8d36fa579
Author: Twice <[email protected]>
AuthorDate: Mon Aug 7 20:57:13 2023 +0800

    Print version as kvrocks in kvrocks2redis (#1649)
---
 src/main.cc                 |  6 +++---
 utils/kvrocks2redis/main.cc | 37 ++++++++++++++++++++++++++-----------
 2 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/src/main.cc b/src/main.cc
index 7260036d..fc3b4611 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -183,7 +183,7 @@ static void InitGoogleLog(const Config *config) {
   FLAGS_max_log_size = 100;
   FLAGS_logbufsecs = 0;
 
-  if (util::ToLower(config->log_dir) == "stdout") {
+  if (util::EqualICase(config->log_dir, "stdout")) {
     for (int level = google::INFO; level <= google::FATAL; level++) {
       google::SetLogDestination(level, "");
     }
@@ -218,7 +218,7 @@ bool SupervisedSystemd() {
 
   auto fd = UniqueFD(socket(AF_UNIX, SOCK_DGRAM, 0));
   if (!fd) {
-    LOG(WARNING) << "Can't connect to systemd socket " << notify_socket;
+    LOG(WARNING) << "Cannot connect to systemd socket " << notify_socket;
     return false;
   }
 
@@ -248,7 +248,7 @@ bool SupervisedSystemd() {
   sendto_flags |= MSG_NOSIGNAL;
 #endif
   if (sendmsg(*fd, &hdr, sendto_flags) < 0) {
-    LOG(WARNING) << "Can't send notification to systemd";
+    LOG(WARNING) << "Cannot send notification to systemd";
     return false;
   }
   return true;
diff --git a/utils/kvrocks2redis/main.cc b/utils/kvrocks2redis/main.cc
index 1bd1c33b..9e93df6f 100644
--- a/utils/kvrocks2redis/main.cc
+++ b/utils/kvrocks2redis/main.cc
@@ -41,33 +41,49 @@ std::function<void()> hup_handler;
 
 struct Options {
   std::string conf_file = kDefaultConfPath;
-  bool show_usage = false;
 };
 
+std::ostream &PrintVersion(std::ostream &os) {
+  os << "kvrocks2redis ";
+
+  if (VERSION != "unstable") {
+    os << "version ";
+  }
+
+  os << VERSION;
+
+  if (!GIT_COMMIT.empty()) {
+    os << " (commit " << GIT_COMMIT << ")";
+  }
+
+  return os;
+}
+
 extern "C" void SignalHandler(int sig) {
   if (hup_handler) hup_handler();
 }
 
 static void Usage(const char *program) {
   std::cout << program << " sync kvrocks to redis\n"
-            << "\t-c config file, default is " << kDefaultConfPath << "\n"
-            << "\t-h help\n";
+            << "\t-c <path> specifies the config file, defaulting to " << 
kDefaultConfPath << "\n"
+            << "\t-h print this help message\n"
+            << "\t-v print version information\n";
   exit(0);
 }
 
 static Options ParseCommandLineOptions(int argc, char **argv) {
   int ch = 0;
   Options opts;
-  while ((ch = ::getopt(argc, argv, "c:h")) != -1) {
+  while ((ch = ::getopt(argc, argv, "c:hv")) != -1) {
     switch (ch) {
       case 'c': {
         opts.conf_file = optarg;
         break;
       }
-      case 'h': {
-        opts.show_usage = true;
-        break;
-      }
+      case 'v':
+        std::cout << PrintVersion << std::endl;
+        exit(0);
+      case 'h':
       default:
         Usage(argv[0]);
     }
@@ -130,9 +146,7 @@ int main(int argc, char *argv[]) {
   signal(SIGINT, SignalHandler);
   signal(SIGTERM, SignalHandler);
 
-  std::cout << "Version: " << VERSION << " @" << GIT_COMMIT << std::endl;
   auto opts = ParseCommandLineOptions(argc, argv);
-  if (opts.show_usage) Usage(argv[0]);
   std::string config_file_path = std::move(opts.conf_file);
 
   kvrocks2redis::Config config;
@@ -143,6 +157,7 @@ int main(int argc, char *argv[]) {
   }
 
   InitGoogleLog(&config);
+  LOG(INFO) << PrintVersion;
 
   if (config.daemonize) Daemonize();
 
@@ -168,7 +183,7 @@ int main(int argc, char *argv[]) {
   Parser parser(&storage, &writer);
 
   Sync sync(&storage, &writer, &parser, &config);
-  hup_handler = [&sync]() {
+  hup_handler = [&sync] {
     if (!sync.IsStopped()) {
       LOG(INFO) << "Bye Bye";
       sync.Stop();

Reply via email to