From e35db04d37e98688c20c6f42fff0c5ce892aa728 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Thu, 31 Aug 2017 15:33:29 +0530 Subject: Make interactive mode as default CLI-37 Change-Id: Ic1ea32d4d38a46652de3fe7840391e76bc35a934 Signed-off-by: Kanagaraj Manickam k00365106 --- main/src/main/java/org/onap/cli/main/OnapCli.java | 41 ++++++++-------------- .../org/onap/cli/main/conf/OnapCliConstants.java | 3 +- main/src/main/resources/onap-readme.txt | 3 -- .../java/org/onap/cli/main/OnapCliMainTest.java | 9 +---- 4 files changed, 17 insertions(+), 39 deletions(-) (limited to 'main/src') 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 528c3e18..ac63fdfa 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -82,11 +82,9 @@ public class OnapCli { */ public void handleHelp() { try { - // By default, it prints help - if ((args.isEmpty()) - || ((args.size() == 1) && (this.getLongOption(OnapCliConstants.PARAM_HELP_LOGN).equals(args.get(0)) - || this.getShortOption(OnapCliConstants.PARAM_HELP_SHORT).equals(args.get(0))))) { - this.print(IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("README.md"))); + if ((args.size() == 1) && (this.getLongOption(OnapCliConstants.PARAM_HELP_LOGN).equals(args.get(0)) + || this.getShortOption(OnapCliConstants.PARAM_HELP_SHORT).equals(args.get(0)))) { + this.print(IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("onap-readme.txt"))); String help = OnapCommandRegistrar.getRegistrar().getHelp(); this.print(help); this.exitSuccessfully(); @@ -115,11 +113,10 @@ public class OnapCli { } /** - * Handles Interactive Mode. --interactive or -i + * Handles Interactive Mode. */ public void handleInteractive() { // NOSONAR - if (isInteractive()) { - + if (args.isEmpty()) { ConsoleReader console = null; try { OnapCommandRegistrar.getRegistrar().setInteractiveMode(true); @@ -148,10 +145,15 @@ public class OnapCli { this.print(e); } } - - continue; + } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_HELP)) { + try { + this.print(OnapCommandRegistrar.getRegistrar().getHelpForEnabledProductVersion()); + } catch (OnapCommandException e) { + this.print(e); + } + } else { + handleCommand(); } - handleCommand(); } } catch (IOException e) { // NOSONAR this.print("Failed to read console, " + e.getMessage()); @@ -171,20 +173,6 @@ public class OnapCli { } } - /** - * Checks if the command is interactive. - * - * @return boolean - */ - public boolean isInteractive() { - if ((args.size() == 1) && (this.getLongOption(OnapCliConstants.PARAM_INTERACTIVE_LONG).equals(args.get(0)) - || this.getShortOption(OnapCliConstants.PARAM_INTERACTIVE_SHORT).equals(args.get(0)))) { - return true; - } - - return false; - } - /** * Creates console reader object. * @@ -198,7 +186,8 @@ public class OnapCli { StringCompleter strCompleter = new StringCompleter(OnapCommandRegistrar.getRegistrar().listCommandsForEnabledProductVersion()); strCompleter.add(OnapCliConstants.PARAM_INTERACTIVE_EXIT, OnapCliConstants.PARAM_INTERACTIVE_CLEAR, - OnapCliConstants.PARAM_INTERACTIVE_USE); + OnapCliConstants.PARAM_INTERACTIVE_USE, + OnapCliConstants.PARAM_INTERACTIVE_HELP); console.addCompleter(strCompleter); console.setPrompt(OnapCliConstants.PARAM_INTERACTIVE_PROMPT); } catch (OnapCommandException e) { // NOSONAR diff --git a/main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java b/main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java index 4db26f74..d01aa1e5 100644 --- a/main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java +++ b/main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java @@ -27,13 +27,12 @@ public final class OnapCliConstants { public static final int EXIT_SUCCESS = 0; public static final int EXIT_FAILURE = 1; - public static final String PARAM_INTERACTIVE_SHORT = "i"; - public static final String PARAM_INTERACTIVE_LONG = "interactive"; public static final String PARAM_INTERACTIVE_PROMPT = "onap>"; public static final String PARAM_INTERACTIVE_EXIT = "exit"; public static final String PARAM_INTERACTIVE_BYE = "bye"; public static final String PARAM_INTERACTIVE_CLEAR = "clear"; public static final String PARAM_INTERACTIVE_USE = "use"; + public static final String PARAM_INTERACTIVE_HELP = "help"; public static final String PARAM_INTERACTIVE_ARG_SPLIT_PATTERN = "\\s+"; private OnapCliConstants(){} diff --git a/main/src/main/resources/onap-readme.txt b/main/src/main/resources/onap-readme.txt index 1008737b..1784a348 100644 --- a/main/src/main/resources/onap-readme.txt +++ b/main/src/main/resources/onap-readme.txt @@ -13,6 +13,3 @@ To know the CLI usage, type onap [-h|--help] To know the usage of sub commands, type onap [-h|--help] To know more, please refer the Onap wiki https://wiki.onap.org - -NOTE: This file has been deprecated in amesterdam release and is -replaced by README.md file \ No newline at end of file diff --git a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java index ff4b4362..a94252ee 100644 --- a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java +++ b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java @@ -126,14 +126,7 @@ public class OnapCliMainTest { @Test public void interactiveTest() { - cli = new OnapCli(new String[] { "-i" }); - boolean isInter = cli.isInteractive(); - - assertTrue(isInter); - cli = new OnapCli(new String[] { "--interactive" }); - isInter = cli.isInteractive(); - assertTrue(isInter); - cli.getExitCode(); + cli = new OnapCli(new String[] {}); mockConsole("exit"); cli.handleInteractive(); -- cgit 1.2.3-korg