aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-08-31 15:33:29 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-08-31 15:48:26 +0530
commite35db04d37e98688c20c6f42fff0c5ce892aa728 (patch)
tree045c183ddccf4bb4ba4237ab5158a2e706347e4b
parent8de208f3e785f7bf160f4f4413b53bbd91417806 (diff)
Make interactive mode as default
CLI-37 Change-Id: Ic1ea32d4d38a46652de3fe7840391e76bc35a934 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
-rw-r--r--README.md48
-rw-r--r--deployment/http/web/index.html47
-rw-r--r--deployment/http/web/onap-cli.pngbin0 -> 29672 bytes
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java48
-rw-r--r--main/src/main/java/org/onap/cli/main/OnapCli.java41
-rw-r--r--main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java3
-rw-r--r--main/src/main/resources/onap-readme.txt3
-rw-r--r--main/src/test/java/org/onap/cli/main/OnapCliMainTest.java9
8 files changed, 125 insertions, 74 deletions
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 <command> [-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 <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. 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 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>ONAP CLI</title>
- <meta charset="UTF-8">
-</head>
-<body>
-Please download ONAP CLI from <a href="./cli-1.0.0-SNAPSHOT.zip">here</a>
-</body>
-</html>
+<!DOCTYPE html><html><head><link rel="icon" href="./onap-cli.png">
+<meta charset="utf-8"><title>ONAP CLI</title><style></style></head><body id="preview">
+<h1><a id="ONAP_Commandline_interface_CLI_0"></a>ONAP Command-line interface (CLI)</h1>
+<p style="color:blue"><strong>One Command to command whole Onap !!</strong></p>
+<p>Provides unified commands to operate ONAP from Linux console.<br>
+Configure the following environment variables, before using it:</p>
+<ol>
+<li><strong>ONAP_HOST_URL</strong> - Onap Micro service bus(MSB) URL or a service URL</li>
+<li><strong>ONAP_USERNAME</strong> - Onap user name</li>
+<li><strong>ONAP_PASSWORD</strong> - Onap user password</li>
+</ol>
+<h2><a id="To_Run_a_command_12"></a>To Run a command</h2>
+<p>Type <strong>onap &lt;command&gt;</strong> from linux console.</p>
+<h2><a id="To_Run_in_Interactive_mode_16"></a>To Run in Interactive mode</h2>
+<p>Type <strong>onap</strong> from linux console</p>
+<h2><a id="Set_the_product_version_20"></a>Set the product version</h2>
+<p>CLI framework is enhanced to handle multiple product versions at same<br>
+time. so to choose the product version, set evironment variable<br>
+<strong>CLI_PROUDCT_VERSION</strong>.</p>
+<p>NOTE: In interactive mode, product version can be selected using<br>
+typing <strong>use &lt;product-version&gt;</strong></p>
+<p>Run <em>onap [-v|–version]</em> to see the CLI and available product version details</p>
+<h2><a id="Help_31"></a>Help</h2>
+<p><em>onap [-h|–help]</em><br>
+<em>onap &lt;command&gt; [-h|–help]</em></p>
+<h2><a id="Debug_Mode_36"></a>Debug Mode</h2>
+<p>To run in debug mode, set following environment variables:</p>
+<ol>
+<li>ONAP_CLI_DEBUG - By default its false, otherwise Set to true</li>
+<li>ONAP_CLI_DEBUG_PORT - By default it is 5005, otherwise set to new TCP port number</li>
+</ol>
+<h2><a id="More_details_42"></a>More details</h2>
+<p><a href="https://wiki.onap.org">https://wiki.onap.org</a></p>
+
+<h2><a id="Download_42"></a>To download</h2>
+<p style="color:red">Please download ONAP CLI <a href="./cli-1.0.0-SNAPSHOT.zip">here</a></p>
+</body></html> \ 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
--- /dev/null
+++ b/deployment/http/web/onap-cli.png
Binary files 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 <product version>'\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 <product version>'";
+ 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());
@@ -172,20 +174,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.
*
* @return ConsoleReader
@@ -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 <command> [-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();