sijie commented on a change in pull request #1094: BP-27 (part 1): New 
BookKeeper CLI Skeleton
URL: https://github.com/apache/bookkeeper/pull/1094#discussion_r168464276
 
 

 ##########
 File path: 
bookkeeper-tools/src/main/java/org/apache/bookkeeper/tools/cli/BookKeeperCLI.java
 ##########
 @@ -0,0 +1,212 @@
+/*
+ * 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.bookkeeper.tools.cli;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.google.common.annotations.VisibleForTesting;
+import java.net.MalformedURLException;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.tools.cli.commands.CmdBase;
+import org.apache.bookkeeper.tools.cli.commands.CmdBookie;
+import org.apache.bookkeeper.tools.cli.commands.CmdClient;
+import org.apache.bookkeeper.tools.cli.commands.CmdCluster;
+import org.apache.bookkeeper.tools.cli.commands.CmdMetadata;
+import org.apache.commons.configuration.ConfigurationException;
+
+/**
+ * BookKeeper CLI.
+ */
+@Slf4j
+public class BookKeeperCLI {
+
+    /**
+     * Make this command map static. This provides a way to plugin different 
sub commands.
+     */
+    private static final Map<String, Class> commandMap;
+
+    static {
+        commandMap = new TreeMap<>();
+
+        // build the default command map
+        commandMap.put("bookie", CmdBookie.class);
+        commandMap.put("client", CmdClient.class);
+        commandMap.put("cluster", CmdCluster.class);
+        commandMap.put("metadata", CmdMetadata.class);
+    }
+
+    static JCommander newJCommander() {
+        return new JCommander();
+    }
+
+    @SuppressWarnings("unchecked")
+    @VisibleForTesting
+    public static Object newCommandInstance(Class cls, ServerConfiguration 
config) throws Exception {
+        return 
cls.getConstructor(ServerConfiguration.class).newInstance(config);
 
 Review comment:
   no particular reason for using reflection. was trying to defer object 
initialization when it is needed. any concern on using reflection?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to