]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Formatter, admin_socket: make default formatter be json-pretty
authorDan Mick <dan.mick@inktank.com>
Wed, 24 Jul 2013 00:23:50 +0000 (17:23 -0700)
committerDan Mick <dan.mick@inktank.com>
Fri, 26 Jul 2013 05:18:09 +0000 (22:18 -0700)
If not given, default to json-pretty; if given but not equal to one
of the formatter choices, return NULL as before.  Remove defaulting
code in admin_socket.cc in favor of this.

Signed-off-by: Dan Mick <dan.mick@inktank.com>
src/common/Formatter.cc
src/common/Formatter.h
src/common/admin_socket.cc

index 357b287fe3222c966b4c4569ec7680c0fcc84f5c..7362684c070eb1b060fc5cc349707d3f1fb946f3 100644 (file)
@@ -62,15 +62,19 @@ Formatter::~Formatter()
 }
 
 Formatter *
-new_formatter(const std::string &type)
+new_formatter(const std::string type)
 {
-    if (type == "json")
+    std::string mytype = type;
+    if (mytype == "")
+      mytype = "json-pretty";
+
+    if (mytype == "json")
       return new JSONFormatter(false);
-    else if (type == "json-pretty")
+    else if (mytype == "json-pretty")
       return new JSONFormatter(true);
-    else if (type == "xml")
+    else if (mytype == "xml")
       return new XMLFormatter(false);
-    else if (type == "xml-pretty")
+    else if (mytype == "xml-pretty")
       return new XMLFormatter(true);
     else
       return (Formatter *)NULL;
index 8775c0cf9df5c5161b92a1a4783a8d02e2ba1075..c62a8303ce1131238aebdc2ebfd63938f04b9f96 100644 (file)
@@ -60,7 +60,7 @@ class Formatter {
   }
 };
 
-Formatter *new_formatter(const std::string &type);
+Formatter *new_formatter(const std::string type);
 
 class JSONFormatter : public Formatter {
  public:
index 5ebb3e040db8d75821e7f9f7bf863a6305beafa6..4afd685b72acd0c4d47077bc057f9258eb003333 100644 (file)
@@ -322,13 +322,6 @@ bool AdminSocket::do_accept()
   cmd_getval(m_cct, cmdmap, "format", format);
   cmd_getval(m_cct, cmdmap, "prefix", c);
 
-  // we don't do plain here
-  if (format != "json" &&
-      format != "json-pretty" &&
-      format != "xml" &&
-      format != "xml-pretty")
-    format = "json";
-
   string firstword;
   if (c.find(" ") == string::npos)
     firstword = c;
@@ -450,9 +443,7 @@ class HelpHook : public AdminSocketHook {
 public:
   HelpHook(AdminSocket *as) : m_as(as) {}
   bool call(string command, string args, string format, bufferlist& out) {
-    // override format here because help should always be pretty and
-    // predictable
-    Formatter *f = new_formatter("json-pretty");
+    Formatter *f = new_formatter(format);
     f->open_object_section("help");
     for (map<string,string>::iterator p = m_as->m_help.begin();
         p != m_as->m_help.end();