summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-02-02 17:07:05 -0500
committerJohn Wiegley <johnw@newartisans.com>2010-02-02 17:07:05 -0500
commit141308597784f77414032b00f239e0601f9d4d38 (patch)
treecfbe1311abbffc7fd05578f8cf0f8ffdf4120f84
parenta56a1db66294c06c7b9d582f694538a0cb473abf (diff)
downloadfork-ledger-141308597784f77414032b00f239e0601f9d4d38.tar.gz
fork-ledger-141308597784f77414032b00f239e0601f9d4d38.tar.bz2
fork-ledger-141308597784f77414032b00f239e0601f9d4d38.zip
Added a --pivot=TAG option
This is equivalent to the following: --account='"TAG:" + tag(/TAG/)'
-rw-r--r--doc/ledger.114
-rw-r--r--src/chain.cc12
-rw-r--r--src/item.cc38
-rw-r--r--src/report.cc1
-rw-r--r--src/report.h3
5 files changed, 50 insertions, 18 deletions
diff --git a/doc/ledger.1 b/doc/ledger.1
index 92457c48..5a91ceb2 100644
--- a/doc/ledger.1
+++ b/doc/ledger.1
@@ -1,4 +1,4 @@
-.Dd November 13, 2009
+.Dd February 2, 2010
.Dt ledger 1
.Sh NAME
.Nm ledger
@@ -277,20 +277,10 @@ transactions they are contained in. See the manual for more information.
.It Fl \-budget
.It Fl \-by-payee Pq Fl P
.It Fl \-cleared Pq Fl C
-.It Fl \-code-as-account
-.It Fl \-code-as-payee
.It Fl \-collapse Pq Fl n
.It Fl \-collapse-if-zero
.It Fl \-color
.It Fl \-columns Ar INT
-.It Fl \-commodity-as-account
-(Also
-.Fl \-\-comm\-as\-account
-).
-.It Fl \-commodity-as-payee
-(Also
-.Fl \-\-comm\-as\-payee
-).
.It Fl \-cost
See
.Fl \-basis .
@@ -343,12 +333,12 @@ See
.It Fl \-only Ar EXPR
.It Fl \-output Ar FILE Pq Fl o
.It Fl \-pager Ar STR
-.It Fl \-payee-as-account
.It Fl \-payee-width Ar INT
.It Fl \-pending
.It Fl \-percentage Pq Fl \%
.It Fl \-period Ar PERIOD Pq Fl p
.It Fl \-period-sort
+.It Fl \-pivot Ar STR
.It Fl \-plot-amount-format Ar FMT
.It Fl \-plot-total-format Ar FMT
.It Fl \-price Pq Fl I
diff --git a/src/chain.cc b/src/chain.cc
index 113a71d8..ecb39e0b 100644
--- a/src/chain.cc
+++ b/src/chain.cc
@@ -158,11 +158,21 @@ post_handler_ptr chain_post_handlers(report_t& report,
report.session.journal->master,
report.HANDLER(date_).str(),
report));
- if (report.HANDLED(account_))
+
+ if (report.HANDLED(account_)) {
handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT,
report.session.journal->master,
report.HANDLER(account_).str(),
report));
+ }
+ else if (report.HANDLED(pivot_)) {
+ string pivot = report.HANDLER(pivot_).str();
+ pivot = string("\"") + pivot + ":\" + tag(/" + pivot + "/)";
+ handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT,
+ report.session.journal->master, pivot,
+ report));
+ }
+
if (report.HANDLED(payee_))
handler.reset(new transfer_details(handler, transfer_details::SET_PAYEE,
report.session.journal->master,
diff --git a/src/item.cc b/src/item.cc
index f86b8ec8..0e596f33 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -238,11 +238,39 @@ namespace {
return false;
}
- value_t get_tag(call_scope_t& scope) {
- in_context_t<item_t> env(scope, "s");
- if (optional<string> value = env->get_tag(env.get<string>(0)))
- return string_value(*value);
- return string_value(empty_string);
+ value_t get_tag(call_scope_t& args) {
+ item_t& item(find_scope<item_t>(args));
+ optional<string> str;
+
+ if (args.size() == 1) {
+ if (args[0].is_string())
+ str = item.get_tag(args[0].as_string());
+ else if (args[0].is_mask())
+ str = item.get_tag(args[0].as_mask());
+ else
+ throw_(std::runtime_error,
+ _("Expected string or mask for argument 1, but received %1")
+ << args[0].label());
+ }
+ else if (args.size() == 2) {
+ if (args[0].is_mask() && args[1].is_mask())
+ str = item.get_tag(args[0].to_mask(), args[1].to_mask());
+ else
+ throw_(std::runtime_error,
+ _("Expected masks for arguments 1 and 2, but received %1 and %2")
+ << args[0].label() << args[1].label());
+ }
+ else if (args.size() == 0) {
+ throw_(std::runtime_error, _("Too few arguments to function"));
+ }
+ else {
+ throw_(std::runtime_error, _("Too many arguments to function"));
+ }
+
+ if (str)
+ return string_value(*str);
+ else
+ return string_value(empty_string);
}
value_t get_pathname(item_t& item) {
diff --git a/src/report.cc b/src/report.cc
index ea02d14f..fa71e584 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -873,6 +873,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(percent);
else OPT_(period_);
else OPT_ALT(sort_xacts_, period_sort_);
+ else OPT(pivot_);
else OPT(plot_amount_format_);
else OPT(plot_total_format_);
else OPT(price);
diff --git a/src/report.h b/src/report.h
index 75f3b1ff..08819e23 100644
--- a/src/report.h
+++ b/src/report.h
@@ -273,6 +273,7 @@ public:
HANDLER(pending).report(out);
HANDLER(percent).report(out);
HANDLER(period_).report(out);
+ HANDLER(pivot_).report(out);
HANDLER(plot_amount_format_).report(out);
HANDLER(plot_total_format_).report(out);
HANDLER(prepend_format_).report(out);
@@ -715,6 +716,8 @@ public:
string_value(text.as_string() + " " + str()));
});
+ OPTION(report_t, pivot_);
+
OPTION__(report_t, plot_amount_format_, CTOR(report_t, plot_amount_format_) {
on(none,
"%(format_date(date, \"%Y-%m-%d\")) %(quantity(scrub(display_amount)))\n");