Magnesium platform upgrade
[lispflowmapping.git] / mappingservice / shell / src / main / java / org / opendaylight / lispflowmapping / shell / LispMappings.java
index cd3999f95f4502797f716b15610077c5249b8792..5fee82e831ed6129cb142d863c12339f9bdc4d68 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc.  All rights reserved.
+ * Copyright (c) 2015, 2017 Cisco Systems, Inc.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -9,20 +9,37 @@
 package org.opendaylight.lispflowmapping.shell;
 
 import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMappingShell;
+import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServiceShell;
 
-@Command(scope = "lisp", name = "mappings", description="Print LISP mapping database")
+/**
+ * This class implements the "mappingservice:mappings" Karaf shell command.
+ *
+ * @author Lorand Jakab
+ *
+ */
+@Command(scope = "mappingservice", name = "mappings", description = "Print mapping database")
 public class LispMappings  extends OsgiCommandSupport {
-    private IFlowMappingShell lispShellService;
+    @Option(name = "-d", aliases = "--debug", description = "Debug output", required = false, multiValued = false)
+    private boolean debug;
+
+    private IMappingServiceShell mappingServiceShell;
 
     @Override
+    @SuppressWarnings("checkstyle:RegexpSinglelineJava")
     protected Object doExecute() throws Exception {
-        System.out.print(lispShellService.printMappings());
+        if (mappingServiceShell != null) {
+            if (debug) {
+                System.out.print(mappingServiceShell.printMappings());
+            } else {
+                System.out.print(mappingServiceShell.prettyPrintMappings());
+            }
+        }
         return null;
     }
 
-    public void setLispShellService(IFlowMappingShell lispShellService) {
-        this.lispShellService = lispShellService;
+    public void setMappingServiceShell(IMappingServiceShell mappingServiceShell) {
+        this.mappingServiceShell = mappingServiceShell;
     }
 }