Skip to content

Commit

Permalink
Merge pull request #519 from mbudde/accounts-prepend-format
Browse files Browse the repository at this point in the history
Add support for --prepend-format in accounts command
  • Loading branch information
jwiegley committed Jan 27, 2018
2 parents 1be23f1 + 6b998ae commit b7b0280
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,23 @@ void format_accounts::operator()(account_t& account)
void report_accounts::flush()
{
std::ostream& out(report.output_stream);
format_t prepend_format;
std::size_t prepend_width;

if (report.HANDLED(prepend_format_)) {
prepend_format.parse_format(report.HANDLER(prepend_format_).str());
prepend_width = report.HANDLED(prepend_width_)
? lexical_cast<std::size_t>(report.HANDLER(prepend_width_).str())
: 0;
}

foreach (accounts_pair& entry, accounts) {
if (prepend_format) {
bind_scope_t bound_scope(report, *entry.first);
out.width(static_cast<std::streamsize>(prepend_width));
out << prepend_format(bound_scope);
}

if (report.HANDLED(count))
out << entry.second << ' ';
out << *entry.first << '\n';
Expand Down
5 changes: 5 additions & 0 deletions test/baseline/opt-prepend-format.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ VMMXX07-Feb-02 RD VMMXX As:Inves:Vanguar:VMMXX 0.350 VMMXX 0.350
VMMXX In:Divid:Vanguar:VMMXX $-0.35 $-0.35
0.350 VMMXX
end test

test accounts --prepend-format "%(account_base) "
VMMXX Assets:Investments:Vanguard:VMMXX
VMMXX Income:Dividends:Vanguard:VMMXX
end test
5 changes: 5 additions & 0 deletions test/baseline/opt-prepend-width.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ test reg --prepend-format "%(account_base) " --prepend-width=10
VMMXX In:Divid:Vanguar:VMMXX $-0.35 $-0.35
0.350 VMMXX
end test

test accounts --prepend-format "%(account_base) " --prepend-width=10
VMMXX Assets:Investments:Vanguard:VMMXX
VMMXX Income:Dividends:Vanguard:VMMXX
end test

0 comments on commit b7b0280

Please sign in to comment.