Greatly improved output from the "format" command

It now shows the formatted result against a sample entry, similar to
what "parse" now does.
This commit is contained in:
John Wiegley 2009-02-13 19:25:15 -04:00
parent b345a45c9b
commit a9061811ce
2 changed files with 46 additions and 24 deletions

View file

@ -43,15 +43,15 @@ void format_t::element_t::dump(std::ostream& out) const
case EXPR: out << " EXPR"; break; case EXPR: out << " EXPR"; break;
} }
out << " flags: " << flags(); out << " flags: 0x" << std::hex << int(flags());
out << " min: "; out << " min: ";
out << std::right; out << std::right;
out.width(2); out.width(2);
out << int(min_width); out << std::dec << int(min_width);
out << " max: "; out << " max: ";
out << std::right; out << std::right;
out.width(2); out.width(2);
out << int(max_width); out << std::dec << int(max_width);
switch (type) { switch (type) {
case STRING: out << " str: '" << chars << "'" << std::endl; break; case STRING: out << " str: '" << chars << "'" << std::endl; break;

View file

@ -34,17 +34,9 @@
namespace ledger { namespace ledger {
value_t parse_command(call_scope_t& args) namespace {
{ xact_t * get_sample_xact(report_t& report)
string arg = join_args(args); {
if (arg.empty()) {
throw std::logic_error("Usage: parse TEXT");
return 1L;
}
report_t& report(find_scope<report_t>(args));
std::ostream& out(report.output_stream);
{ {
string str; string str;
{ {
@ -56,6 +48,9 @@ value_t parse_command(call_scope_t& args)
str = buf.str(); str = buf.str();
} }
std::ostream& out(report.output_stream);
out << "--- Context is first transaction of the following entry ---" out << "--- Context is first transaction of the following entry ---"
<< std::endl << str << std::endl; << std::endl << str << std::endl;
{ {
@ -65,7 +60,22 @@ value_t parse_command(call_scope_t& args)
} }
} }
entry_t * first = report.session.journal->entries.front(); entry_t * first = report.session.journal->entries.front();
xact_t * xact = first->xacts.front(); return first->xacts.front();
}
}
value_t parse_command(call_scope_t& args)
{
string arg = join_args(args);
if (arg.empty()) {
throw std::logic_error("Usage: parse TEXT");
return 1L;
}
report_t& report(find_scope<report_t>(args));
std::ostream& out(report.output_stream);
xact_t * xact = get_sample_xact(report);
out << "--- Input expression ---" << std::endl; out << "--- Input expression ---" << std::endl;
out << arg << std::endl; out << arg << std::endl;
@ -114,9 +124,21 @@ value_t format_command(call_scope_t& args)
report_t& report(find_scope<report_t>(args)); report_t& report(find_scope<report_t>(args));
std::ostream& out(report.output_stream); std::ostream& out(report.output_stream);
xact_t * xact = get_sample_xact(report);
out << "--- Input format string ---" << std::endl;
out << arg << std::endl << std::endl;
out << "--- Format elements ---" << std::endl;
format_t fmt(arg); format_t fmt(arg);
fmt.dump(out); fmt.dump(out);
out << std::endl << "--- Formatted string ---" << std::endl;
bind_scope_t bound_scope(args, *xact);
out << '"';
fmt.format(out, bound_scope);
out << "\"\n";
return 0L; return 0L;
} }