diff options
author | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2017-12-13 11:40:16 +0530 |
---|---|---|
committer | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2017-12-13 11:40:16 +0530 |
commit | 8356f97171f8cec8ff07a7d39f5fef5c49e85063 (patch) | |
tree | ce373c78d97ecfd61284483921dfd1d796347cfb /framework/src | |
parent | 50aea9d5d3db01513c701e34c5f6cf7f6e25ac1f (diff) |
Fix -h to be precedence over other args
Issue-ID: CLI-66
Change-Id: I252fe9705d2801012aa571f51d386c0712416ad9
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'framework/src')
3 files changed, 17 insertions, 21 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java index 4b7fe976..09e1927a 100644 --- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java +++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java @@ -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(); } /** diff --git a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java index 4eaab81a..3544fd7c 100644 --- a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java +++ b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java @@ -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()); diff --git a/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml b/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml index e8e08f46..02e8a717 100644 --- a/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml +++ b/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml @@ -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 |