Replace CmdLineParser and SubCommandHandler of arg4j as custom class.
Add HelpCLI dummy class.
Add some classes for supporting print usage info.
Change-Id: I80486e18a89d5869f5b511ac5dd36e63a4c56389
Signed-off-by: Heongseok Heo <hyeongseok.heo@samsung.com>
--- /dev/null
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.ncli.core;
+
+
+/**
+ * This class represent sub command information of Tizen New CLI.
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
+ *
+ *
+ */
+public class CommandInfo implements Comparable<CommandInfo>{
+ private final String parentCmd;
+ private final String commandName;
+ private String usage;
+ private boolean common;
+
+ public CommandInfo(final String parentCmd, final String name, final String usage, boolean common) {
+ this.parentCmd = parentCmd;
+ this.commandName = name;
+ this.usage = usage;
+ this.common = common;
+ }
+
+ /**
+ * @param rootCmdName
+ */
+ public CommandInfo(final String parentCmd, final String cmdName) {
+ this.parentCmd = parentCmd;
+ this.commandName = cmdName;
+ }
+
+ public String getUsage() {
+ return usage;
+ }
+
+ public void setUsage(String usage) {
+ this.usage = usage;
+ }
+
+ public boolean isCommon() {
+ return common;
+ }
+
+ public void setCommon(boolean common) {
+ this.common = common;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(CommandInfo o) {
+ if( null != o.parentCmd && o.parentCmd.equals(this.parentCmd) ) {
+ if ( o.commandName != null && o.commandName.equals(this.commandName)) {
+ return 0;
+ }
+ }
+ return 1;
+ }
+
+
+}
--- /dev/null
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.ncli.core;
+
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.util.List;
+import java.util.ResourceBundle;
+
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.OptionHandlerFilter;
+import org.kohsuke.args4j.spi.FieldSetter;
+import org.kohsuke.args4j.spi.OptionHandler;
+import org.kohsuke.args4j.spi.Setter;
+import org.kohsuke.args4j.spi.SubCommand;
+import org.kohsuke.args4j.spi.SubCommands;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
+ *
+ *
+ */
+public class CommandLineParser extends CmdLineParser {
+ private Logger log = LoggerFactory.getLogger(getClass());
+
+ public CommandLineParser(Object bean) {
+ super(bean);
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.kohsuke.args4j.CmdLineParser#printUsage(java.io.Writer, java.util.ResourceBundle, org.kohsuke.args4j.OptionHandlerFilter)
+ */
+ @Override
+ public void printUsage(Writer out, ResourceBundle rb, OptionHandlerFilter filter) {
+ super.printUsage(out, rb, filter);
+
+ }
+
+
+
+
+
+ /* (non-Javadoc)
+ * @see org.kohsuke.args4j.CmdLineParser#parseArgument(java.lang.String[])
+ */
+ @Override
+ public void parseArgument(String... args) throws CmdLineException {
+ try {
+ super.parseArgument(args);
+ }catch(CmdLineException e) {
+ log.trace("CmdLineException occurred.\n{}",e.getMessage());
+ throw e;
+ }finally {
+ //process parsing subcommand infos
+ log.trace("make sub command reference infos.");
+ makeSubcommandData();
+ }
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.kohsuke.args4j.CmdLineParser#printOption(java.io.PrintWriter, org.kohsuke.args4j.spi.OptionHandler, int, java.util.ResourceBundle, org.kohsuke.args4j.OptionHandlerFilter)
+ */
+ @Override
+ protected void printOption(PrintWriter out, OptionHandler handler, int len, ResourceBundle rb,
+ OptionHandlerFilter filter) {
+ super.printOption(out, handler, len, rb, filter);
+ log.trace("PrintOption:handler.setter {}",handler.setter);
+ }
+
+
+
+ public void makeSubcommandData() {
+ List<OptionHandler> arguments2 = getArguments();
+ if ( null != arguments2) {
+ OptionHandler optionHandler = arguments2.get(0);
+ if( optionHandler instanceof TizenSubCommandHandler) {
+ log.trace("{}",optionHandler);
+ TizenSubCommandHandler tizenSubCmdHandler = (TizenSubCommandHandler) optionHandler;
+ SubCommands subCommands = tizenSubCmdHandler.getSubcommand();
+ SubCommand[] subCommandArray = subCommands.value();
+ for (int i = 0; i < subCommandArray.length; i++) {
+ Object instantiate = tizenSubCmdHandler.instantiate(subCommandArray[i]);
+ TizenSubCommand annotation = instantiate.getClass().getAnnotation(TizenSubCommand.class);
+ log.trace("SubCommand:{}",subCommandArray[i].name());
+ if( null != annotation) {
+ String subCmdName = ( null == annotation.name())?subCommandArray[i].name():annotation.name();
+// SubCommandData.put(subCmdName,new CommandInfo(subCmdName,annotation.usage(),annotation.common()));
+ log.trace("SubCommandData:"+subCmdName+"\t{}\t{}", annotation.usage(), annotation.common());
+ }else {
+ log.trace("SubCommandData w/o annotation:{}",subCommandArray[i].name());
+// SubCommandData.put(subCommandArray[i].name(), null);
+ }
+
+ }
+
+ }
+ }
+ }
+
+
+
+}
--- /dev/null
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.ncli.core;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.kohsuke.args4j.spi.SubCommand;
+
+/**
+ * To reference {@link SubCommand} information , load and set sub command information
+ * on this class.
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
+ *
+ *
+ */
+public class SubCommandData {
+ private static final SubCommandData CMD_DATA = new SubCommandData();
+
+
+ private static final Map<CommandInfo ,CommandInfo> CMD_TREEMAP = new TreeMap<CommandInfo, CommandInfo>();
+
+ private SubCommandData() {
+ }
+
+ protected static void put(CommandInfo parent , CommandInfo child) {
+ CMD_TREEMAP.put(parent, child);
+ }
+
+ public static CommandInfo[] getChildren(CommandInfo parent) {
+ return null;
+ }
+
+
+}
--- /dev/null
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.ncli.core;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.kohsuke.args4j.spi.SubCommand;
+
+/**
+ * This is reference data class for {@link SubCommand} , mainly {@link #usage()} and {@link #common()}.
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface TizenSubCommand {
+ /**
+ * This is just for showing information in CLI.
+ * @return command's name which will be used in CLI.
+ */
+ public String name() default "";
+ /**
+ * @return single line usage text for this sub command
+ */
+ public String usage() default "";
+ /**
+ * @return default is false. set true if this command should show in the usage
+ */
+ public boolean common() default false;
+}
--- /dev/null
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.ncli.core;
+
+import java.util.AbstractList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.OptionDef;
+import org.kohsuke.args4j.spi.Messages;
+import org.kohsuke.args4j.spi.OptionHandler;
+import org.kohsuke.args4j.spi.Parameters;
+import org.kohsuke.args4j.spi.Setter;
+import org.kohsuke.args4j.spi.SubCommand;
+import org.kohsuke.args4j.spi.SubCommandHandler;
+import org.kohsuke.args4j.spi.SubCommands;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
+ *
+ *
+ */
+public class TizenSubCommandHandler extends OptionHandler<Object> {
+ private Logger log = LoggerFactory.getLogger(getClass());
+
+ private SubCommands commands;
+ private Map<String, CommandInfo> commandInfo = new HashMap<String, CommandInfo>();
+
+ public TizenSubCommandHandler(CmdLineParser parser, OptionDef option, Setter<Object> setter) {
+ super(parser, option, setter);
+ commands = setter.asAnnotatedElement().getAnnotation(SubCommands.class);
+ if (commands==null) {
+ throw new IllegalStateException("SubCommandHandler must be used with @SubCommands annotation");
+ }
+
+ }
+
+ @Override
+ public int parseArguments(Parameters params) throws CmdLineException {
+ String subCmd = params.getParameter(0);
+
+ for (SubCommand c : commands.value()) {
+ if (c.name().equals(subCmd)) {
+ setter.addValue(subCommand(c,params));
+ return params.size(); // consume all the remaining tokens
+ }
+ }
+
+ return fallback(subCmd);
+ }
+
+ protected int fallback(String subCmd) throws CmdLineException {
+ throw new CmdLineException(owner, Messages.ILLEGAL_OPERAND.format(option.toString(),subCmd));
+ }
+
+ protected Object subCommand(SubCommand c, final Parameters params) throws CmdLineException {
+ Object subCmd = instantiate(c);
+ CmdLineParser p = configureParser(subCmd,c);
+ p.parseArgument(new AbstractList<String>() {
+ @Override
+ public String get(int index) {
+ try {
+ return params.getParameter(index+1);
+ } catch (CmdLineException e) {
+ // invalid index was accessed.
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ @Override
+ public int size() {
+ return params.size()-1;
+ }
+ });
+ return subCmd;
+ }
+
+ protected CmdLineParser configureParser(Object subCmd, SubCommand c) {
+ return new CommandLineParser(subCmd);
+ }
+
+ protected Object instantiate(SubCommand c) {
+ try {
+ return c.impl().newInstance();
+ } catch (InstantiationException e) {
+ throw new IllegalStateException("Failed to instantiate "+c,e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalStateException("Failed to instantiate "+c,e);
+ }
+ }
+
+ @Override
+ public String getDefaultMetaVariable() {
+ return "CMD ARGS...";
+ }
+
+ public SubCommands getSubcommand() {
+ return this.commands;
+ }
+
+
+
+}
--- /dev/null
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.ncli.core.collection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.tizen.ncli.core.CommandInfo;
+
+/**
+ * Tree structure collection.<br>
+ * <p>Initially this is copied from http://stackoverflow.com/questions/3522454/java-tree-data-structure
+ * But some features are added.
+ * This is not for general data container like huge size of data.(e.g. file directory structure)
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
+ * @param <T>
+ * @date 2013. 11. 20.
+ */
+public class Tree<T> {
+ private Node<T> root;
+
+ public Tree(T rootData) {
+ root = new Node<T>();
+ root.data = rootData;
+ root.children = new ArrayList<Node<T>>();
+ }
+
+ public static class Node<T> {
+ private T data;
+ private Node<T> parent;
+ private List<Node<T>> children;
+ }
+
+ /**
+ * Get {@linkplain Node} which has a given <code>commandInfo</code> as a root.
+ * @param commandInfo
+ */
+ public Node<T> get(CommandInfo commandInfo) {
+ // TODO Auto-generated method stub
+ if( root.data.equals(commandInfo) ) {
+ return root;
+ }else {
+ //traverse if there is Node as same as given commandInfo
+ for (Node<T> child : root.children) {
+ if(child.data.equals(commandInfo)) {
+ return child;
+ }
+ }
+ }
+ return null;
+ }
+}
-/*\r
- * IDE\r
- *\r
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * Hyeongseok Heo <hyeongseok.heo@samsung.com>\r
- * Kangho Kim <kh5325.kim@samsung.com>\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- */\r
-package org.tizen.ncli.ide.shell;\r
-\r
-import java.io.File;\r
-import java.io.PrintWriter;\r
-\r
-import org.kohsuke.args4j.Option;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * Implemented common function of CLI options\r
- * \r
- * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)\r
- */\r
-public abstract class AbstractCLI {\r
- protected Logger log = LoggerFactory.getLogger(getClass());\r
-\r
- @Option(name = "--", metaVar = "working directory", usage = "Specify where is the base directory for the command")\r
- public File workingDir;\r
-\r
- @Option(name = "--current-workspace-path", metaVar = "current workspace path", usage = "Specify where is the root path for the command as a default")\r
- public String currentWorkspacePath;\r
-\r
- protected PrintWriter output = new PrintWriter(System.out);;\r
-\r
- public abstract void execute();\r
-}\r
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.ncli.ide.shell;
+
+import java.io.File;
+import java.io.PrintWriter;
+
+import org.kohsuke.args4j.Option;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implemented common function of CLI options
+ *
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
+ */
+public abstract class AbstractCLI {
+ protected Logger log = LoggerFactory.getLogger(getClass());
+
+ @Option(name = "--", metaVar = "working directory", usage = "Specify where is the base directory for the command")
+ public File workingDir;
+
+ @Option(hidden=true,name = "--current-workspace-path", metaVar = "current workspace path", usage = "Specify where is the root path for the command as a default")
+ public String currentWorkspacePath;
+
+ protected PrintWriter output = new PrintWriter(System.out);;
+
+ public abstract void execute();
+}
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
import org.tizen.core.ide.BuildWebParameter;\r
+import org.tizen.ncli.core.TizenSubCommand;\r
import org.tizen.ncli.ide.subcommands.BuildWebCLICommand;\r
\r
+@TizenSubCommand(name="build-web" , common=true , usage = "Build sources under the Tizen web project")\r
public class BuildWebCLI extends AbstractCLI {\r
private Logger log = LoggerFactory.getLogger(getClass());\r
\r
import org.kohsuke.args4j.Option;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
+import org.tizen.ncli.core.TizenSubCommand;\r
import org.tizen.ncli.ide.Tizen;\r
import org.tizen.ncli.ide.TizenCLIConfig;\r
import org.tizen.ncli.ide.config.Configuration;\r
/**\r
* @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)\r
*/\r
+@TizenSubCommand(name="config" , usage="Set up configurations on the tizen CLI")\r
public class ConfigCLI extends AbstractCLI{\r
private Map<String, String> properties = new HashMap<String, String>();\r
\r
--- /dev/null
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.ncli.ide.shell;
+
+/**
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
+ *
+ *
+ */
+public class HelpCLI extends AbstractCLI{
+
+ @Override
+ public void execute() {
+ // TODO Auto-generated method stub
+
+ }
+
+
+
+}
-/**\r
- * \r
- */\r
-package org.tizen.ncli.ide.shell;\r
-\r
-import java.io.PrintWriter;\r
-import java.text.MessageFormat;\r
-import java.util.List;\r
-\r
-import org.kohsuke.args4j.Argument;\r
-import org.kohsuke.args4j.CmdLineException;\r
-import org.kohsuke.args4j.CmdLineParser;\r
-import org.kohsuke.args4j.OptionHandlerFilter;\r
-import org.kohsuke.args4j.spi.OptionHandler;\r
-import org.kohsuke.args4j.spi.SubCommand;\r
-import org.kohsuke.args4j.spi.SubCommandHandler;\r
-import org.kohsuke.args4j.spi.SubCommands;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * This class is entry point of Tizen New Command Line Interface. All the command line argument would be parsed and then\r
- * proper Command class is called.\r
- * \r
- * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)\r
- * \r
- */\r
-public class Main {\r
-\r
- private Logger log = LoggerFactory.getLogger(Main.class);\r
- \r
- //FIXME Should resolve subcommand usage message problem and usage and metaVar should be externalized!\r
- /*\r
- * usage="Set up configurations on the tizen CLI\n "\r
- + "Create tizen resource\n "\r
- + "Build sources with Tizen native build tools\n "\r
- + "Build sources under the Tizen web project\n "\r
- + "Make a sinature file with a given certificate information \n "\r
- + "Make a tizen package(tpk|wgt) \n "\r
- + "Transfer the package to the target and install on the target \n "\r
- + "Uninstall app. from the selected target with given package id \n "\r
- + "Run a app. at the target \n "\r
- + "Debug a app. at the target"\r
- * */\r
- @Argument(index = 0, required = true, handler = SubCommandHandler.class , \r
- metaVar="cli-config\n"\r
- + "create\n"\r
- + "build-native\n"\r
- + "build-web\n"\r
- + "sign\n"\r
- + "package\n"\r
- + "install\n"\r
- + "uninstall\n"\r
- + "run\n"\r
- + "debug",\r
- usage="Set up configurations on the tizen CLI\n "\r
- )\r
- @SubCommands({ @SubCommand(name = "create", impl = CreateCLI.class),\r
- @SubCommand(name = "build-native", impl = BuildNativeCLI.class),\r
- @SubCommand(name = "build-web", impl = BuildWebCLI.class),\r
- @SubCommand(name = "sign", impl = SignCLI.class), \r
- @SubCommand(name = "cli-config", impl = ConfigCLI.class) })\r
- private AbstractCLI tizenCLI;\r
-\r
- /**\r
- * @param args\r
- */\r
- public static void main(String[] args) {\r
- Main tizen = new Main();\r
- tizen.run(args);\r
-\r
- }\r
-\r
- private void run(String[] args) {\r
- CmdLineParser cmdParser = new CmdLineParser(this);\r
- log.trace("Start running Tizen CLI Main class...");\r
- PrintWriter errorWriter = new PrintWriter(System.err);\r
- try {\r
- cmdParser.setUsageWidth(120);\r
- // Argument parsing - make metadata from annotation.\r
- cmdParser.parseArgument(args);\r
- } catch (CmdLineException e) {\r
- if( args.length > 0) {\r
- errorWriter.println();\r
- errorWriter.println("Argument is not valid!");\r
- errorWriter.println(MessageFormat.format("Error: {0}", e.getMessage()));\r
- errorWriter.println();\r
- }else {\r
- errorWriter.print("Command is needed like belows!");\r
- errorWriter.println();\r
- cmdParser.printUsage(errorWriter, null);\r
- errorWriter.println();\r
- }\r
- errorWriter.flush();\r
- System.exit(1);\r
- }\r
- \r
- try {\r
- //Execute actual command classes\r
- if (null != this.tizenCLI) {\r
- this.tizenCLI.execute();\r
- }\r
- }catch(Exception e) {\r
- e.printStackTrace();\r
- }\r
-\r
- errorWriter.flush(); \r
- if( null != tizenCLI.output) {\r
- tizenCLI.output.flush();\r
- }\r
- System.exit(1);\r
-\r
- }\r
-\r
-}\r
+/**
+ *
+ */
+package org.tizen.ncli.ide.shell;
+
+import java.io.PrintWriter;
+import java.text.MessageFormat;
+import java.util.List;
+
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.OptionHandlerFilter;
+import org.kohsuke.args4j.spi.OptionHandler;
+import org.kohsuke.args4j.spi.SubCommand;
+import org.kohsuke.args4j.spi.SubCommandHandler;
+import org.kohsuke.args4j.spi.SubCommands;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.ncli.core.CommandLineParser;
+import org.tizen.ncli.core.TizenSubCommand;
+import org.tizen.ncli.core.TizenSubCommandHandler;
+
+/**
+ * This class is entry point of Tizen New Command Line Interface. All the command line argument would be parsed and then
+ * proper Command class is called.
+ *
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
+ *
+ */
+public class Main {
+
+ private Logger log = LoggerFactory.getLogger(Main.class);
+
+ //FIXME Should resolve subcommand usage message problem and usage and metaVar should be externalized!
+ @Argument(index = 0, required = true, handler = TizenSubCommandHandler.class ,
+ metaVar="<command>",
+ usage="tizen <command>"
+ )
+ @SubCommands({ @SubCommand(name = "create", impl = CreateCLI.class),
+ @SubCommand(name = "build-native", impl = BuildNativeCLI.class),
+ @SubCommand(name = "build-web", impl = BuildWebCLI.class),
+ @SubCommand(name = "sign", impl = SignCLI.class),
+ @SubCommand(name = "cli-config", impl = ConfigCLI.class),
+ @SubCommand(name = "help", impl = HelpCLI.class)
+ })
+ private AbstractCLI tizenCLI;
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ Main tizen = new Main();
+ tizen.run(args);
+
+ }
+
+ private void run(String[] args) {
+ CommandLineParser cmdParser = new CommandLineParser(this);
+ log.trace("Start running Tizen CLI Main class...");
+ log.trace("Argument count:{}",args.length);
+ PrintWriter errorWriter = new PrintWriter(System.err);
+ try {
+ cmdParser.setUsageWidth(120);
+ // Argument parsing - make metadata from annotation.
+ cmdParser.parseArgument(args);
+ } catch (CmdLineException e) {
+ if( args.length > 0) {
+ errorWriter.println();
+ errorWriter.println("Argument is not valid!");
+ errorWriter.println(MessageFormat.format("Error: {0}", e.getMessage()));
+ errorWriter.println();
+ }else if(args.length == 0){
+ errorWriter.println();
+ errorWriter.println("Usage: tizen <command> [args]");
+ errorWriter.println();
+ errorWriter.println("Where <command> is one of ");
+ //TODO sub command list should be printed by input argument.
+ }
+ errorWriter.flush();
+ System.exit(1);
+ }
+
+ try {
+ //Execute actual command classes
+ if (null != this.tizenCLI) {
+ this.tizenCLI.execute();
+ }
+ }catch(Exception e) {
+ e.printStackTrace();
+ }
+
+ errorWriter.flush();
+ if( null != tizenCLI.output) {
+ tizenCLI.output.flush();
+ }
+ System.exit(1);
+
+ }
+
+}