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 --- .../java/org/onap/cli/fw/OnapCommandRegistrar.java | 26 +++++++++++----------- .../main/java/org/onap/cli/fw/conf/Constants.java | 5 +++++ 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'framework/src/main/java/org/onap') 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() { } -- cgit 1.2.3-korg