summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Mick <dan.mick@inktank.com>2013-07-23 17:23:50 -0700
committerDan Mick <dan.mick@inktank.com>2013-07-25 22:18:09 -0700
commitc7c4c23e5faea2182b8f9d18d12a31608e428f28 (patch)
treef93a7777f5fd12cbcf80cdf9c0fe23ab38643a12
parent3f598e8c65731c3451c1aecf8ec0925e34b0bec8 (diff)
downloadceph-c7c4c23e5faea2182b8f9d18d12a31608e428f28.tar.gz
Formatter, admin_socket: make default formatter be json-pretty
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>
-rw-r--r--src/common/Formatter.cc14
-rw-r--r--src/common/Formatter.h2
-rw-r--r--src/common/admin_socket.cc11
3 files changed, 11 insertions, 16 deletions
diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc
index 357b287fe32..7362684c070 100644
--- a/src/common/Formatter.cc
+++ b/src/common/Formatter.cc
@@ -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;
diff --git a/src/common/Formatter.h b/src/common/Formatter.h
index 8775c0cf9df..c62a8303ce1 100644
--- a/src/common/Formatter.h
+++ b/src/common/Formatter.h
@@ -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:
diff --git a/src/common/admin_socket.cc b/src/common/admin_socket.cc
index 5ebb3e040db..4afd685b72a 100644
--- a/src/common/admin_socket.cc
+++ b/src/common/admin_socket.cc
@@ -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();