zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eolive...@apache.org
Subject [zookeeper] branch master updated: ZOOKEEPER-1425: add version command to the zookeeper client shell
Date Mon, 20 May 2019 20:55:05 GMT
This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new af59be2  ZOOKEEPER-1425: add version command to the zookeeper client shell
af59be2 is described below

commit af59be25c564d34c6620cd931cd84ef5200aa1b3
Author: maoling <maoling199210191@sina.com>
AuthorDate: Mon May 20 22:54:43 2019 +0200

    ZOOKEEPER-1425: add version command to the zookeeper client shell
    
    Original review history was included in [PR-913](https://github.com/apache/zookeeper/pull/913)
    more details in [ZOOKEEPER-1425](https://issues.apache.org/jira/browse/ZOOKEEPER-1425)
    
    Author: maoling <maoling199210191@sina.com>
    
    Reviewers: Enrico Olivelli <eolivelli@apache.org>, Andor Molnar <andor@apache.org>
    
    Closes #930 from maoling/ZOOKEEPER-1425
---
 .../java/org/apache/zookeeper/ZooKeeperMain.java   |  2 +
 .../org/apache/zookeeper/cli/VersionCommand.java   | 61 ++++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java b/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java
index 3261f39..ce575b1 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java
@@ -40,6 +40,7 @@ import org.apache.zookeeper.cli.CommandNotFoundException;
 import org.apache.zookeeper.cli.GetAllChildrenNumberCommand;
 import org.apache.zookeeper.cli.GetEphemeralsCommand;
 import org.apache.zookeeper.cli.MalformedCommandException;
+import org.apache.zookeeper.cli.VersionCommand;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.zookeeper.ZooDefs.Ids;
@@ -126,6 +127,7 @@ public class ZooKeeperMain {
         new RemoveWatchesCommand().addToMap(commandMapCli);
         new GetEphemeralsCommand().addToMap(commandMapCli);
         new GetAllChildrenNumberCommand().addToMap(commandMapCli);
+        new VersionCommand().addToMap(commandMapCli);
 
         // add all to commandMap
         for (Entry<String, CliCommand> entry : commandMapCli.entrySet()) {
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/cli/VersionCommand.java b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/VersionCommand.java
new file mode 100644
index 0000000..25e2e58
--- /dev/null
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/VersionCommand.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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.
+ */
+package org.apache.zookeeper.cli;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.Parser;
+import org.apache.commons.cli.PosixParser;
+import org.apache.zookeeper.Version;
+
+/**
+ * version command for cli
+ */
+public class VersionCommand extends CliCommand {
+
+    private static Options options = new Options();
+    private String[] args;
+
+    public VersionCommand() {
+        super("version", "");
+    }
+
+    @Override
+    public CliCommand parse(String[] cmdArgs) throws CliParseException {
+        Parser parser = new PosixParser();
+        CommandLine cl;
+        try {
+            cl = parser.parse(options, cmdArgs);
+        } catch (ParseException ex) {
+            throw new CliParseException(ex);
+        }
+        args = cl.getArgs();
+        if (args.length > 1) {
+            throw new CliParseException(getUsageStr());
+        }
+
+        return this;
+    }
+
+    @Override
+    public boolean exec() throws CliException {
+        out.println("ZooKeeper CLI version: " + Version.getFullVersion());
+
+        return false;
+    }
+}


Mime
View raw message