Add getNoOfRows in Results object 81/26381/1
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Fri, 15 Dec 2017 19:37:35 +0000 (01:07 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Fri, 15 Dec 2017 19:37:35 +0000 (01:07 +0530)
Issue-ID: CLI-66

Change-Id: I89fa87019c63504e8f8ceb4f052f12e62941bc3a
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java
main/src/main/java/org/onap/cli/main/OnapCli.java

index 3544fd7..0b9f9be 100644 (file)
@@ -171,6 +171,17 @@ public class OnapCommandResult {
         this.isDebug = isDebug;
     }
 
+    public int getNumberOfRows() {
+        int noOfRecords = 0;
+
+        for (OnapCommandResultAttribute cols : this.records) {
+            if (cols != null && noOfRecords < cols.getValues().size()) {
+                noOfRecords = cols.getValues().size();
+            }
+        }
+
+        return noOfRecords;
+    }
     /**
      * Helps to print the result based on the type.
      *
index 149fd95..65edfc1 100644 (file)
@@ -56,12 +56,19 @@ public class OnapCli {
 
     private List<String> args = new ArrayList<>();
 
+    private String product = null;
+
     private int exitCode = -1;
 
     public OnapCli(String[] args) {
         this.args = Arrays.asList(args);
     }
 
+    public OnapCli(String product, String[] args) {
+        this(args);
+        this.product = product;
+    }
+
     private void exitSuccessfully() {
         this.exitCode = OnapCliConstants.EXIT_SUCCESS;
     }
@@ -323,7 +330,11 @@ public class OnapCli {
         OnapCommand cmd;
         if (!args.isEmpty()) {
             try {
-                cmd = OnapCommandRegistrar.getRegistrar().get(args.get(0));
+                if (this.product != null) {
+                    cmd = OnapCommandRegistrar.getRegistrar().get(args.get(0), this.product);
+                } else {
+                    cmd = OnapCommandRegistrar.getRegistrar().get(args.get(0));
+                }
             } catch (Exception e) {
                 this.print(e);
                 this.exitFailure();