From: Kanagaraj Manickam k00365106 Date: Thu, 31 Aug 2017 10:03:29 +0000 (+0530) Subject: Make interactive mode as default X-Git-Tag: 1.0.0-Amsterdam~179 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=e35db04d37e98688c20c6f42fff0c5ce892aa728;p=cli.git Make interactive mode as default CLI-37 Change-Id: Ic1ea32d4d38a46652de3fe7840391e76bc35a934 Signed-off-by: Kanagaraj Manickam k00365106 --- diff --git a/README.md b/README.md index b1ef55d1..29f78d75 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,45 @@ -Onap Command-line interface (CLI). +ONAP Command-line interface (CLI) +================================== -One Command to command whole Onap !! It provides the unified commands -to access and operate Onap functionalities. To use this CLI, please -configure the following environment variables: +**One Command to command whole Onap !!** -1. ONAP_HOST_URL - Onap Micro service bus(MSB) URL or a service URL -2. ONAP_USERNAME - Onap user name -3. ONAP_PASSWORD - Onap user password +Provides unified commands to operate ONAP from Linux console. +Configure the following environment variables, before using it: -To know the CLI version, type onap [-v|--version] -To know the CLI usage, type onap [-h|--help] -To know the usage of sub commands, type onap [-h|--help] +1. **ONAP_HOST_URL** - Onap Micro service bus(MSB) URL or a service URL +2. **ONAP_USERNAME** - Onap user name +3. **ONAP_PASSWORD** - Onap user password +To Run a command +----------------- +Type **onap ** from linux console. + +To Run in Interactive mode +-------------------------- +Type **onap** from linux console + +Set the product version +------------------------ +CLI framework is enhanced to handle multiple product versions at same +time. so to choose the product version, set evironment variable +**CLI_PROUDCT_VERSION**. + +NOTE: In interactive mode, product version can be selected using +typing **use ** + +Run *onap [-v|--version]* to see the CLI and available product version details + +Help +---- +*onap [-h|--help]* +*onap [-h|--help]* + +Debug Mode +---------- To run in debug mode, set following environment variables: 1. ONAP_CLI_DEBUG - By default its false, otherwise Set to true 2. ONAP_CLI_DEBUG_PORT - By default it is 5005, otherwise set to new TCP port number -To know more, please refer the Onap wiki https://wiki.onap.org +More details +------------- +https://wiki.onap.org \ No newline at end of file diff --git a/deployment/http/web/index.html b/deployment/http/web/index.html index f44cc907..ea2491a9 100644 --- a/deployment/http/web/index.html +++ b/deployment/http/web/index.html @@ -1,10 +1,37 @@ - - - - ONAP CLI - - - -Please download ONAP CLI from here - - + +ONAP CLI +

ONAP Command-line interface (CLI)

+

One Command to command whole Onap !!

+

Provides unified commands to operate ONAP from Linux console.
+Configure the following environment variables, before using it:

+
    +
  1. ONAP_HOST_URL - Onap Micro service bus(MSB) URL or a service URL
  2. +
  3. ONAP_USERNAME - Onap user name
  4. +
  5. ONAP_PASSWORD - Onap user password
  6. +
+

To Run a command

+

Type onap <command> from linux console.

+

To Run in Interactive mode

+

Type onap from linux console

+

Set the product version

+

CLI framework is enhanced to handle multiple product versions at same
+time. so to choose the product version, set evironment variable
+CLI_PROUDCT_VERSION.

+

NOTE: In interactive mode, product version can be selected using
+typing use <product-version>

+

Run onap [-v|–version] to see the CLI and available product version details

+

Help

+

onap [-h|–help]
+onap <command> [-h|–help]

+

Debug Mode

+

To run in debug mode, set following environment variables:

+
    +
  1. ONAP_CLI_DEBUG - By default its false, otherwise Set to true
  2. +
  3. ONAP_CLI_DEBUG_PORT - By default it is 5005, otherwise set to new TCP port number
  4. +
+

More details

+

https://wiki.onap.org

+ +

To download

+

Please download ONAP CLI here

