From 9921b1751cde31721958d004935f2b7fc5e95513 Mon Sep 17 00:00:00 2001 From: jitendra007 Date: Tue, 21 Jul 2020 14:35:31 +0530 Subject: Code improvement for pending sonar issues Issue-ID: CLI-270 Signed-off-by: jitendra007 Change-Id: Ie27d3ff077fa1ef4d13788849aa82d695f183eeb --- main/src/main/java/org/onap/cli/main/OnapCli.java | 86 ++++++++++------------- 1 file changed, 39 insertions(+), 47 deletions(-) (limited to 'main') diff --git a/main/src/main/java/org/onap/cli/main/OnapCli.java b/main/src/main/java/org/onap/cli/main/OnapCli.java index 061c1f7b..1c27205f 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -225,8 +225,8 @@ public class OnapCli { if (this.profile != null) { OnapCommandRegistrar.getRegistrar().setProfile( this.profile, - new ArrayList(), - new ArrayList()); + new ArrayList<>(), + new ArrayList<>()); } } catch (Exception e) { this.print(e); @@ -378,10 +378,9 @@ public class OnapCli { break; } else if (OnapCliConstants.PARAM_INTERACTIVE_CLEAR.equalsIgnoreCase(line)) { console.clearScreen(); - continue; - } - this.args = new ArrayList<>(); - this.args.addAll(Arrays.asList(line.split(OnapCliConstants.PARAM_INTERACTIVE_ARG_SPLIT_PATTERN))); + } else { + this.args = new ArrayList<>(); + this.args.addAll(Arrays.asList(line.split(OnapCliConstants.PARAM_INTERACTIVE_ARG_SPLIT_PATTERN))); if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_USE)) { if (args.size() == 1) { @@ -397,53 +396,46 @@ public class OnapCli { } } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_HELP)) { - try { - this.print(OnapCommandRegistrar.getRegistrar().getHelpForEnabledProductVersion()); - this.print(OnapCli.getDirectiveHelp()); - } catch (OnapCommandException e) { - this.print(e); - } - - } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_VERSION)) { - this.printVersion = true; - handleVersion(); - - } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_PROFILE)) { - if (args.size() == 1) { - this.print("Please use it in the form of 'profile '\n"); - this.print("Available profiles: "); - this.print(OnapCommandRegistrar.getRegistrar().getUserProfiles().toString()); - } else { - this.profile = args.get(1); - handleProfile(); - } + this.print(OnapCommandRegistrar.getRegistrar().getHelpForEnabledProductVersion()); + this.print(OnapCli.getDirectiveHelp()); + } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_VERSION)) { + this.printVersion = true; + handleVersion(); + + } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_PROFILE)) { + if (args.size() == 1) { + this.print("Please use it in the form of 'profile '\n"); + this.print("Available profiles: "); + this.print(OnapCommandRegistrar.getRegistrar().getUserProfiles().toString()); + } else { + this.profile = args.get(1); + handleProfile(); + } - } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_SET)) { - if (args.size() > 1) { - String [] paramEntry = args.get(1).trim().split("=", 2); - if (paramEntry.length == 2) { - OnapCommandRegistrar.getRegistrar().addParamCache(paramEntry[0].trim(), paramEntry[1].trim()); + } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_SET)) { + if (args.size() > 1) { + String[] paramEntry = args.get(1).trim().split("=", 2); + if (paramEntry.length == 2) { + OnapCommandRegistrar.getRegistrar().addParamCache(paramEntry[0].trim(), paramEntry[1].trim()); + } else { + this.print("Please use it in the form of 'set ='"); + } } else { - this.print("Please use it in the form of 'set ='"); + this.print(OnapCommandRegistrar.getRegistrar().getParamCache().toString()); } - } else { - this.print(OnapCommandRegistrar.getRegistrar().getParamCache().toString()); - } - } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_UNSET)) { - if (args.size() > 1) { - for (int i = 1; i 1) { + for (int i = 1; i < args.size(); i++) { + OnapCommandRegistrar.getRegistrar().removeParamCache(args.get(i)); + } + } + } else { + if (!(args.size() == 1 && args.get(0).trim().isEmpty())) { + this.setArgs(this.args.toArray(new String[]{})); + handleCommand(); } } - } else { - if (args.size() == 1 && args.get(0).trim().isEmpty()) { - //Ignore blanks // NOSONAR - continue; - } - - this.setArgs(this.args.toArray(new String [] {})); - handleCommand(); } } } catch (IOException e) { // NOSONAR -- cgit 1.2.3-korg