From 81f15e39c42a2d86d590bbf1622bbd32434ad584 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Thu, 12 Oct 2017 19:30:55 +0530 Subject: Optimize version option output Issue-Id: CLI-66 Change-Id: Ia64adb3e32de0dafc124ce1dbaf0204b43e9ffaf Signed-off-by: Kanagaraj Manickam k00365106 --- framework/pom.xml | 5 +++++ .../java/org/onap/cli/fw/OnapCommandRegistrar.java | 26 +++++++++++----------- .../main/java/org/onap/cli/fw/conf/Constants.java | 5 +++++ framework/src/main/resources/version.info | 7 ++++++ 4 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 framework/src/main/resources/version.info (limited to 'framework') diff --git a/framework/pom.xml b/framework/pom.xml index a1b81e93..2b7aece2 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -56,6 +56,11 @@ commons-csv 1.3 + + org.apache.commons + commons-io + 1.3.2 + org.apache.httpcomponents httpclient 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 e2d35654..1d2c5166 100644 --- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java +++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java @@ -16,14 +16,17 @@ package org.onap.cli.fw; +import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.commons.io.IOUtils; import org.onap.cli.fw.cmd.OnapHttpCommand; import org.onap.cli.fw.conf.Constants; import org.onap.cli.fw.conf.OnapCommandConfg; @@ -278,21 +281,18 @@ public class OnapCommandRegistrar { String configuredProductVersion = this.getEnabledProductVersion(); - String errorNote = ""; - String usageNote = "\n\nTo enable a product version, use one of following methods:" - + "\n 1. set env variable OPEN_CLI_PRODUCT_IN_USE" - + "\n 2. set cli.product.version in open-cli.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() + "."; - + String versionInfo = ""; + try { + versionInfo = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream(Constants.VERSION_INFO)); + } catch (IOException e) { + //Never occurs // NOSONAR } - return "CLI version : " + version + buildTime + "\n" - + "Available product versions: " + this.availableProductVersions.toString() + "\n" - + "Enabled product version : " + configuredProductVersion + "\n" + - errorNote + usageNote; + versionInfo = versionInfo.replaceAll(Constants.VERSION_INFO_PLACE_HOLDER_ENB_PRD_VER, configuredProductVersion); + versionInfo = versionInfo.replaceAll(Constants.VERSION_INFO_PLACE_HOLDER_AVL_PRD_VER, this.availableProductVersions.toString()); + versionInfo = versionInfo.replaceAll(Constants.VERSION_INFO_PLACE_HOLDER_VERSION + "", version + buildTime); + + return versionInfo; } /** diff --git a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java index a43dec2b..bd416446 100644 --- a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java +++ b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java @@ -213,6 +213,11 @@ public class Constants { public static final String CATALOG_SERVICE_BASE_PATH = "catalog-service-base-path"; public static final String CATALOG_SERVICE_HOST_URL = "catalog-service-host-url"; + public static final String VERSION_INFO = "version.info"; + public static final String VERSION_INFO_PLACE_HOLDER_VERSION = "__VERSION__"; + public static final String VERSION_INFO_PLACE_HOLDER_AVL_PRD_VER = "__AVAILABLE_PRODUCT_VERSIONS__"; + public static final String VERSION_INFO_PLACE_HOLDER_ENB_PRD_VER = "__ENABLED_PRODUCT_VERSIONS__"; + private Constants() { } diff --git a/framework/src/main/resources/version.info b/framework/src/main/resources/version.info new file mode 100644 index 00000000..34f4d969 --- /dev/null +++ b/framework/src/main/resources/version.info @@ -0,0 +1,7 @@ +CLI version : __VERSION__ +Available products: __AVAILABLE_PRODUCT_VERSIONS__ +Enabled product : __ENABLED_PRODUCT_VERSIONS__ + +To enable a product , use one of following methods: +1. In scripting mode, Set environment variable OPEN_CLI_PRODUCT_IN_USE +2. In interactive mode, set the directive 'use ' -- cgit 1.2.3-korg