+ \ No newline at end of file diff --git a/deployment/http/web/onap-cli.png b/deployment/http/web/onap-cli.png new file mode 100644 index 00000000..60c3e151 Binary files /dev/null and b/deployment/http/web/onap-cli.png differ diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java index 39f684cc..a58cfd54 100644 --- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java +++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java @@ -238,15 +238,19 @@ public class OnapCommandRegistrar { String configuredProductVersion = OnapCommandConfg.getEnabledProductVersion(); String errorNote = ""; + String usageNote = "\n\nTo enable a product version, use one of following methods:" + + "\n 1. set env variable CLI_PRODUCT_VERSION" + + "\n 2. set cli.product.version in onap.properties" + + "\n 3. in interactive mode, use the directive 'use '\n"; + if (!this.availableProductVersions.contains(configuredProductVersion)) { - errorNote = "** CUATION: Please configure the enabled product version to use one of " + this.availableProductVersions.toString() + - ".\nTo enable a product version, use one of following methods:\n\t 1. set env variable CLI_PRODUCT_VERSION" - + "\n\t 2. set cli.product.version in onap.properties \n\t 3. in interactive mode, use the directive 'use '"; + errorNote = "** CUATION: Please configure the enabled product version to use one of " + this.availableProductVersions.toString() + "."; + } return "CLI version : " + version + "\n" + "Available product versions: " + this.availableProductVersions.toString() + "\n" + "Enabled product version : " + configuredProductVersion + "\n" + - errorNote; + errorNote + usageNote; } /** @@ -257,6 +261,14 @@ public class OnapCommandRegistrar { * Help cmd failed */ public String getHelp() throws OnapCommandHelpFailed { + return this.getHelp(false); + } + + public String getHelpForEnabledProductVersion() throws OnapCommandHelpFailed { + return this.getHelp(true); + } + + private String getHelp(boolean isEnabledProductVersionOnly) throws OnapCommandHelpFailed { OnapCommandResult help = new OnapCommandResult(); help.setType(ResultType.TABLE); help.setPrintDirection(PrintDirection.LANDSCAPE); @@ -268,10 +280,12 @@ public class OnapCommandRegistrar { help.getRecords().add(attr); OnapCommandResultAttribute attrVer = new OnapCommandResultAttribute(); - attrVer.setName(Constants.PRODUCT_VERSION.toUpperCase()); - attrVer.setDescription(Constants.DESCRIPTION); - attrVer.setScope(OnapCommandResultAttributeScope.SHORT); - help.getRecords().add(attrVer); + if (!isEnabledProductVersionOnly) { + attrVer.setName(Constants.PRODUCT_VERSION.toUpperCase()); + attrVer.setDescription(Constants.DESCRIPTION); + attrVer.setScope(OnapCommandResultAttributeScope.SHORT); + help.getRecords().add(attrVer); + } OnapCommandResultAttribute attrSrv = new OnapCommandResultAttribute(); attrSrv.setName(Constants.SERVICE.toUpperCase()); @@ -285,13 +299,19 @@ public class OnapCommandRegistrar { attrDesc.setScope(OnapCommandResultAttributeScope.SHORT); help.getRecords().add(attrDesc); - for (String cmdName : OnapCommandUtils.sort(this.listCommands())) { + for (String cmdName : isEnabledProductVersionOnly ? OnapCommandUtils.sort(this.listCommandsForEnabledProductVersion()) : OnapCommandUtils.sort(this.listCommands())) { OnapCommand cmd; try { - String []cmdVer = cmdName.split(":"); - cmd = this.get(cmdVer[0], cmdVer[1]); - attr.getValues().add(cmdVer[0]); - attrVer.getValues().add(cmdVer[1]); + if (!isEnabledProductVersionOnly) { + String []cmdVer = cmdName.split(":"); + cmd = this.get(cmdVer[0], cmdVer[1]); + attr.getValues().add(cmdVer[0]); + attrVer.getValues().add(cmdVer[1]); + } else { + cmd = this.get(cmdName); + attr.getValues().add(cmdName); + } + attrSrv.getValues().add(cmd.printVersion()); attrDesc.getValues().add(cmd.getDescription()); } catch (OnapCommandException e) { @@ -300,7 +320,7 @@ public class OnapCommandRegistrar { } try { - return "\n\nOnap sub-commands:\n" + help.print() + "\n" + this.getVersion(); + return "\n\nOnap sub-commands:\n" + help.print() + (isEnabledProductVersionOnly ? "" : "\n" + this.getVersion()); } catch (OnapCommandException e) { throw new OnapCommandHelpFailed(e); } 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();