From 738538cca9a27dc980cac595566b044d13bacc57 Mon Sep 17 00:00:00 2001 From: "hyeongseok.heo" Date: Thu, 19 Dec 2013 19:21:43 +0900 Subject: [PATCH] CLI : Modify help output messages Modify default help message to show usage. Fix current working path error. Change-Id: I24783c4acb7ff59b3902d002e7246fd83349f801 Signed-off-by: hyeongseok.heo --- .../resources/log4j-progress-dev.xml | 5 +++ org.tizen.ncli.ide/resources/profiles.xml | 36 ++++++++++++++++++++++ .../src/org/tizen/ncli/core/CommandLineParser.java | 3 +- .../src/org/tizen/ncli/ide/shell/AbstractCLI.java | 3 +- .../org/tizen/ncli/ide/shell/BuildNativeCLI.java | 4 +-- .../src/org/tizen/ncli/ide/shell/InstallCLI.java | 2 +- .../src/org/tizen/ncli/ide/shell/ListAppCLI.java | 2 +- .../src/org/tizen/ncli/ide/shell/ListCLI.java | 2 +- .../org/tizen/ncli/ide/shell/ListTargetCLI.java | 2 +- .../src/org/tizen/ncli/ide/shell/Main.java | 29 ++++++++++++++--- .../src/org/tizen/ncli/ide/shell/RunCLI.java | 2 +- .../src/org/tizen/ncli/ide/shell/SignCLI.java | 2 +- .../src/org/tizen/ncli/ide/shell/UninstallCLI.java | 2 +- 13 files changed, 79 insertions(+), 15 deletions(-) create mode 100755 org.tizen.ncli.ide/resources/profiles.xml diff --git a/org.tizen.ncli.ide/resources/log4j-progress-dev.xml b/org.tizen.ncli.ide/resources/log4j-progress-dev.xml index 4d85bb9..660ec3f 100644 --- a/org.tizen.ncli.ide/resources/log4j-progress-dev.xml +++ b/org.tizen.ncli.ide/resources/log4j-progress-dev.xml @@ -27,6 +27,11 @@ + + + + + diff --git a/org.tizen.ncli.ide/resources/profiles.xml b/org.tizen.ncli.ide/resources/profiles.xml new file mode 100755 index 0000000..1e35701 --- /dev/null +++ b/org.tizen.ncli.ide/resources/profiles.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/core/CommandLineParser.java b/org.tizen.ncli.ide/src/org/tizen/ncli/core/CommandLineParser.java index b87cef1..6d837b8 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/core/CommandLineParser.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/core/CommandLineParser.java @@ -26,6 +26,7 @@ package org.tizen.ncli.core; import java.io.PrintWriter; import java.io.Writer; +import java.lang.annotation.Annotation; import java.util.List; import java.util.ResourceBundle; @@ -163,7 +164,7 @@ public class CommandLineParser extends CmdLineParser { * @return */ private CommandInfo parseTizenSubCommand(SubCommand subCommand) { - TizenSubCommand annotation = subCommand.impl().getClass().getAnnotation(TizenSubCommand.class); + TizenSubCommand annotation = subCommand.impl().getAnnotation(TizenSubCommand.class); log.trace("SubCommand:{}", subCommand.name()); String subCmdName = subCommand.name(); CommandInfo cmdInfo = null; diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java index 0a907f3..1895d5f 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java @@ -91,13 +91,14 @@ public abstract class AbstractCLI { progressLog.info("-----------------------------------------------------"); progressLog.info("Starting {}", getCurrCmdName()); progressLog.info("-----------------------------------------------------"); + progressLog.info(""); } private void printFinished() { if( !isLoggingStartFinish) return; progressLog.info("-----------------------------------------------------"); progressLog.info("Finished {}", getCurrCmdName()); - progressLog.info("-----------------------------------------------------"); + progressLog.info(""); } private String getCurrCmdName() { diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java index 3092c6f..cfce137 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java @@ -32,7 +32,7 @@ import org.tizen.ncli.ide.subcommands.BuildNative; import org.tizen.ncli.ide.subcommands.BuildNativeCLICommand; /** - * @author Hyunsik Noh{@leteral } (S-core) + * @author Hyunsik Noh{@literal } (S-core) */ @TizenSubCommand(name="build-native" , usage="Build for the tizen native project") public class BuildNativeCLI extends AbstractCLI { @@ -64,7 +64,7 @@ public class BuildNativeCLI extends AbstractCLI { BuildNativeCLICommand command = new BuildNativeCLICommand(); - command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir); + command.setWorkingDir(getRealWorkingPath()); configuration = DA.equals(configuration) ? DA_ORIGIN : configuration; command.setRequiredOptions(new String[]{architecture, compiler, configuration}); command.setPredefineOption(predefineOption); diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/InstallCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/InstallCLI.java index 9c2374d..cb069e3 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/InstallCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/InstallCLI.java @@ -49,7 +49,7 @@ public class InstallCLI extends AbstractCLI{ public void execute() { log.trace("Execute InstallCLI..."); InstallCLICommand command = new InstallCLICommand(); - command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir); + command.setWorkingDir(getRealWorkingPath()); command.setTarget(target); command.setName(name); Install runCommand = command.runCommand(); diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java index ee21428..4ece177 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java @@ -46,7 +46,7 @@ public class ListAppCLI extends AbstractCLI{ public void execute() { log.trace("Execute ListAppCLI..."); ListAppCLICommand command = new ListAppCLICommand(); - command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir); + command.setWorkingDir(getRealWorkingPath()); command.setTarget(target); ListApp runCommand = command.runCommand(); } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListCLI.java index 8a64cbd..d8c3edc 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListCLI.java @@ -36,7 +36,7 @@ import org.tizen.ncli.core.TizenSubCommandHandler; public class ListCLI extends AbstractCLI{ private Logger log = LoggerFactory.getLogger(getClass()); - @Argument(index = 0, required = true, handler = TizenSubCommandHandler.class, usage = "Command is needed!") + @Argument(index = 0, required = true, handler = TizenSubCommandHandler.class) @SubCommands({ @SubCommand(name = "target", impl = ListTargetCLI.class), @SubCommand(name = "app", impl = ListAppCLI.class) diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListTargetCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListTargetCLI.java index 001fce1..eba842b 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListTargetCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListTargetCLI.java @@ -43,7 +43,7 @@ public class ListTargetCLI extends AbstractCLI{ log.trace("Execute ListDeviceCLI..."); ListTargetCLICommand command = new ListTargetCLICommand(); - command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir); + command.setWorkingDir(getRealWorkingPath()); command.setDetail(detail); ListTarget runCommand = command.runCommand(); } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java index c082af9..ee1eb14 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java @@ -5,6 +5,7 @@ package org.tizen.ncli.ide.shell; import java.io.PrintWriter; import java.text.MessageFormat; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -16,6 +17,7 @@ import org.kohsuke.args4j.spi.SubCommands; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.common.util.IOUtil; +import org.tizen.common.util.StringUtil; import org.tizen.ncli.core.CommandInfo; import org.tizen.ncli.core.CommandLineParser; import org.tizen.ncli.core.SubCommandData; @@ -81,7 +83,7 @@ public class Main { try { if (args.length == 0 || helpOpt) { printDefaultCommandUsage(errorWriter); - } else if (args.length == 3) { + } else if (args.length == 3 ) { String command = args[0]; log.trace("{}", command); if (null == SubCommandData.get(command)) { @@ -136,8 +138,9 @@ public class Main { if (findTreeNode.children.size() > 0) { errorWriter.println(MessageFormat.format("Usage: tizen {0} [args]", command)); List> children = findTreeNode.children; + int maxLen = getMaxLengthForTreeNode(children)+4; for (TreeNode treeNode : children) { - errorWriter.printf(" %s\t%s\n", treeNode.data.getCommandName(), treeNode.data.getUsage()); + errorWriter.printf(" %-"+maxLen+"s%s\n", treeNode.data.getCommandName(), treeNode.data.getUsage()); } } else { errorWriter.println(MessageFormat.format("Usage: tizen {0} [args]", command)); @@ -147,15 +150,33 @@ public class Main { } } - private void printDefaultCommandUsage(PrintWriter errorWriter) { + private int getMaxLengthForTreeNode(List> children) { + int ret = 0; + for (TreeNode treeNode : children) { + int currLen = ( null != treeNode.data.getCommandName())?treeNode.data.getCommandName().length():0; + ret = Math.max(ret, currLen); + } + return ret; + } + + private void printDefaultCommandUsage(PrintWriter errorWriter) { progressLog.error("Usage: tizen [args]"); progressLog.error("Where is one of "); progressLog.error("-----------------------------"); Set commandNames = SubCommandData.keySet(); + int maxLen = getMaxLength(commandNames)+4; for (String key : commandNames) { CommandInfo commandInfo = SubCommandData.get(key); - progressLog.error(" {}\t{}",key,(commandInfo.getUsage() == null) ? "" : commandInfo.getUsage()); + progressLog.error(String.format(" %-"+maxLen+"s%s", key,(commandInfo.getUsage() == null) ? "" : commandInfo.getUsage())); } progressLog.error("See more information:\n tizen help "); } + + private int getMaxLength(Iterable keys) { + int ret = 0; + for (String key : keys) { + ret = Math.max(ret, key.length()); + } + return ret; + } } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java index 29fe028..ef585af 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java @@ -48,7 +48,7 @@ public class RunCLI extends AbstractCLI{ public void execute() { log.trace("Execute RunCLI..."); RunCLICommand command = new RunCLICommand(); - command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir); + command.setWorkingDir(getRealWorkingPath()); command.setTarget(target); command.setPackageId(pkgId); Run runCommand = command.runCommand(); diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/SignCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/SignCLI.java index 98739b4..b470c66 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/SignCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/SignCLI.java @@ -45,7 +45,7 @@ public class SignCLI extends AbstractCLI { SignCLICommand command = new SignCLICommand(); command.setProfileName(profile); - command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir); + command.setWorkingDir(getRealWorkingPath()); Sign sign = command.runCommand(); } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java index ecaa719..9ebfab0 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java @@ -48,7 +48,7 @@ public class UninstallCLI extends AbstractCLI{ public void execute() { log.trace("Execute UninstallCLI..."); UninstallCLICommand command = new UninstallCLICommand(); - command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir); + command.setWorkingDir(getRealWorkingPath()); command.setTarget(target); command.setPkgId(pkgId); Uninstall runCommand = command.runCommand(); -- 2.7.4