From: Kanagaraj Manickam k00365106 Date: Tue, 5 Sep 2017 06:40:41 +0000 (+0530) Subject: Add set unset directive X-Git-Tag: 1.0.0-Amsterdam~173^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=60e988d324475b22fb273b0e1cba7a1481fa0082;p=cli.git Add set unset directive CLI-2 Change-Id: I70ca564cc2c41508bb209b5fae54104aba13a8be Signed-off-by: Kanagaraj Manickam k00365106 --- diff --git a/README.md b/README.md index 29f78d75..07cae08d 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,13 @@ Type **onap ** 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 ** 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/http/web/occ.html b/deployment/http/web/occ.html index e0a18d91..de2daee5 100644 --- a/deployment/http/web/occ.html +++ b/deployment/http/web/occ.html @@ -1,16 +1,16 @@ - - - - OCC - - - - - - -
- - - - + + + + OCC + + + + + + +
+ + + + \ 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 args = new ArrayList<>(); + Map 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