diff options
author | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-02-12 10:23:56 +0530 |
---|---|---|
committer | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-02-12 11:26:31 +0530 |
commit | 3984f88cab86fb89c0b5a6200730855eade5360e (patch) | |
tree | 4d61bb753a59bca5e14221fdf37c57af228c9cb7 | |
parent | 305eee7a0e8d74735ae8d41c83fce484030e988c (diff) |
Make console reader be safer
Issue-ID: CLI-92
Change-Id: I5c415b2fcdf92b2a861a871d9ab907221290107d
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
-rw-r--r-- | main/src/main/java/org/onap/cli/main/OnapCli.java | 34 |
1 files changed, 17 insertions, 17 deletions
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 65edfc13..62b78fd5 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -303,24 +303,24 @@ public class OnapCli { * exception */ private ConsoleReader createConsoleReader() throws IOException { - ConsoleReader console = new ConsoleReader(); - try { - StringCompleter strCompleter = new StringCompleter(OnapCommandRegistrar.getRegistrar().listCommandsForEnabledProductVersion()); - strCompleter.add(OnapCliConstants.PARAM_INTERACTIVE_EXIT, - OnapCliConstants.PARAM_INTERACTIVE_CLEAR, - OnapCliConstants.PARAM_INTERACTIVE_USE, - OnapCliConstants.PARAM_INTERACTIVE_HELP, - OnapCliConstants.PARAM_INTERACTIVE_VERSION, - OnapCliConstants.PARAM_INTERACTIVE_SET, - OnapCliConstants.PARAM_INTERACTIVE_UNSET, - OnapCliConstants.PARAM_INTERACTIVE_PROFILE); - console.addCompleter(strCompleter); - console.setPrompt(OnapCliConstants.PARAM_INTERACTIVE_PROMPT + ":" + OnapCommandRegistrar.getRegistrar().getEnabledProductVersion() + ">"); - } catch (OnapCommandException e) { // NOSONAR - this.print("Failed to load oclip commands," + e.getMessage()); + try(ConsoleReader console = new ConsoleReader()){ + try { + StringCompleter strCompleter = new StringCompleter(OnapCommandRegistrar.getRegistrar().listCommandsForEnabledProductVersion()); + strCompleter.add(OnapCliConstants.PARAM_INTERACTIVE_EXIT, + OnapCliConstants.PARAM_INTERACTIVE_CLEAR, + OnapCliConstants.PARAM_INTERACTIVE_USE, + OnapCliConstants.PARAM_INTERACTIVE_HELP, + OnapCliConstants.PARAM_INTERACTIVE_VERSION, + OnapCliConstants.PARAM_INTERACTIVE_SET, + OnapCliConstants.PARAM_INTERACTIVE_UNSET, + OnapCliConstants.PARAM_INTERACTIVE_PROFILE); + console.addCompleter(strCompleter); + console.setPrompt(OnapCliConstants.PARAM_INTERACTIVE_PROMPT + ":" + OnapCommandRegistrar.getRegistrar().getEnabledProductVersion() + ">"); + } catch (OnapCommandException e) { // NOSONAR + this.print("Failed to load oclip commands," + e.getMessage()); + } + return console; } - - return console; } /** |