Added a "json" report command

This commit is contained in:
John Wiegley 2012-05-18 01:38:39 -06:00
parent a38ed141c1
commit 7e8ba51cd0
4 changed files with 27 additions and 6 deletions

View file

@ -74,7 +74,14 @@ void format_ptree::flush()
put_post(pt, *post);
}
property_tree::write_xml(out, pt);
switch (format) {
case FORMAT_XML:
property_tree::write_xml(out, pt);
break;
case FORMAT_JSON:
property_tree::write_json(out, pt);
break;
}
}
void format_ptree::operator()(post_t& post)

View file

@ -74,8 +74,14 @@ protected:
std::deque<xact_t *> transactions;
public:
format_ptree(report_t& _report) : report(_report) {
TRACE_CTOR(format_ptree, "report&");
enum format_t {
FORMAT_XML,
FORMAT_JSON
} format;
format_ptree(report_t& _report, format_t _format = FORMAT_XML)
: report(_report), format(_format) {
TRACE_CTOR(format_ptree, "report&, format_t");
}
virtual ~format_ptree() {
TRACE_DTOR(format_ptree);

View file

@ -1602,11 +1602,16 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
}
break;
case 'j':
if (is_eq(p, "json"))
return POSTS_REPORTER(new format_ptree(*this,
format_ptree::FORMAT_JSON));
break;
case 'o':
if (is_eq(p, "org")) {
if (is_eq(p, "org"))
return POSTS_REPORTER(new posts_to_org_table
(*this, maybe_format(HANDLER(prepend_format_))));
}
break;
case 'p':
@ -1649,7 +1654,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
if (is_eq(p, "xact"))
return WRAP_FUNCTOR(xact_command);
else if (is_eq(p, "xml"))
return POSTS_REPORTER(new format_ptree(*this));
return POSTS_REPORTER(new format_ptree(*this,
format_ptree::FORMAT_XML));
break;
}
break;

View file

@ -419,6 +419,8 @@ value_t select_command(call_scope_t& args)
}
else if (arg == "xml") {
}
else if (arg == "json") {
}
else if (arg == "emacs") {
}
else if (arg == "org") {