diff options
author | Kanagaraj Manickam <kanagaraj.manickam@huawei.com> | 2017-09-05 16:34:03 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-09-05 16:34:03 +0000 |
commit | 8baba5cddb6dce7932872ec6e2709c28953c5c05 (patch) | |
tree | 16911f3b25f5388c327d14e7f98ca15c1d0149f8 | |
parent | 6898144bb42b5663e6cbfb7166d31c67a3c1665a (diff) | |
parent | 60e988d324475b22fb273b0e1cba7a1481fa0082 (diff) |
Merge changes I70ca564c,I502ca257
* changes:
Add set unset directive
Make the cli zip download consistent
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | deployment/docker/src/main/docker/Dockerfile | 8 | ||||
-rw-r--r-- | deployment/http/web/index.html | 2 | ||||
-rw-r--r-- | deployment/http/web/occ.html | 16 | ||||
-rw-r--r-- | framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java | 2 | ||||
-rw-r--r-- | main/src/main/java/org/onap/cli/main/OnapCli.java | 98 | ||||
-rw-r--r-- | main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java | 10 | ||||
-rw-r--r-- | main/src/main/resources/onap-readme.txt | 8 | ||||
-rw-r--r-- | main/src/test/java/org/onap/cli/main/OnapCliMainTest.java | 3 |
9 files changed, 142 insertions, 17 deletions
@@ -16,7 +16,13 @@ Type **onap <command>** from linux console. To Run in Interactive mode -------------------------- -Type **onap** from linux console +Type **onap** from linux console. + +And use the directive set to set the values for following parameters: + +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 Set the product version ------------------------ @@ -29,6 +35,10 @@ typing **use <product-version>** Run *onap [-v|--version]* to see the CLI and available product version details +Set the parameter values +------------------------ +Use the directive 'set' for setting the values for parameters and 'unset' for un-seting the values. + Help ---- *onap [-h|--help]* diff --git a/deployment/docker/src/main/docker/Dockerfile b/deployment/docker/src/main/docker/Dockerfile index 8717fb3d..61ecd505 100644 --- a/deployment/docker/src/main/docker/Dockerfile +++ b/deployment/docker/src/main/docker/Dockerfile @@ -3,7 +3,7 @@ FROM ubuntu:14.04 #installation RUN apt-get update RUN apt-get update && apt-get install -y software-properties-common -RUN sudo -E add-apt-repository ppa:openjdk-r/ppa && apt-get update && apt-get install -y openjdk-8-jdk && apt-get install -y lighttpd && apt-get install -y git curl +RUN sudo -E add-apt-repository ppa:openjdk-r/ppa && apt-get update && apt-get install -y openjdk-8-jdk && apt-get install -y lighttpd && apt-get install -y git curl && apt-get install -y pandoc RUN cd /tmp && curl -O https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz && tar -xvf go1.9.linux-amd64.tar.gz RUN mkdir -p /tmp/gotty && \ GOPATH=/tmp/gotty /tmp/go/bin/go get github.com/yudai/gotty && \ @@ -28,9 +28,13 @@ RUN ln ./bin/onap.sh /usr/sbin/onap RUN if [ ! -d ./data ]; then mkdir ./data; fi RUN if [ ! -d ./onap-cli-schema ]; then mkdir ./onap-cli-schema; fi +RUN pandoc -t plain $ONAP_CLI_HOME/docs/README.md > $ONAP_CLI_HOME/docs/onap-readme.txt + COPY ./STAGE/http/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf COPY ./STAGE/http/web /var/www-data/servers/onap-cli/ -COPY ./STAGE/installer/*.zip /var/www-data/servers/onap-cli/ + +COPY ./STAGE/installer/cli-*.zip /var/www-data/servers/onap-cli/onap-cli.zip + RUN if [ ! -f /var/log/lighttpd/access.log ]; then touch /var/log/lighttpd/access.log; fi COPY ./STAGE/http/lighttpd/10-proxy.conf /etc/lighttpd/conf-enabled/ RUN cp /etc/lighttpd/conf-available/10-accesslog.conf /etc/lighttpd/conf-enabled/ diff --git a/deployment/http/web/index.html b/deployment/http/web/index.html index ea2491a9..768dcc44 100644 --- a/deployment/http/web/index.html +++ b/deployment/http/web/index.html @@ -33,5 +33,5 @@ typing <strong>use <product-version></strong></p> <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> +<p style="color:red">Please download ONAP CLI <a href="./onap-cli.zip">here</a></p> </body></html>
\ No newline at end of file diff --git a/deployment/http/web/occ.html b/deployment/http/web/occ.html new file mode 100644 index 00000000..de2daee5 --- /dev/null +++ b/deployment/http/web/occ.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <title>OCC</title> + <link rel="icon" type="image/png" href="./onap-cli.png"> + <link rel="stylesheet" href="./css/index.css" /> + <link rel="stylesheet" href="./css/xterm.css" /> + <link rel="stylesheet" href="./css/xterm_customize.css" /> + </head> + <body> + <div id="terminal"></div> + <script src="./auth_token.js"></script> + <script src="./config.js"></script> + <script src="./js/gotty-bundle.js"></script> + </body> +</html>
\ No newline at end of file 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 a58cfd54..424d26ca 100644 --- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java +++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java @@ -320,7 +320,7 @@ public class OnapCommandRegistrar { } try { - return "\n\nOnap sub-commands:\n" + help.print() + (isEnabledProductVersionOnly ? "" : "\n" + this.getVersion()); + return "\n\nCommands:\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 b52d89d7..52922277 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -16,13 +16,26 @@ package org.onap.cli.main; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.commons.io.IOUtils; import org.onap.cli.fw.OnapCommand; import org.onap.cli.fw.OnapCommandRegistrar; +import org.onap.cli.fw.conf.Constants; import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.error.OnapCommandHelpFailed; import org.onap.cli.fw.error.OnapCommandWarning; import org.onap.cli.fw.input.OnapCommandParameter; import org.onap.cli.fw.output.OnapCommandResult; +import org.onap.cli.fw.output.OnapCommandResultAttribute; +import org.onap.cli.fw.output.OnapCommandResultAttributeScope; +import org.onap.cli.fw.output.PrintDirection; +import org.onap.cli.fw.output.ResultType; import org.onap.cli.main.conf.OnapCliConstants; import org.onap.cli.main.interactive.StringCompleter; import org.onap.cli.main.utils.OnapCliUtils; @@ -30,11 +43,6 @@ import org.onap.cli.main.utils.OnapCliUtils; import jline.TerminalFactory; import jline.console.ConsoleReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - /** * Onap Command Line Interface (CLI). * @@ -42,6 +50,7 @@ import java.util.List; public class OnapCli { private List<String> args = new ArrayList<>(); + Map<String, String> paramCache = new HashMap<>(); private int exitCode = -1; @@ -112,6 +121,50 @@ public class OnapCli { } } + private String getDirectiveHelp() throws OnapCommandHelpFailed { + OnapCommandResult help = new OnapCommandResult(); + help.setType(ResultType.TABLE); + help.setPrintDirection(PrintDirection.LANDSCAPE); + + OnapCommandResultAttribute attr = new OnapCommandResultAttribute(); + attr.setName(Constants.NAME.toUpperCase()); + attr.setDescription(Constants.DESCRIPTION); + attr.setScope(OnapCommandResultAttributeScope.SHORT); + help.getRecords().add(attr); + + OnapCommandResultAttribute attrDesc = new OnapCommandResultAttribute(); + attrDesc.setName(Constants.DESCRIPTION.toUpperCase()); + attrDesc.setDescription(Constants.DESCRIPTION); + attrDesc.setScope(OnapCommandResultAttributeScope.SHORT); + help.getRecords().add(attrDesc); + + attr.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_CLEAR); + attrDesc.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_CLEAR_MSG); + + attr.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_EXIT); + attrDesc.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_EXIT_MSG); + + attr.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_VERSION); + attrDesc.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_VERSION_MSG); + + attr.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_USE); + attrDesc.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_USE_MSG); + + attr.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_SET); + attrDesc.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_SET_MSG); + + attr.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_UNSET); + attrDesc.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_UNSET_MSG); + + attr.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_HELP); + attrDesc.getValues().add(OnapCliConstants.PARAM_INTERACTIVE_HELP_MSG); + + try { + return "\n\nDirectives:\n" + help.print(); + } catch (OnapCommandException e) { + throw new OnapCommandHelpFailed(e); + } + } /** * Handles Interactive Mode. */ @@ -122,9 +175,9 @@ public class OnapCli { OnapCommandRegistrar.getRegistrar().setInteractiveMode(true); console = createConsoleReader(); String line = null; + while ((line = console.readLine()) != null) { - if (OnapCliConstants.PARAM_INTERACTIVE_EXIT.equalsIgnoreCase(line) - || OnapCliConstants.PARAM_INTERACTIVE_BYE.equalsIgnoreCase(line)) { + if (OnapCliConstants.PARAM_INTERACTIVE_EXIT.equalsIgnoreCase(line)) { break; } else if (OnapCliConstants.PARAM_INTERACTIVE_CLEAR.equalsIgnoreCase(line)) { console.clearScreen(); @@ -148,17 +201,38 @@ public class OnapCli { } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_HELP)) { try { this.print(OnapCommandRegistrar.getRegistrar().getHelpForEnabledProductVersion()); + this.print(this.getDirectiveHelp()); } catch (OnapCommandException e) { this.print(e); } } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_VERSION)) { this.args = Arrays.asList(new String [] {this.getLongOption(OnapCliConstants.PARAM_VERSION_LONG)}); handleVersion(); + } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_SET)) { + if (args.size() > 1) { + String [] paramEntry = args.get(1).trim().split("="); + if (paramEntry.length >= 2) { + this.paramCache.put(paramEntry[0].trim(), paramEntry[1].trim()); + } else { + this.print("Please use it in the form of 'set param-name=param-value'"); + } + } else { + this.print(this.paramCache.toString()); + } + } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_UNSET)) { + if (args.size() > 1) { + for (int i = 1; i <args.size(); i++) { + if (this.paramCache.containsKey(args.get(i))) { + this.paramCache.remove(args.get(i)); + } + } + } } else { if (args.size() == 1 && args.get(0).trim().isEmpty()) { //Ignore blanks // NOSONAR continue; } + handleCommand(); } } @@ -195,7 +269,9 @@ public class OnapCli { OnapCliConstants.PARAM_INTERACTIVE_CLEAR, OnapCliConstants.PARAM_INTERACTIVE_USE, OnapCliConstants.PARAM_INTERACTIVE_HELP, - OnapCliConstants.PARAM_INTERACTIVE_VERSION); + OnapCliConstants.PARAM_INTERACTIVE_VERSION, + OnapCliConstants.PARAM_INTERACTIVE_SET, + OnapCliConstants.PARAM_INTERACTIVE_UNSET); console.addCompleter(strCompleter); console.setPrompt(OnapCliConstants.PARAM_INTERACTIVE_PROMPT); } catch (OnapCommandException e) { // NOSONAR @@ -236,6 +312,12 @@ public class OnapCli { } } + for (OnapCommandParameter param: cmd.getParameters()) { + if (this.paramCache.containsKey(param.getLongOption())) { + param.setValue(this.paramCache.get(param.getLongOption())); + } + } + OnapCliUtils.populateParams(cmd.getParameters(), args); OnapCommandResult result = cmd.execute(); this.print(result.getDebugInfo()); 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 dfb20c96..2ce12f33 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 @@ -29,11 +29,19 @@ public final class OnapCliConstants { 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_EXIT_MSG = "To exit from the session."; public static final String PARAM_INTERACTIVE_CLEAR = "clear"; + public static final String PARAM_INTERACTIVE_CLEAR_MSG = "To clear the screen"; public static final String PARAM_INTERACTIVE_USE = "use"; + public static final String PARAM_INTERACTIVE_USE_MSG = "To set the current product version, more details please check version"; public static final String PARAM_INTERACTIVE_HELP = "help"; + public static final String PARAM_INTERACTIVE_HELP_MSG = "To get the help details of supported commands"; public static final String PARAM_INTERACTIVE_VERSION = "version"; + public static final String PARAM_INTERACTIVE_VERSION_MSG = "To see the version details"; + public static final String PARAM_INTERACTIVE_SET = "set"; + public static final String PARAM_INTERACTIVE_SET_MSG = "To set the parameter values. Once its set, will be available for all commands in current session."; + public static final String PARAM_INTERACTIVE_UNSET = "unset"; + public static final String PARAM_INTERACTIVE_UNSET_MSG = "To unset the parameter value in current session."; 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 1784a348..668d7584 100644 --- a/main/src/main/resources/onap-readme.txt +++ b/main/src/main/resources/onap-readme.txt @@ -1,5 +1,13 @@ 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: 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 a94252ee..05dd7d4c 100644 --- a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java +++ b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java @@ -131,9 +131,6 @@ public class OnapCliMainTest { mockConsole("exit"); cli.handleInteractive(); - mockConsole("bye"); - cli.handleInteractive(); - mockConsole("clear"); try { cli.handleInteractive(); |