CLI : Modify help output messages 72/13972/1
authorhyeongseok.heo <hyeongseok.heo@samsung.com>
Thu, 19 Dec 2013 10:21:43 +0000 (19:21 +0900)
committerhyeongseok.heo <hyeongseok.heo@samsung.com>
Thu, 19 Dec 2013 10:21:43 +0000 (19:21 +0900)
Modify default help message to show usage.

Fix current working path error.

Change-Id: I24783c4acb7ff59b3902d002e7246fd83349f801
Signed-off-by: hyeongseok.heo <hyeongseok.heo@samsung.com>
13 files changed:
org.tizen.ncli.ide/resources/log4j-progress-dev.xml
org.tizen.ncli.ide/resources/profiles.xml [new file with mode: 0755]
org.tizen.ncli.ide/src/org/tizen/ncli/core/CommandLineParser.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/InstallCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListTargetCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/SignCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java

index 4d85bb9..660ec3f 100644 (file)
        <appender-ref ref="console" />
        </logger>
        
+       <logger name="org.tizen.ncli.core">
+          <level value="trace"/>
+       <appender-ref ref="console" />
+       </logger>
+       
        <logger name="org.tizen.core.ide">
        <level value="off"/>
        <appender-ref ref="console" />
diff --git a/org.tizen.ncli.ide/resources/profiles.xml b/org.tizen.ncli.ide/resources/profiles.xml
new file mode 100755 (executable)
index 0000000..1e35701
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<profiles version="2.2">
+       <profile name="develop">
+<!-- Please change <SDK_PATH> to the installed sdk path like '/home/user/tizen-sdk'.-->
+
+<!-- [REQUIRED] -->
+<!-- This is an author certificate. Please change key and password attributes. -->
+<!-- If you want, you can create a new certificate using the certificate-generator. -->
+               <profileitem
+                       ca="<SDK_PATH>/tools/certificate-generator/certificates/developer/tizen-developer-ca.cer"
+                       distributor="0"
+                       key="<Your Certificate (.p12) Path>"
+                       password=""
+                       rootca=""/>
+
+<!-- [REQUIRED] -->
+<!-- This is a default distributor certificate for developer. -->
+<!-- Generally, you don't need to change this. -->
+               <profileitem
+                       ca="<SDK_PATH>/tools/certificate-generator/certificates/distributor/tizen-distributor-ca.cer"
+                       distributor="1"
+                       key="<SDK_PATH>/tools/certificate-generator/certificates/distributor/tizen-distributor-signer.p12"
+                       password="Vy63flx5JBMc5GA4iEf8oFy+8aKE7FX/+arrDcO4I5k="
+                       rootca=""/>
+
+<!-- [OPTIONAL] -->
+<!-- Second distributor is a special purposed option. -->
+<!-- Generally, you don't need to change this. -->
+               <profileitem
+                       ca=""
+                       distributor="2"
+                       key=""
+                       password=""
+                       rootca=""/>
+       </profile>
+</profiles>
index b87cef1..6d837b8 100644 (file)
@@ -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;
index 0a907f3..1895d5f 100644 (file)
@@ -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() {
index 3092c6f..cfce137 100644 (file)
@@ -32,7 +32,7 @@ import org.tizen.ncli.ide.subcommands.BuildNative;
 import org.tizen.ncli.ide.subcommands.BuildNativeCLICommand;\r
 \r
 /**\r
- * @author Hyunsik Noh{@leteral <hyunsik.noh@samsung.com>} (S-core)\r
+ * @author Hyunsik Noh{@literal <hyunsik.noh@samsung.com>} (S-core)\r
  */\r
 @TizenSubCommand(name="build-native" , usage="Build for the tizen native project")\r
 public class BuildNativeCLI extends AbstractCLI {\r
@@ -64,7 +64,7 @@ public class BuildNativeCLI extends AbstractCLI {
 \r
         BuildNativeCLICommand command = new BuildNativeCLICommand();\r
 \r
-        command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir);\r
+        command.setWorkingDir(getRealWorkingPath());\r
         configuration = DA.equals(configuration) ? DA_ORIGIN : configuration;\r
         command.setRequiredOptions(new String[]{architecture, compiler, configuration});\r
         command.setPredefineOption(predefineOption);\r
index 9c2374d..cb069e3 100644 (file)
@@ -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();
index ee21428..4ece177 100644 (file)
@@ -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();
     }
index 8a64cbd..d8c3edc 100644 (file)
@@ -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)
index 001fce1..eba842b 100644 (file)
@@ -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();
     }
index c082af9..ee1eb14 100644 (file)
@@ -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} <sub-command> [args]", command));
                 List<TreeNode<CommandInfo>> children = findTreeNode.children;
+                int maxLen = getMaxLengthForTreeNode(children)+4;
                 for (TreeNode<CommandInfo> 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<TreeNode<CommandInfo>> children) {
+       int ret = 0;
+       for (TreeNode<CommandInfo> 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 <command> [args]");
         progressLog.error("Where <command> is one of ");
         progressLog.error("-----------------------------");
         Set<String> 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 <command>");
     }
+
+       private int getMaxLength(Iterable<String> keys) {
+               int ret = 0;
+               for (String key : keys) {
+                       ret = Math.max(ret, key.length());
+               }
+               return ret;
+       }
 }
index 29fe028..ef585af 100644 (file)
@@ -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();
index 98739b4..b470c66 100644 (file)
@@ -45,7 +45,7 @@ public class SignCLI extends AbstractCLI {
         SignCLICommand command = new SignCLICommand();\r
         \r
         command.setProfileName(profile);\r
-        command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir);\r
+        command.setWorkingDir(getRealWorkingPath());\r
         Sign sign = command.runCommand();\r
     }\r
     \r
index ecaa719..9ebfab0 100644 (file)
@@ -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();