Updated Branches: refs/heads/sqoop2 f55b13203 -> 4cefb88d1
SQOOP-750 Introduce show option client command (Jarek Jarcec Cecho) Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/4cefb88d Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/4cefb88d Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/4cefb88d Branch: refs/heads/sqoop2 Commit: 4cefb88d14e6c12d555ef8f1eaa718b69a4989b6 Parents: f55b132 Author: Bilung Lee <[email protected]> Authored: Fri Dec 28 12:45:17 2012 -0800 Committer: Bilung Lee <[email protected]> Committed: Fri Dec 28 12:45:17 2012 -0800 ---------------------------------------------------------------------- .../org/apache/sqoop/client/shell/ShowCommand.java | 8 +- .../sqoop/client/shell/ShowOptionFunction.java | 89 +++++++++++++++ 2 files changed, 96 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sqoop/blob/4cefb88d/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java index 359add9..efbb8f2 100644 --- a/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java +++ b/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java @@ -34,13 +34,14 @@ public class ShowCommand extends SqoopCommand private ShowJobFunction jobFunction; private ShowFrameworkFunction frameworkFunction; private ShowConnectionFunction connectionFunction; + private ShowOptionFunction optionFunction; protected ShowCommand(Shell shell) { super(shell, Constants.CMD_SHOW, Constants.CMD_SHOW_SC, new String[] {Constants.FN_SERVER, Constants.FN_VERSION, Constants.FN_CONNECTOR, Constants.FN_FRAMEWORK, - Constants.FN_CONNECTION, Constants.FN_JOB }, + Constants.FN_CONNECTION, Constants.FN_JOB, Constants.FN_OPTION }, Constants.PRE_SHOW, Constants.SUF_INFO); } @@ -91,6 +92,11 @@ public class ShowCommand extends SqoopCommand jobFunction = new ShowJobFunction(io); } return jobFunction.execute(args); + } else if (func.equals(Constants.FN_OPTION)) { + if (optionFunction == null) { + optionFunction = new ShowOptionFunction(io); + } + return optionFunction.execute(args); } else { throw new SqoopException(ClientError.CLIENT_0002, usageMsg); } http://git-wip-us.apache.org/repos/asf/sqoop/blob/4cefb88d/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java new file mode 100644 index 0000000..d8af0b2 --- /dev/null +++ b/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java @@ -0,0 +1,89 @@ +/** + * 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.sqoop.client.shell; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.OptionBuilder; +import org.apache.sqoop.client.core.Constants; +import org.apache.sqoop.client.core.Environment; +import org.codehaus.groovy.tools.shell.IO; + +import java.util.List; + +/** + * Show client internal options + */ +public class ShowOptionFunction extends SqoopFunction { + + private IO io; + + /** + * Construct new object. + * + * @param io Shell's associated IO object + */ + @SuppressWarnings("static-access") + protected ShowOptionFunction(IO io) { + this.io = io; + + this.addOption(OptionBuilder + .hasArg().withArgName(Constants.OPT_NAME) + .withDescription(getResource().getString(Constants.RES_SET_PROMPT_OPT_NAME)) + .withLongOpt(Constants.OPT_NAME) + .create(Constants.OPT_NAME_CHAR)); + } + + /** + * Execute this function from parsed command line. + * + * @param args Arguments passed to this function. + * @return Null + */ + public Object execute(List<String> args) { + if (args.size() == 1) { + printAllOptions(); + return null; + } + + CommandLine line = parseOptions(this, 1, args); + if (line.hasOption(Constants.OPT_NAME)) { + String optionName = line.getOptionValue(Constants.OPT_NAME); + + if(optionName.equals(Constants.OPT_VERBOSE)) { + printVerbose(); + } + } + + return null; + } + + /** + * Print all known client options. + */ + private void printAllOptions() { + printVerbose(); + } + + /** + * Print verbose option. + */ + private void printVerbose() { + io.out.print("Verbose = "); + io.out.println(Environment.isVerboose()); + } +}
