Optimize version option output 81/24381/7
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Thu, 12 Oct 2017 14:00:55 +0000 (19:30 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 20 Nov 2017 08:37:57 +0000 (14:07 +0530)
Issue-Id: CLI-66

Change-Id: Ia64adb3e32de0dafc124ce1dbaf0204b43e9ffaf
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
framework/pom.xml
framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
framework/src/main/java/org/onap/cli/fw/conf/Constants.java
framework/src/main/resources/version.info [new file with mode: 0644]

index a1b81e9..2b7aece 100644 (file)
             <artifactId>commons-csv</artifactId>
             <version>1.3</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>1.3.2</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpclient</artifactId>
index e2d3565..1d2c516 100644 (file)
 
 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 <product version>'\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;
     }
 
     /**
index a43dec2..bd41644 100644 (file)
@@ -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 (file)
index 0000000..34f4d96
--- /dev/null
@@ -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 <product>'