Fix -h to be precedence over other args 77/26177/1
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Wed, 13 Dec 2017 06:10:16 +0000 (11:40 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Wed, 13 Dec 2017 06:10:16 +0000 (11:40 +0530)
Issue-ID: CLI-66

Change-Id: I252fe9705d2801012aa571f51d386c0712416ad9
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java
framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java
framework/src/main/resources/open-cli-schema/default_input_parameters.yaml

index 4b7fe97..09e1927 100644 (file)
@@ -166,18 +166,16 @@ public abstract class OnapCommand {
 
         // -h or --help is always higher precedence !, user can set this value to get help message
         if (OnapCommandConstants.BOOLEAN_TRUE.equals(paramMap.get(OnapCommandConstants.DEFAULT_PARAMETER_HELP).getValue())) {
-            OnapCommandResult result = new OnapCommandResult();
-            result.setType(OnapCommandResultType.TEXT);
-            result.setOutput(this.printHelp());
-            return result;
+            this.cmdResult.setType(OnapCommandResultType.TEXT);
+            this.cmdResult.setOutput(this.printHelp());
+            return this.cmdResult;
         }
 
         // -v or --version is next higher precedence !, user can set this value to get help message
         if (OnapCommandConstants.BOOLEAN_TRUE.equals(paramMap.get(OnapCommandConstants.DEFAULT_PARAMETER_VERSION).getValue())) {
-            OnapCommandResult result = new OnapCommandResult();
-            result.setType(OnapCommandResultType.TEXT);
-            result.setOutput(this.printVersion());
-            return result;
+            this.cmdResult.setType(OnapCommandResultType.TEXT);
+            this.cmdResult.setOutput(this.printVersion());
+            return this.cmdResult;
         }
 
         // validate
@@ -225,7 +223,7 @@ public abstract class OnapCommand {
      * @return version
      */
     public String printVersion() {
-        return this.getInfo().getService();
+        return this.getInfo().getProduct() + "::" + this.getInfo().getService();
     }
 
     /**
index 4eaab81..3544fd7 100644 (file)
@@ -181,10 +181,10 @@ public class OnapCommandResult {
      *             exception
      */
     public String print() throws OnapCommandException {
-        String printOutput = "";
-
         if (this.getRecords().isEmpty()) {
-            return printOutput;
+            return "";
+        } else if (this.getType().equals(OnapCommandResultType.TEXT)) {
+            return this.getOutput().toString();
         }
 
         OnapCommandPrint print = new OnapCommandPrint();
@@ -220,16 +220,14 @@ public class OnapCommandResult {
             print.addColumn(val.getName(), val.getValues());
         }
 
-        if (this.isDebug()) {
-            printOutput = this.getDebugInfo() + "\n";
-        }
-
         if (this.getType().equals(OnapCommandResultType.JSON)) {
-            return printOutput + print.printJson();
+            return print.printJson();
         } else if (this.getType().equals(OnapCommandResultType.TABLE)) {
-            return printOutput + print.printTable(this.isIncludeSeparator());
+            return print.printTable(this.isIncludeSeparator());
         } else if (this.getType().equals(OnapCommandResultType.CSV)) {
-            return printOutput + print.printCsv();
+            return print.printCsv();
+        } else if (this.getType().equals(OnapCommandResultType.YAML)) {
+            return print.printYaml();
         }
 
         throw new OnapCommandOutputFormatNotsupported(this.getType().name());
index e8e08f4..02e8a71 100644 (file)
@@ -7,13 +7,13 @@ info:
 
 parameters:
   - name: help
-    type: string
+    type: bool
     description: print help message
     short_option: h
     long_option: help
     default_value: false
   - name: version
-    type: string
+    type: bool
     description: print service version
     short_option: v
     long_option: version