CLI: modify format of usage
authorjihye424.kim <jihye424.kim@samsung.com>
Wed, 23 Mar 2016 08:23:10 +0000 (17:23 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 25 Mar 2016 01:05:48 +0000 (10:05 +0900)
- old-> <explain>: <example>
- new-> <explain>
          <example>

Change-Id: If155f5541faef96ecb199fed7bdaf1f0b158b769
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/console/util/OutputUtil.java

index 192ff85..c4aaa23 100644 (file)
@@ -86,7 +86,7 @@ public class OutputUtil {
 
        public static void printGlobalHelp() {
                System.out.println(StringResources.NEW_LINE + "Usage: "
-                               + "em-cli [global options] <command> [command options]"); //$NON-NLS-1$
+                               + "em-cli [global options] <COMMAND> [command options]"); //$NON-NLS-1$
 
                // print global options
                System.out.println("");
@@ -105,14 +105,21 @@ public class OutputUtil {
 
        public static void printCommandHelp(Command action) {
                String mandatoryOptions = "";
+               int count = 0;
                for (Option c : action.getOptionList()) {
                        if (c.isMandatory()) {
                                mandatoryOptions += " " + c.getShortUsage();
+                       } else {
+                               count++;
                        }
                }
 
-               System.out.println("Usage: " + "em-cli " //$NON-NLS-1$ //$NON-NLS-2$
-                                                       + action.getCommand() + mandatoryOptions + " [options]"); //$NON-NLS-1$
+               String usage = "Usage: " + "em-cli " //$NON-NLS-1$ //$NON-NLS-2$
+                               + action.getCommand() + mandatoryOptions;
+               if (count > 0) {
+                       usage += " [options]"; //$NON-NLS-1$
+               }
+               System.out.println(usage);
 
                System.out.println("");
                System.out.println("Command description"); //$NON-NLS-1$
@@ -132,7 +139,7 @@ public class OutputUtil {
 
                System.out.println();
                System.out.println("Examples"); //$NON-NLS-1$
-               printWithLine(action.getUsage());
+               printUsage(action.getUsage());
        }
 
        private static void printWithLine(String value) {
@@ -144,9 +151,25 @@ public class OutputUtil {
                }
        }
 
+       private static void printUsage(String value) {
+               assert value != null;
+
+               String[] usages = value.split(StringResources.NEW_LINE);
+               boolean odd = false;
+               for (String usage : usages) {
+                       if (!odd) {
+                               System.out.println("  " + usage);
+                               odd = true;
+                       } else {
+                               System.out.println("    " + "em-cli " + usage);
+                               odd = false;
+                       }
+               }
+       }
+
        private static int columns = 0;
        public static void printKeyandValue(String key, String value) {
-               printCommandDescription(key, value);
+               printCommandDescription(key, ": " + value);
        }
 
        private static void printOptionDescription(String value, String description) {