From ee757a5761156fcbcff3d0bd4f6e75bb0931d536 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Mon, 11 Sep 2017 18:39:55 +0530 Subject: CLI profile support invoke CLI with --profile to persist the settings across the sessions. CLI-5 Change-Id: I214334dab11fecdb730c780976d5d9bb2c14509d Signed-off-by: Kanagaraj Manickam k00365106 --- main/src/main/java/org/onap/cli/main/OnapCli.java | 29 +++++++++++++++++++--- .../org/onap/cli/main/conf/OnapCliConstants.java | 3 +++ 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'main') 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 f689830a..71d9cf77 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -118,6 +118,25 @@ public class OnapCli { } } + + /** + * Handles profile. --profile or -c + */ + public void handleProfile() { + try { + if ((args.size() == 2) && (this.getLongOption(OnapCliConstants.PARAM_PROFILE_LONG).equals(args.get(0)) + || this.getShortOption(OnapCliConstants.PARAM_PROFILE_SHORT).equals(args.get(0)))) { + + OnapCommandRegistrar.getRegistrar().setProfile(args.get(1)); + //Make space of interactive mode + this.args = new ArrayList<>(); + } + } catch (Exception e) { + this.print(e); + this.exitFailure(); + } + } + private String getDirectiveHelp() throws OnapCommandHelpFailed { OnapCommandResult help = new OnapCommandResult(); help.setType(ResultType.TABLE); @@ -344,14 +363,18 @@ public class OnapCli { this.handleVersion(); } + if (this.exitCode == -1) { + this.handleProfile(); + } + if (this.exitCode == -1) { this.handleInteractive(); } - if (this.exitCode == -1) { - this.handleCommand(); - } + if (this.exitCode == -1) { + this.handleCommand(); } + } /** * Main method. 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 2ce12f33..337cd41c 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 @@ -24,6 +24,9 @@ public final class OnapCliConstants { public static final String PARAM_VERSION_SHORT = "v"; public static final String PARAM_VERSION_LONG = "version"; + public static final String PARAM_PROFILE_SHORT = "c"; + public static final String PARAM_PROFILE_LONG = "profile"; + public static final int EXIT_SUCCESS = 0; public static final int EXIT_FAILURE = 1; -- cgit 1.2.3-korg