SRADA-896: Updated help message for CLI 'start' command.
authorMaria Guseva <m.guseva@samsung.com>
Tue, 19 Jul 2016 11:40:30 +0000 (14:40 +0300)
committerMaria Guseva <m.guseva@samsung.com>
Tue, 19 Jul 2016 14:49:53 +0000 (23:49 +0900)
Updated general description of 'start' command and added more detailed
description for CLI tracing features options.

* StartCommand - help message in constructor updated to mention features
instead of templates.
* TracingFeatureArgument.addDefaultFeaturesDescription() - new private method,
invoked in static section for all enum values.
* TracingFeatureArgument.updateArgsDescription() - new private method,
invoked in addFeatureValue().
* Help.width - new private final field, set to 100 now.
* Help.printHelp() - changed to print options in order they were defined.

Change-Id: I7f109124320a67d4a83dedc9c7259b3db3ee9453

org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/commands/StartCommand.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingFeatureArgument.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/utils/Help.java

index de98157..a8c26f2 100644 (file)
@@ -21,7 +21,7 @@ public class StartCommand extends Command {
         */
        public StartCommand() {
                super("start", 0,
-                               "start trace specified application on specified target using specified template",
+                               "start tracing on specified target for specified application using selected tracing features",
                                "<ip:port|serial>");
 
        }
index 4ea03ff..a2aad44 100644 (file)
@@ -50,6 +50,11 @@ public enum TracingFeatureArgument {
 
                SYNC.addDefaultFeatureValue("thread", PrimitiveFeature.THREAD_ANALYSIS);
                SYNC.addDefaultFeatureValue("sync", PrimitiveFeature.SYNC_ANALYSIS);
+
+               // Add description of default options
+               for (TracingFeatureArgument featureArg : values())
+                       if (featureArg.getOption().hasArgs())
+                               featureArg.addDefaulFeaturestDescription();
        }
 
        private final Option option;
@@ -64,10 +69,34 @@ public enum TracingFeatureArgument {
         * @param longName long name of CLI option
         */
        private TracingFeatureArgument(String name, String longName) {
+               String desc = "select " + longName.replace("-", " ") + " tracing\n"
+                               + "Possible arguments: ";
                this.option = Option.builder(name).longOpt(longName).hasArgs()
                                .valueSeparator(',').optionalArg(true)
-                               .desc("select " + longName.replace("-", " ") + " tracing")
-                               .build();
+                               .desc(desc).build();
+       }
+
+       /**
+        * Update option description with information of features selected by default
+        */
+       private void addDefaulFeaturestDescription() {
+               String desc = option.getDescription();
+               String defDesc = "If no arguments provided - '";
+               // Check if default are all
+               if (defFeatures.size() == availFeatures.size())
+                       defDesc += ALL_NAME;
+               else {
+                       StringBuffer defArgsString = new StringBuffer();
+                       for (Map.Entry<String, PrimitiveFeature> feature : availFeatures
+                                       .entrySet()) {
+                               if (defFeatures.contains(feature.getValue()))
+                                       defArgsString.append(feature.getKey() + ",");
+                       }
+                       defDesc += defArgsString.toString();
+                       // remove last ',' symbol
+                       defDesc = defDesc.substring(0, defDesc.length()-1);
+               }
+               option.setDescription(desc + "\n" + defDesc + "' is selected");
        }
 
        /**
@@ -79,7 +108,7 @@ public enum TracingFeatureArgument {
        private TracingFeatureArgument(String name, PrimitiveFeature feature) {
                this.option = Option.builder(name)
                                .longOpt(feature.getName().toLowerCase().replace(' ', '-'))
-                               .desc("select " + feature.getName().toLowerCase() + " tracing")
+                               .desc("Select " + feature.getName().toLowerCase() + " tracing")
                                .build();
                defFeatures.add(feature);
        }
@@ -103,6 +132,17 @@ public enum TracingFeatureArgument {
         */
        private void addFeatureValue(String name, PrimitiveFeature feature) {
                availFeatures.put(name, feature);
+               updateArgsDescription(name);
+       }
+
+       /**
+        * Update option's description according to added feature value
+        * @param name name of added feature value
+        */
+       private void updateArgsDescription(String name) {
+               String desc = option.getDescription();
+               desc = desc.replace(ALL_NAME, "");
+               option.setDescription(desc + name + ", " + ALL_NAME);
        }
 
        /**
index ae32fed..67974bb 100644 (file)
@@ -8,6 +8,12 @@ import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.Options;
 
 public class Help {
+
+       /**
+        * Width of help message
+        */
+       private static int width = 100;
+
        /**
         * Prints command's help message to given <code>PrintStream</code>.
         * @param commandDesc <code>String</code> with command description
@@ -18,9 +24,11 @@ public class Help {
        public static void printHelp(String commandDesc, Options opts, PrintStream ps) throws IOException {
                PrintWriter pw = new PrintWriter(ps, true);
                HelpFormatter formatter = new HelpFormatter();
+               // Print in the order options were defined
+               formatter.setOptionComparator(null);
 
-               formatter.printWrapped(pw, 80, 30, commandDesc);
-               formatter.printOptions(pw, 80, opts, 4, 4);
+               formatter.printWrapped(pw, width, 30, commandDesc);
+               formatter.printOptions(pw, width, opts, 4, 4);
                pw.println();
        }
 }