summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-03-09 03:51:53 -0600
committerJohn Wiegley <johnw@newartisans.com>2012-03-09 03:51:53 -0600
commit59f5ebe2dfe7cc93e36377f0251691e4de7b83b4 (patch)
tree479d00fc71f4c7c12cc6f37c01ab579e2119effb
parentef478079e7836a9817992a8f8982b40ce97eef55 (diff)
downloadfork-ledger-59f5ebe2dfe7cc93e36377f0251691e4de7b83b4.tar.gz
fork-ledger-59f5ebe2dfe7cc93e36377f0251691e4de7b83b4.tar.bz2
fork-ledger-59f5ebe2dfe7cc93e36377f0251691e4de7b83b4.zip
Reworked the way that options are handled
-rw-r--r--doc/ledger.13
-rw-r--r--src/chain.cc11
-rw-r--r--src/draft.cc2
-rw-r--r--src/option.h77
-rw-r--r--src/print.cc17
-rw-r--r--src/pyinterp.h4
-rw-r--r--src/report.cc240
-rw-r--r--src/report.h635
-rw-r--r--src/session.h18
-rw-r--r--test/baseline/opt-no-pager.test0
10 files changed, 468 insertions, 539 deletions
diff --git a/doc/ledger.1 b/doc/ledger.1
index 2fb074cb..a948d5a6 100644
--- a/doc/ledger.1
+++ b/doc/ledger.1
@@ -1,4 +1,4 @@
-.Dd March 7, 2012
+.Dd March 9, 2012
.Dt ledger 1
.Sh NAME
.Nm ledger
@@ -359,6 +359,7 @@ See
.It Fl \-meta-width Ar INT
.It Fl \-monthly Pq Fl M
.It Fl \-no-color
+.It Fl \-no-pager
.It Fl \-no-rounding
.It Fl \-no-titles
.It Fl \-no-total
diff --git a/src/chain.cc b/src/chain.cc
index f8f0aeff..44b3db82 100644
--- a/src/chain.cc
+++ b/src/chain.cc
@@ -88,10 +88,9 @@ post_handler_ptr chain_pre_post_handlers(post_handler_ptr base_handler,
predicate_t(report.HANDLER(forecast_while_).str(),
report.what_to_keep()),
report,
- report.HANDLED(forecast_years_) ?
- static_cast<std::size_t>
- (report.HANDLER(forecast_years_).value.to_long()) :
- 5UL);
+ (report.HANDLED(forecast_years_) ?
+ lexical_cast<std::size_t>
+ (report.HANDLER(forecast_years_).value) : 5UL));
forecast_handler->add_period_xacts(report.session.journal->period_xacts);
handler.reset(forecast_handler);
@@ -137,9 +136,9 @@ post_handler_ptr chain_post_handlers(post_handler_ptr base_handler,
handler.reset
(new truncate_xacts(handler,
report.HANDLED(head_) ?
- report.HANDLER(head_).value.to_int() : 0,
+ lexical_cast<int>(report.HANDLER(head_).value) : 0,
report.HANDLED(tail_) ?
- report.HANDLER(tail_).value.to_int() : 0));
+ lexical_cast<int>(report.HANDLER(tail_).value) : 0));
// display_filter_posts adds virtual posts to the list to account
// for changes in value of commodities, which otherwise would affect
diff --git a/src/draft.cc b/src/draft.cc
index 9abc769e..74a6f4d2 100644
--- a/src/draft.cc
+++ b/src/draft.cc
@@ -522,7 +522,7 @@ value_t xact_command(call_scope_t& args)
xact_t * new_xact = draft.insert(*report.session.journal.get());
// Only consider actual postings for the "xact" command
- report.HANDLER(limit_).on(string("#xact"), "actual");
+ report.HANDLER(limit_).on("#xact", "actual");
if (new_xact)
report.xact_report(post_handler_ptr(new print_xacts(report)), *new_xact);
diff --git a/src/option.h b/src/option.h
index 38431f9d..f892b00e 100644
--- a/src/option.h
+++ b/src/option.h
@@ -61,9 +61,9 @@ protected:
option_t& operator=(const option_t&);
public:
- T * parent;
- value_t value;
- bool wants_arg;
+ T * parent;
+ string value;
+ bool wants_arg;
option_t(const char * _name, const char _ch = '\0')
: name(_name), name_len(std::strlen(name)), ch(_ch),
@@ -94,7 +94,8 @@ public:
out << std::right << desc();
if (wants_arg) {
out << " = ";
- value.print(out, 42);
+ out.width(42);
+ out << value;
} else {
out.width(45);
out << ' ';
@@ -123,43 +124,49 @@ public:
return handled;
}
- string& str() {
+ string str() const {
assert(handled);
- if (! value)
+ if (value.empty())
throw_(std::runtime_error, _("No argument provided for %1") << desc());
- return value.as_string_lval();
+ return value;
}
- string str() const {
- assert(handled);
- if (! value)
- throw_(std::runtime_error, _("No argument provided for %1") << desc());
- return value.as_string();
+ void on(const char * whence) {
+ on(string(whence));
}
+ void on(const optional<string>& whence) {
+ handler_thunk(whence);
- void on_only(const optional<string>& whence) {
handled = true;
source = whence;
}
- void on(const optional<string>& whence, const string& str) {
- on_with(whence, string_value(str));
+
+ void on(const char * whence, const string& str) {
+ on(string(whence), str);
}
- virtual void on_with(const optional<string>& whence,
- const value_t& val) {
+ void on(const optional<string>& whence, const string& str) {
+ string before = value;
+
+ handler_thunk(whence, str);
+
+ if (value == before)
+ value = str;
+
handled = true;
- value = val;
source = whence;
}
void off() {
handled = false;
- value = value_t();
+ value = "";
source = none;
}
- virtual void handler_thunk(call_scope_t&) {}
+ virtual void handler_thunk(const optional<string>& whence) {}
+ virtual void handler_thunk(const optional<string>& whence,
+ const string& str) {}
- virtual void handler(call_scope_t& args) {
+ value_t handler(call_scope_t& args) {
if (wants_arg) {
if (args.size() < 2)
throw_(std::runtime_error, _("No argument provided for %1") << desc());
@@ -167,7 +174,7 @@ public:
throw_(std::runtime_error, _("To many arguments provided for %1") << desc());
else if (! args[0].is_string())
throw_(std::runtime_error, _("Context argument for %1 not a string") << desc());
- on_with(args.get<string>(0), args[1]);
+ on(args.get<string>(0), args.get<string>(1));
}
else if (args.size() < 1) {
throw_(std::runtime_error, _("No argument provided for %1") << desc());
@@ -176,27 +183,18 @@ public:
throw_(std::runtime_error, _("Context argument for %1 not a string") << desc());
}
else {
- on_only(args.get<string>(0));
+ on(args.get<string>(0));
}
-
- handler_thunk(args);
- }
-
- virtual value_t handler_wrapper(call_scope_t& args) {
- handler(args);
return true;
}
virtual value_t operator()(call_scope_t& args) {
if (! args.empty()) {
args.push_front(string_value("?expr"));
- return handler_wrapper(args);
+ return handler(args);
}
else if (wants_arg) {
- if (handled)
- return value;
- else
- return NULL_VALUE;
+ return string_value(value);
}
else {
return handled;
@@ -215,15 +213,16 @@ public:
vartype var ; \
name ## option_t() : option_t<type>(#name), var value
-#define DO() virtual void handler_thunk(call_scope_t&)
-#define DO_(var) virtual void handler_thunk(call_scope_t& var)
+#define DO() virtual void handler_thunk(const optional<string>& whence)
+#define DO_(var) virtual void handler_thunk(const optional<string>& whence, \
+ const string& var)
#define END(name) name ## handler
#define COPY_OPT(name, other) name ## handler(other.name ## handler)
#define MAKE_OPT_HANDLER(type, x) \
- expr_t::op_t::wrap_functor(bind(&option_t<type>::handler_wrapper, x, _1))
+ expr_t::op_t::wrap_functor(bind(&option_t<type>::handler, x, _1))
#define MAKE_OPT_FUNCTOR(type, x) \
expr_t::op_t::wrap_functor(bind(&option_t<type>::operator(), x, _1))
@@ -284,6 +283,10 @@ inline bool is_eq(const char * p, const char * n) {
} \
END(name)
+#define OTHER(name) \
+ parent->HANDLER(name).parent = parent; \
+ parent->HANDLER(name)
+
bool process_option(const string& whence, const string& name, scope_t& scope,
const char * arg, const string& varname);
diff --git a/src/print.cc b/src/print.cc
index c544c4e0..9e52ce95 100644
--- a/src/print.cc
+++ b/src/print.cc
@@ -133,7 +133,7 @@ namespace {
std::size_t columns =
(report.HANDLED(columns_) ?
- static_cast<std::size_t>(report.HANDLER(columns_).value.to_long()) : 80);
+ lexical_cast<std::size_t>(report.HANDLER(columns_).str()) : 80);
if (xact.note)
print_note(out, *xact.note, xact.has_flags(ITEM_NOTE_ON_NEXT_LINE),
@@ -191,8 +191,8 @@ namespace {
unistring name(pbuf.str());
std::size_t account_width =
- (report.HANDLER(account_width_).specified ?
- static_cast<std::size_t>(report.HANDLER(account_width_).value.to_long()) : 36);
+ (report.HANDLED(account_width_) ?
+ lexical_cast<std::size_t>(report.HANDLER(account_width_).str()) : 36);
if (account_width < name.length())
account_width = name.length();
@@ -218,13 +218,14 @@ namespace {
// first.
}
else {
- int amount_width =
- (report.HANDLER(amount_width_).specified ?
- report.HANDLER(amount_width_).value.to_int() : 12);
+ std::size_t amount_width =
+ (report.HANDLED(amount_width_) ?
+ lexical_cast<std::size_t>(report.HANDLER(amount_width_).str()) :
+ 12);
std::ostringstream amt_str;
- value_t(post->amount).print(amt_str, amount_width, -1,
- AMOUNT_PRINT_RIGHT_JUSTIFY |
+ value_t(post->amount).print(amt_str, static_cast<int>(amount_width),
+ -1, AMOUNT_PRINT_RIGHT_JUSTIFY |
AMOUNT_PRINT_NO_COMPUTED_ANNOTATIONS);
amt = amt_str.str();
}
diff --git a/src/pyinterp.h b/src/pyinterp.h
index 8699f69d..556b1563 100644
--- a/src/pyinterp.h
+++ b/src/pyinterp.h
@@ -136,8 +136,8 @@ public:
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
- OPTION_(python_interpreter_t, import_, DO_(args) {
- parent->import_option(args.get<string>(1));
+ OPTION_(python_interpreter_t, import_, DO_(str) {
+ parent->import_option(str);
});
};
diff --git a/src/report.cc b/src/report.cc
index 02fd7c18..110d33ee 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -59,7 +59,7 @@ void report_t::normalize_options(const string& verb)
#ifdef HAVE_ISATTY
if (! HANDLED(force_color)) {
if (! HANDLED(no_color) && isatty(STDOUT_FILENO))
- HANDLER(color).on_only(string("?normalize"));
+ HANDLER(color).on("?normalize");
if (HANDLED(color) && ! isatty(STDOUT_FILENO))
HANDLER(color).off();
}
@@ -83,7 +83,7 @@ void report_t::normalize_options(const string& verb)
if (session.HANDLED(price_exp_))
commodity_pool_t::current_pool->quote_leeway =
- session.HANDLER(price_exp_).value.as_long();
+ lexical_cast<long>(session.HANDLER(price_exp_).value) * 3600L;
if (session.HANDLED(price_db_))
commodity_pool_t::current_pool->price_db = session.HANDLER(price_db_).str();
@@ -106,39 +106,35 @@ void report_t::normalize_options(const string& verb)
if (! HANDLED(meta_width_)) {
string::size_type i = HANDLER(meta_).str().find(':');
if (i != string::npos) {
- HANDLED(meta_width_).on_with
- (string("?normalize"),
- lexical_cast<long>(string(HANDLER(meta_).str(), i + 1)));
- HANDLED(meta_).on(string("?normalize"),
+ HANDLED(meta_width_).on("?normalize",
+ string(HANDLER(meta_).str(), i + 1));
+ HANDLED(meta_).on("?normalize",
string(HANDLER(meta_).str(), 0, i));
}
}
if (HANDLED(meta_width_)) {
- HANDLER(prepend_format_).on
- (string("?normalize"),
- string("%(justify(truncated(tag(\"") +
- HANDLER(meta_).str() + "\"), " +
- HANDLED(meta_width_).value.to_string() + " - 1), " +
- HANDLED(meta_width_).value.to_string() + "))");
- meta_width = HANDLED(meta_width_).value.to_long();
+ HANDLER(prepend_format_)
+ .on("?normalize", string("%(justify(truncated(tag(\"") +
+ HANDLER(meta_).str() + "\"), " +
+ HANDLED(meta_width_).value + " - 1), " +
+ HANDLED(meta_width_).value + "))");
+ meta_width = lexical_cast<long>(HANDLED(meta_width_).value);
} else {
- HANDLER(prepend_format_).on(string("?normalize"), string("%(tag(\"") +
- HANDLER(meta_).str() + "\"))");
+ HANDLER(prepend_format_)
+ .on("?normalize", string("%(tag(\"") + HANDLER(meta_).str() + "\"))");
}
}
- if (! HANDLED(prepend_width_))
- HANDLER(prepend_width_).on_with(string("?normalize"), static_cast<long>(0));
if (verb == "print" || verb == "xact" || verb == "dump") {
- HANDLER(related).on_only(string("?normalize"));
- HANDLER(related_all).on_only(string("?normalize"));
+ HANDLER(related_all).parent = this;
+ HANDLER(related_all).on("?normalize");
}
else if (verb == "equity") {
- HANDLER(equity).on_only(string("?normalize"));
+ HANDLER(equity).on("?normalize");
}
if (verb[0] != 'b' && verb[0] != 'r')
- HANDLER(base).on_only(string("?normalize"));
+ HANDLER(base).on("?normalize");
// If a time period was specified with -p, check whether it also gave a
// begin and/or end to the report period (though these can be overridden
@@ -152,12 +148,10 @@ void report_t::normalize_options(const string& verb)
// to avoid option ordering issues were we to have done it during the
// initial parsing of the options.
if (HANDLED(amount_data)) {
- HANDLER(format_)
- .on_with(string("?normalize"), HANDLER(plot_amount_format_).value);
+ HANDLER(format_).on("?normalize", HANDLER(plot_amount_format_).value);
}
else if (HANDLED(total_data)) {
- HANDLER(format_)
- .on_with(string("?normalize"), HANDLER(plot_total_format_).value);
+ HANDLER(format_).on("?normalize", HANDLER(plot_total_format_).value);
}
// If the --exchange (-X) option was used, parse out any final price
@@ -170,7 +164,7 @@ void report_t::normalize_options(const string& verb)
long cols = 0;
if (HANDLED(columns_))
- cols = HANDLER(columns_).value.to_long();
+ cols = lexical_cast<long>(HANDLER(columns_).value);
else if (const char * columns = std::getenv("COLUMNS"))
cols = lexical_cast<long>(columns);
else
@@ -182,23 +176,20 @@ void report_t::normalize_options(const string& verb)
if (cols > 0) {
DEBUG("auto.columns", "cols = " << cols);
- if (! HANDLER(date_width_).specified)
- HANDLER(date_width_)
- .on_with(none, static_cast<long>(format_date(CURRENT_DATE(),
- FMT_PRINTED).length()));
-
- long date_width = HANDLER(date_width_).value.to_long();
- long payee_width = (HANDLER(payee_width_).specified ?
- HANDLER(payee_width_).value.to_long() :
- int(double(cols) * 0.263157));
- long account_width = (HANDLER(account_width_).specified ?
- HANDLER(account_width_).value.to_long() :
- int(double(cols) * 0.302631));
- long amount_width = (HANDLER(amount_width_).specified ?
- HANDLER(amount_width_).value.to_long() :
- int(double(cols) * 0.157894));
- long total_width = (HANDLER(total_width_).specified ?
- HANDLER(total_width_).value.to_long() :
+ long date_width = (HANDLED(date_width_) ?
+ lexical_cast<long>(HANDLER(date_width_).str()) :
+ format_date(CURRENT_DATE(),FMT_PRINTED).length());
+ long payee_width = (HANDLED(payee_width_) ?
+ lexical_cast<long>(HANDLER(payee_width_).str()) :
+ long(double(cols) * 0.263157));
+ long account_width = (HANDLED(account_width_) ?
+ lexical_cast<long>(HANDLER(account_width_).str()) :
+ long(double(cols) * 0.302631));
+ long amount_width = (HANDLED(amount_width_) ?
+ lexical_cast<long>(HANDLER(amount_width_).str()) :
+ long(double(cols) * 0.157894));
+ long total_width = (HANDLED(total_width_) ?
+ lexical_cast<long>(HANDLER(total_width_).str()) :
amount_width);
DEBUG("auto.columns", "date_width = " << date_width);
@@ -207,11 +198,11 @@ void report_t::normalize_options(const string& verb)
DEBUG("auto.columns", "amount_width = " << amount_width);
DEBUG("auto.columns", "total_width = " << total_width);
- if (! HANDLER(date_width_).specified &&
- ! HANDLER(payee_width_).specified &&
- ! HANDLER(account_width_).specified &&
- ! HANDLER(amount_width_).specified &&
- ! HANDLER(total_width_).specified) {
+ if (! HANDLED(date_width_) &&
+ ! HANDLED(payee_width_) &&
+ ! HANDLED(account_width_) &&
+ ! HANDLED(amount_width_) &&
+ ! HANDLED(total_width_)) {
long total = (4 /* the spaces between */ + date_width + payee_width +
account_width + amount_width + total_width);
if (total > cols) {
@@ -222,17 +213,19 @@ void report_t::normalize_options(const string& verb)
}
if (! HANDLED(meta_width_))
- HANDLER(meta_width_).on_with(string("?normalize"), 0L);
- if (! HANDLER(date_width_).specified)
- HANDLER(date_width_).on_with(string("?normalize"), date_width);
- if (! HANDLER(payee_width_).specified)
- HANDLER(payee_width_).on_with(string("?normalize"), payee_width);
- if (! HANDLER(account_width_).specified)
- HANDLER(account_width_).on_with(string("?normalize"), account_width);
- if (! HANDLER(amount_width_).specified)
- HANDLER(amount_width_).on_with(string("?normalize"), amount_width);
- if (! HANDLER(total_width_).specified)
- HANDLER(total_width_).on_with(string("?normalize"), total_width);
+ HANDLER(meta_width_).value = "0";
+ if (! HANDLED(prepend_width_))
+ HANDLER(prepend_width_).value = "0";
+ if (! HANDLED(date_width_))
+ HANDLER(date_width_).value = to_string(date_width);
+ if (! HANDLED(payee_width_))
+ HANDLER(payee_width_).value = to_string(payee_width);
+ if (! HANDLED(account_width_))
+ HANDLER(account_width_).value = to_string(account_width);
+ if (! HANDLED(amount_width_))
+ HANDLER(amount_width_).value = to_string(amount_width);
+ if (! HANDLED(total_width_))
+ HANDLER(total_width_).value = to_string(total_width);
}
}
@@ -255,7 +248,7 @@ void report_t::normalize_period()
if (! interval.duration)
HANDLER(period_).off();
else if (! HANDLED(sort_all_))
- HANDLER(sort_xacts_).on_only(string("?normalize"));
+ HANDLER(sort_xacts_).on("?normalize");
}
void report_t::parse_query_args(const value_t& args, const string& whence)
@@ -278,7 +271,7 @@ void report_t::parse_query_args(const value_t& args, const string& whence)
}
if (query.has_query(query_t::QUERY_BOLD)) {
- HANDLER(bold_if_).set_expr(whence, query.get_query(query_t::QUERY_BOLD));
+ HANDLER(bold_if_).on(whence, query.get_query(query_t::QUERY_BOLD));
DEBUG("report.predicate", "Bolding predicate = " << HANDLER(bold_if_).str());
}
@@ -329,9 +322,9 @@ void report_t::generate_report(post_handler_ptr handler)
generate_posts_iterator walker
(session, HANDLED(seed_) ?
- static_cast<unsigned int>(HANDLER(seed_).value.to_long()) : 0,
+ lexical_cast<unsigned int>(HANDLER(seed_).str()) : 0,
HANDLED(head_) ?
- static_cast<unsigned int>(HANDLER(head_).value.to_long()) : 50);
+ lexical_cast<unsigned int>(HANDLER(head_).str()) : 50);
pass_down_posts<generate_posts_iterator>(handler, walker);
}
@@ -527,16 +520,17 @@ value_t report_t::fn_market(call_scope_t& args)
arg0 = tmp;
}
+ string target_commodity;
if (args.has<string>(2))
- result = arg0.exchange_commodities(args.get<string>(2),
+ target_commodity = args.get<string>(2);
+
+ if (! target_commodity.empty())
+ result = arg0.exchange_commodities(target_commodity,
/* add_prices= */ false, moment);
else
result = arg0.value(moment);
- if (! result.is_null())
- return result;
-
- return args[0];
+ return ! result.is_null() ? result : arg0;
}
value_t report_t::fn_get_at(call_scope_t& args)
@@ -1245,7 +1239,7 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
else if (is_eq(p, "display_total"))
return MAKE_FUNCTOR(report_t::fn_display_total);
else if (is_eq(p, "date"))
- return MAKE_FUNCTOR(report_t::fn_now);
+ return MAKE_FUNCTOR(report_t::fn_today);
break;
case 'f':
@@ -1404,85 +1398,98 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return MAKE_OPT_HANDLER(report_t, handler);
break;
-#define POSTS_REPORT(formatter) \
+#define POSTS_REPORTER(formatter) \
WRAP_FUNCTOR(reporter<>(post_handler_ptr(formatter), *this, \
- string("#") + p));
+ string("#") + p))
// Can't use WRAP_FUNCTOR here because the template arguments
// confuse the parser
-#define POSTS_REPORT_(method, formatter) \
- expr_t::op_t::wrap_functor \
- (reporter<post_t, post_handler_ptr, method> \
- (post_handler_ptr(formatter), *this, string("#") + p));
-
-#define ACCOUNTS_REPORT(formatter) \
+#define POSTS_REPORTER_(method, formatter) \
+ expr_t::op_t::wrap_functor \
+ (reporter<post_t, post_handler_ptr, method> \
+ (post_handler_ptr(formatter), *this, string("#") + p))
+
+#define FORMATTED_POSTS_REPORTER(format) \
+ POSTS_REPORTER \
+ (new format_posts \
+ (*this, report_format(HANDLER(format)), \
+ maybe_format(HANDLER(prepend_format_)), \
+ HANDLED(prepend_width_) ? \
+ lexical_cast<std::size_t>(HANDLER(prepend_width_).str()) : 0))
+
+#define FORMATTED_COMMODITIES_REPORTER(format) \
+ POSTS_REPORTER_ \
+ (&report_t::commodities_report, \
+ new format_posts \
+ (*this, report_format(HANDLER(format)), \
+ maybe_format(HANDLER(prepend_format_)), \
+ HANDLED(prepend_width_) ? \
+ lexical_cast<std::size_t>(HANDLER(prepend_width_).str()) : 0))
+
+#define ACCOUNTS_REPORTER(formatter) \
expr_t::op_t::wrap_functor(reporter<account_t, acct_handler_ptr, \
&report_t::accounts_report> \
(acct_handler_ptr(formatter), *this, \
- string("#") + p));
+ string("#") + p))
+
+#define FORMATTED_ACCOUNTS_REPORTER(format) \
+ ACCOUNTS_REPORTER \
+ (new format_accounts \
+ (*this, report_format(HANDLER(format)), \
+ maybe_format(HANDLER(prepend_format_)), \
+ HANDLED(prepend_width_) ? \
+ lexical_cast<std::size_t>(HANDLER(prepend_width_).str()) : 0))
case symbol_t::COMMAND:
switch (*p) {
case 'a':
if (is_eq(p, "accounts")) {
- return POSTS_REPORT(new report_accounts(*this));
+ return POSTS_REPORTER(new report_accounts(*this));
}
break;
case 'b':
if (*(p + 1) == '\0' || is_eq(p, "bal") || is_eq(p, "balance")) {
- return ACCOUNTS_REPORT(new format_accounts
- (*this, report_format(HANDLER(balance_format_)),
- maybe_format(HANDLER(prepend_format_)),
- HANDLER(prepend_width_).value.to_size_t()));
+ return FORMATTED_ACCOUNTS_REPORTER(balance_format_);
}
else if (is_eq(p, "budget")) {
- HANDLER(amount_).set_expr(string("#budget"), "(amount, 0)");
+ HANDLER(amount_).on(string("#budget"), "(amount, 0)");
budget_flags |= BUDGET_WRAP_VALUES;
if (! (budget_flags & ~BUDGET_WRAP_VALUES))
budget_flags |= BUDGET_BUDGETED;
- return ACCOUNTS_REPORT(new format_accounts
- (*this, report_format(HANDLER(budget_format_)),
- maybe_format(HANDLER(prepend_format_)),
- HANDLER(prepend_width_).value.to_size_t()));
+ return FORMATTED_ACCOUNTS_REPORTER(budget_format_);
}
break;
case 'c':
if (is_eq(p, "csv")) {
- return POSTS_REPORT(new format_posts
- (*this, report_format(HANDLER(csv_format_)),
- maybe_format(HANDLER(prepend_format_)),
- HANDLER(prepend_width_).value.to_size_t()));
+ return FORMATTED_POSTS_REPORTER(csv_format_);
}
else if (is_eq(p, "cleared")) {
- HANDLER(amount_).set_expr(string("#cleared"),
- "(amount, cleared ? amount : 0)");
- return ACCOUNTS_REPORT(new format_accounts
- (*this, report_format(HANDLER(cleared_format_)),
- maybe_format(HANDLER(prepend_format_)),
- HANDLER(prepend_width_).value.to_size_t()));
+ HANDLER(amount_).on(string("#cleared"),
+ "(amount, cleared ? amount : 0)");
+ return FORMATTED_ACCOUNTS_REPORTER(cleared_format_);
}
else if (is_eq(p, "convert")) {
return WRAP_FUNCTOR(convert_command);
}
else if (is_eq(p, "commodities")) {
- return POSTS_REPORT(new report_commodities(*this));
+ return POSTS_REPORTER(new report_commodities(*this));
}
break;
case 'e':
if (is_eq(p, "equity")) {
- HANDLER(generated).on_only(string("#equity"));
- return POSTS_REPORT(new print_xacts(*this));
+ HANDLER(generated).on("#equity");
+ return POSTS_REPORTER(new print_xacts(*this));
}
else if (is_eq(p, "entry")) {
return WRAP_FUNCTOR(xact_command);
}
else if (is_eq(p, "emacs")) {
- return POSTS_REPORT(new format_emacs_posts(output_stream));
+ return POSTS_REPORTER(new format_emacs_posts(output_stream));
}
else if (is_eq(p, "echo")) {
return MAKE_FUNCTOR(report_t::echo_command);
@@ -1491,43 +1498,32 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
case 'o':
if (is_eq(p, "org")) {
- return POSTS_REPORT(new posts_to_org_table
+ return POSTS_REPORTER(new posts_to_org_table
(*this, maybe_format(HANDLER(prepend_format_))));
}
break;
case 'p':
if (*(p + 1) == '\0' || is_eq(p, "print")) {
- return POSTS_REPORT(new print_xacts(*this, HANDLED(raw)));
+ return POSTS_REPORTER(new print_xacts(*this, HANDLED(raw)));
}
else if (is_eq(p, "prices")) {
- return POSTS_REPORT_(&report_t::commodities_report,
- new format_posts
- (*this, report_format(HANDLER(prices_format_)),
- maybe_format(HANDLER(prepend_format_)),
- HANDLER(prepend_width_).value.to_size_t()));
+ return FORMATTED_COMMODITIES_REPORTER(prices_format_);
}
else if (is_eq(p, "pricedb")) {
- return POSTS_REPORT_(&report_t::commodities_report,
- new format_posts
- (*this, report_format(HANDLER(pricedb_format_)),
- maybe_format(HANDLER(prepend_format_)),
- HANDLER(prepend_width_).value.to_size_t()));
+ return FORMATTED_COMMODITIES_REPORTER(pricedb_format_);
}
else if (is_eq(p, "pricemap")) {
return MAKE_FUNCTOR(report_t::pricemap_command);
}
else if (is_eq(p, "payees")) {
- return POSTS_REPORT(new report_payees(*this));
+ return POSTS_REPORTER(new report_payees(*this));
}
break;
case 'r':
if (*(p + 1) == '\0' || is_eq(p, "reg") || is_eq(p, "register")) {
- return POSTS_REPORT(new format_posts
- (*this, report_format(HANDLER(register_format_)),
- maybe_format(HANDLER(prepend_format_)),
- HANDLER(prepend_width_).value.to_size_t()));
+ return FORMATTED_POSTS_REPORTER(register_format_);
}
else if (is_eq(p, "reload")) {
return MAKE_FUNCTOR(report_t::reload_command);
@@ -1545,7 +1541,7 @@ 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_REPORT(new format_xml(*this));
+ return POSTS_REPORTER(new format_xml(*this));
break;
}
break;
@@ -1568,8 +1564,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
break;
case 'g':
if (is_eq(p, "generate"))
- return POSTS_REPORT_(&report_t::generate_report,
- new print_xacts(*this));
+ return POSTS_REPORTER_(&report_t::generate_report,
+ new print_xacts(*this));
break;
case 'p':
if (is_eq(p, "parse"))
diff --git a/src/report.h b/src/report.h
index d68d1f75..2ad53f01 100644
--- a/src/report.h
+++ b/src/report.h
@@ -353,12 +353,16 @@ public:
* Option handlers
*/
- OPTION__(report_t, abbrev_len_,
- CTOR(report_t, abbrev_len_) { on_with(none, 2L); });
+ OPTION__
+ (report_t, abbrev_len_,
+ CTOR(report_t, abbrev_len_) {
+ on(none, "2");
+ });
+
OPTION(report_t, account_);
OPTION_(report_t, actual, DO() { // -L
- parent->HANDLER(limit_).on(string("--actual"), "actual");
+ OTHER(limit_).on(whence, "actual");
});
OPTION_(report_t, add_budget, DO() {
@@ -368,12 +372,8 @@ public:
OPTION__
(report_t, amount_, // -t
DECL1(report_t, amount_, merged_expr_t, expr, ("amount_expr", "amount")) {}
- void set_expr(const optional<string>& whence, const string& str) {
+ DO_(str) {
expr.append(str);
- on(whence, str);
- }
- DO_(args) {
- set_expr(args.get<string>(0), args.get<string>(1));
});
OPTION(report_t, amount_data); // -j
@@ -381,216 +381,204 @@ public:
OPTION(report_t, auto_match);
OPTION_(report_t, average, DO() { // -A
- parent->HANDLER(display_total_)
- .set_expr(string("--average"), "count>0?(display_total/count):0");
+ OTHER(display_total_)
+ .on(whence, "count>0?(display_total/count):0");
});
- OPTION__(report_t, balance_format_, CTOR(report_t, balance_format_) {
- on(none,
- "%(ansify_if("
- " justify(scrub(display_total), 20, 20 + prepend_width, true, color),"
- " bold if should_bold))"
- " %(!options.flat ? depth_spacer : \"\")"
- "%-(ansify_if("
- " ansify_if(partial_account(options.flat), blue if color),"
- " bold if should_bold))\n%/"
- "%$1\n%/"
- "%(prepend_width ? \" \" * prepend_width : \"\")"
- "--------------------\n");
- });
+ OPTION__
+ (report_t, balance_format_,
+ CTOR(report_t, balance_format_) {
+ on(none,
+ "%(ansify_if("
+ " justify(scrub(display_total), 20,"
+ " 20 + int(prepend_width), true, color),"
+ " bold if should_bold))"
+ " %(!options.flat ? depth_spacer : \"\")"
+ "%-(ansify_if("
+ " ansify_if(partial_account(options.flat), blue if color),"
+ " bold if should_bold))\n%/"
+ "%$1\n%/"
+ "%(prepend_width ? \" \" * int(prepend_width) : \"\")"
+ "--------------------\n");
+ });
OPTION(report_t, base);
OPTION_(report_t, basis, DO() { // -B
- parent->HANDLER(revalued).on_only(string("--basis"));
- parent->HANDLER(amount_).expr.set_base_expr("rounded(cost)");
+ OTHER(revalued).on(whence);
+ OTHER(amount_).expr.set_base_expr("rounded(cost)");
});
- OPTION_(report_t, begin_, DO_(args) { // -b
- date_interval_t interval(args.get<string>(1));
- optional<date_t> begin = interval.begin();
- if (! begin)
+ OPTION_(report_t, begin_, DO_(str) { // -b
+ date_interval_t interval(str);
+ if (optional<date_t> begin = interval.begin()) {
+ string predicate = "date>=[" + to_iso_extended_string(*begin) + "]";
+ OTHER(limit_).on(whence, predicate);
+ } else {
throw_(std::invalid_argument,
- _("Could not determine beginning of period '%1'")
- << args.get<string>(1));
-
- string predicate = "date>=[" + to_iso_extended_string(*begin) + "]";
- parent->HANDLER(limit_).on(string("--begin"), predicate);
+ _("Could not determine beginning of period '%1'") << str);
+ }
});
- OPTION__
+ OPTION_
(report_t, bold_if_,
expr_t expr;
- CTOR(report_t, bold_if_) {}
- void set_expr(const optional<string>& whence, const string& str) {
+ DO_(str) {
expr = str;
- on(whence, str);
- }
- DO_(args) {
- set_expr(args.get<string>(0), args.get<string>(1));
});
OPTION_(report_t, budget, DO() {
parent->budget_flags |= BUDGET_BUDGETED;
});
- OPTION__(report_t, budget_format_, CTOR(report_t, budget_format_) {
- on(none,
- "%(justify(scrub(get_at(display_total, 0)), 12, -1, true, color))"
- " %(justify(-scrub(get_at(display_total, 1)), 12, "
- " 12 + 1 + 12, true, color))"
- " %(justify(scrub(get_at(display_total, 1) + "
- " get_at(display_total, 0)), 12, "
- " 12 + 1 + 12 + 1 + 12, true, color))"
- " %(ansify_if("
- " justify((get_at(display_total, 1) ? "
- " (100% * scrub(get_at(display_total, 0))) / "
- " -scrub(get_at(display_total, 1)) : 0), "
- " 5, -1, true, false),"
- " magenta if (color and get_at(display_total, 1) and "
- " (abs(quantity(scrub(get_at(display_total, 0))) / "
- " quantity(scrub(get_at(display_total, 1)))) >= 1))))"
- " %(!options.flat ? depth_spacer : \"\")"
- "%-(ansify_if(partial_account(options.flat), blue if color))\n"
- "%/%$1 %$2 %$3 %$4\n%/"
- "%(prepend_width ? \" \" * prepend_width : \"\")"
- "------------ ------------ ------------ -----\n");
- });
+ OPTION__
+ (report_t, budget_format_,
+ CTOR(report_t, budget_format_) {
+ on(none,
+ "%(justify(scrub(get_at(display_total, 0)), 12, -1, true, color))"
+ " %(justify(-scrub(get_at(display_total, 1)), 12, "
+ " 12 + 1 + 12, true, color))"
+ " %(justify(scrub(get_at(display_total, 1) + "
+ " get_at(display_total, 0)), 12, "
+ " 12 + 1 + 12 + 1 + 12, true, color))"
+ " %(ansify_if("
+ " justify((get_at(display_total, 1) ? "
+ " (100% * scrub(get_at(display_total, 0))) / "
+ " -scrub(get_at(display_total, 1)) : 0), "
+ " 5, -1, true, false),"
+ " magenta if (color and get_at(display_total, 1) and "
+ " (abs(quantity(scrub(get_at(display_total, 0))) / "
+ " quantity(scrub(get_at(display_total, 1)))) >= 1))))"
+ " %(!options.flat ? depth_spacer : \"\")"
+ "%-(ansify_if(partial_account(options.flat), blue if color))\n"
+ "%/%$1 %$2 %$3 %$4\n%/"
+ "%(prepend_width ? \" \" * int(prepend_width) : \"\")"
+ "------------ ------------ ------------ -----\n");
+ });
OPTION(report_t, by_payee); // -P
OPTION_(report_t, cleared, DO() { // -C
- parent->HANDLER(limit_).on(string("--cleared"), "cleared");
+ OTHER(limit_).on(whence, "cleared");
});
- OPTION__(report_t, cleared_format_, CTOR(report_t, cleared_format_) {
- on(none,
- "%(justify(scrub(get_at(display_total, 0)), 16, 16 + prepend_width, "
- " true, color)) %(justify(scrub(get_at(display_total, 1)), 18, "
- " 36 + prepend_width, true, color))"
- " %(latest_cleared ? format_date(latest_cleared) : \" \")"
- " %(!options.flat ? depth_spacer : \"\")"
- "%-(ansify_if(partial_account(options.flat), blue if color))\n%/"
- "%$1 %$2 %$3\n%/"
- "%(prepend_width ? \" \" * prepend_width : \"\")"
- "---------------- ---------------- ---------\n");
- });
+ OPTION__
+ (report_t, cleared_format_,
+ CTOR(report_t, cleared_format_) {
+ on(none,
+ "%(justify(scrub(get_at(display_total, 0)), 16, 16 + int(prepend_width), "
+ " true, color)) %(justify(scrub(get_at(display_total, 1)), 18, "
+ " 36 + int(prepend_width), true, color))"
+ " %(latest_cleared ? format_date(latest_cleared) : \" \")"
+ " %(!options.flat ? depth_spacer : \"\")"
+ "%-(ansify_if(partial_account(options.flat), blue if color))\n%/"
+ "%$1 %$2 %$3\n%/"
+ "%(prepend_width ? \" \" * int(prepend_width) : \"\")"
+ "---------------- ---------------- ---------\n");
+ });
OPTION(report_t, color);
OPTION_(report_t, collapse, DO() { // -n
// Make sure that balance reports are collapsed too, but only apply it
// to account xacts
- parent->HANDLER(display_).on(string("--collapse"), "post|depth<=1");
+ OTHER(display_).on(whence, "post|depth<=1");
});
OPTION_(report_t, collapse_if_zero, DO() {
- parent->HANDLER(collapse).on_only(string("--collapse-if-zero"));
+ OTHER(collapse).on(whence);
});
OPTION(report_t, columns_);
OPTION(report_t, count);
- OPTION__(report_t, csv_format_, CTOR(report_t, csv_format_) {
- on(none,
- "%(quoted(date)),"
- "%(quoted(code)),"
- "%(quoted(payee)),"
- "%(quoted(display_account)),"
- "%(quoted(commodity)),"
- "%(quoted(quantity(scrub(display_amount)))),"
- "%(quoted(cleared ? \"*\" : (pending ? \"!\" : \"\"))),"
- "%(quoted(join(note | xact.note)))\n");
- });
+ OPTION__
+ (report_t, csv_format_,
+ CTOR(report_t, csv_format_) {
+ on(none,
+ "%(quoted(date)),"
+ "%(quoted(code)),"
+ "%(quoted(payee)),"
+ "%(quoted(display_account)),"
+ "%(quoted(commodity)),"
+ "%(quoted(quantity(scrub(display_amount)))),"
+ "%(quoted(cleared ? \"*\" : (pending ? \"!\" : \"\"))),"
+ "%(quoted(join(note | xact.note)))\n");
+ });
OPTION_(report_t, current, DO() { // -c
- parent->HANDLER(limit_).on(string("--current"), "date<=today");
+ OTHER(limit_).on(whence, "date<=today");
});
OPTION_(report_t, daily, DO() { // -D
- parent->HANDLER(period_).on(string("--daily"), "daily");
+ OTHER(period_).on(whence, "daily");
});
OPTION(report_t, date_);
OPTION(report_t, date_format_);
OPTION(report_t, datetime_format_);
- OPTION_(report_t, depth_, DO_(args) {
- parent->HANDLER(display_)
- .on(string("--depth"), string("depth<=") + args.get<string>(1));
+ OPTION_(report_t, depth_, DO_(str) {
+ OTHER(display_).on(whence, string("depth<=") + str);
});
OPTION_(report_t, deviation, DO() {
- parent->HANDLER(display_total_)
- .set_expr(string("--deviation"), "display_amount-display_total");
+ OTHER(display_total_)
+ .on(whence, "display_amount-display_total");
});
- OPTION__
- (report_t, display_, // -d
- CTOR(report_t, display_) {}
- virtual void on_with(const optional<string>& whence, const value_t& text) {
- if (! handled)
- option_t<report_t>::on_with(whence, text);
- else
- option_t<report_t>::on_with(whence,
- string_value(string("(") + str() + ")&(" +
- text.as_string() + ")"));
+ OPTION_
+ (report_t, display_,
+ DO_(str) { // -d
+ if (handled)
+ value = string("(") + value + ")&(" + str + ")";
});
OPTION__
(report_t, display_amount_,
DECL1(report_t, display_amount_, merged_expr_t, expr,
("display_amount", "amount_expr")) {}
- void set_expr(const optional<string>& whence, const string& str) {
+ DO_(str) {
expr.append(str);
- on(whence, str);
- }
- DO_(args) {
- set_expr(args.get<string>(0), args.get<string>(1));
});
OPTION__
(report_t, display_total_,
DECL1(report_t, display_total_, merged_expr_t, expr,
("display_total", "total_expr")) {}
- void set_expr(const optional<string>& whence, const string& str) {
+ DO_(str) {
expr.append(str);
- on(whence, str);
- }
- DO_(args) {
- set_expr(args.get<string>(0), args.get<string>(1));
});
OPTION(report_t, dow);
OPTION(report_t, aux_date);
OPTION(report_t, empty); // -E
- OPTION_(report_t, end_, DO_(args) { // -e
- date_interval_t interval(args.get<string>(1));
+ OPTION_(report_t, end_, DO_(str) { // -e
// Use begin() here so that if the user says --end=2008, we end on
// 2008/01/01 instead of 2009/01/01 (which is what end() would
// return).
- optional<date_t> end = interval.begin();
- if (! end)
+ date_interval_t interval(str);
+ if (optional<date_t> end = interval.begin()) {
+ string predicate = "date<[" + to_iso_extended_string(*end) + "]";
+ OTHER(limit_).on(whence, predicate);
+
+ parent->terminus = datetime_t(*end);
+ } else {
throw_(std::invalid_argument,
_("Could not determine end of period '%1'")
- << args.get<string>(1));
-
- string predicate = "date<[" + to_iso_extended_string(*end) + "]";
- parent->HANDLER(limit_).on(string("--end"), predicate);
-
- parent->terminus = datetime_t(*end);
+ << str);
+ }
});
OPTION(report_t, equity);
OPTION(report_t, exact);
- OPTION_(report_t, exchange_, DO_(args) { // -X
- on_with(args.get<string>(0), args[1]);
- call_scope_t no_args(*parent);
- no_args.push_back(args[0]);
- parent->HANDLER(market).parent = parent;
- parent->HANDLER(market).handler(no_args);
+ OPTION_(report_t, exchange_, DO_() { // -X
+ // Using -X implies -V. The main difference is that now
+ // HANDLER(exchange_) contains the name of a commodity, which
+ // is accessed via the "exchange" value expression function.
+ OTHER(market).on(whence);
});
OPTION(report_t, flat);
@@ -601,74 +589,65 @@ public:
OPTION(report_t, format_); // -F
OPTION_(report_t, gain, DO() { // -G
- parent->HANDLER(revalued).on_only(string("--gain"));
+ OTHER(revalued).on(whence);
- parent->HANDLER(amount_).expr.set_base_expr("(amount, cost)");
- parent->HANDLER(total_).expr.set_base_expr("total");
+ OTHER(amount_).expr.set_base_expr("(amount, cost)");
+ OTHER(total_).expr.set_base_expr("total");
// Since we are displaying the amounts of revalued postings, they
// will end up being composite totals, and hence a pair of pairs.
- parent->HANDLER(display_amount_)
- .set_expr(string("--gain"),
- "use_direct_amount ? amount :"
- " (is_seq(get_at(amount_expr, 0)) ?"
- " get_at(get_at(amount_expr, 0), 0) :"
- " market(get_at(amount_expr, 0), value_date, exchange)"
- " - get_at(amount_expr, 1))");
- parent->HANDLER(revalued_total_)
- .set_expr(string("--gain"),
- "(market(get_at(total_expr, 0), value_date, exchange), "
- "get_at(total_expr, 1))");
- parent->HANDLER(display_total_)
- .set_expr(string("--gain"),
- "use_direct_amount ? total_expr :"
- " market(get_at(total_expr, 0), value_date, exchange)"
- " - get_at(total_expr, 1)");
+ OTHER(display_amount_)
+ .on(whence,
+ "use_direct_amount ? amount :"
+ " (is_seq(get_at(amount_expr, 0)) ?"
+ " get_at(get_at(amount_expr, 0), 0) :"
+ " market(get_at(amount_expr, 0), value_date, exchange)"
+ " - get_at(amount_expr, 1))");
+ OTHER(revalued_total_)
+ .on(whence,
+ "(market(get_at(total_expr, 0), value_date, exchange), "
+ "get_at(total_expr, 1))");
+ OTHER(display_total_)
+ .on(whence,
+ "use_direct_amount ? total_expr :"
+ " market(get_at(total_expr, 0), value_date, exchange)"
+ " - get_at(total_expr, 1)");
});
OPTION(report_t, generated);
- OPTION__
+ OPTION_
(report_t, group_by_,
expr_t expr;
- CTOR(report_t, group_by_) {}
- void set_expr(const optional<string>& whence, const string& str) {
+ DO_(str) {
expr = str;
- on(whence, str);
- }
- DO_(args) {
- set_expr(args.get<string>(0), args.get<string>(1));
});
- OPTION__(report_t, group_title_format_, CTOR(report_t, group_title_format_) {
- on(none, "%(value)\n");
- });
+ OPTION__
+ (report_t, group_title_format_,
+ CTOR(report_t, group_title_format_) {
+ on(none, "%(value)\n");
+ });
OPTION(report_t, head_);
OPTION_(report_t, historical, DO() { // -H
- parent->HANDLER(amount_)
- .set_expr(string("--historical"),
- "nail_down(amount_expr, (s,d,t -> market(s,value_date,t)))");
+ OTHER(amount_)
+ .on(whence, "nail_down(amount_expr, "
+ "market(amount_expr, value_date, exchange))");
});
-
OPTION(report_t, inject_);
OPTION_(report_t, invert, DO() {
- parent->HANDLER(amount_).set_expr(string("--invert"), "-amount");
+ OTHER(amount_).on(whence, "-amount");
});
- OPTION__
- (report_t, limit_, // -l
- CTOR(report_t, limit_) {}
- virtual void on_with(const optional<string>& whence, const value_t& text) {
- if (! handled)
- option_t<report_t>::on_with(whence, text);
- else
- option_t<report_t>::on_with(whence,
- string_value(string("(") + str() + ")&(" +
- text.as_string() + ")"));
+ OPTION_
+ (report_t, limit_,
+ DO_(str) { // -l
+ if (handled)
+ value = string("(") + value + ")&(" + str + ")";
});
OPTION(report_t, lot_dates);
@@ -678,49 +657,44 @@ public:
OPTION(report_t, lots_actual);
OPTION_(report_t, market, DO() { // -V
- parent->HANDLER(revalued).on_only(string("--market"));
- parent->HANDLER(display_amount_)
- .set_expr(string("--market"),
- "market(display_amount, value_date, exchange)");
- parent->HANDLER(display_total_)
- .set_expr(string("--market"),
- "market(display_total, value_date, exchange)");
+ OTHER(revalued).on(whence);
+
+ OTHER(display_amount_)
+ .on(whence, "market(display_amount, value_date, exchange)");
+ OTHER(display_total_)
+ .on(whence, "market(display_total, value_date, exchange)");
});
OPTION(report_t, meta_);
OPTION_(report_t, monthly, DO() { // -M
- parent->HANDLER(period_).on(string("--monthly"), "monthly");
+ OTHER(period_).on(whence, "monthly");
});
OPTION_(report_t, no_color, DO() {
- parent->HANDLER(color).off();
+ OTHER(color).off();
});
OPTION(report_t, no_rounding);
OPTION(report_t, no_titles);
OPTION(report_t, no_total);
- OPTION_(report_t, now_, DO_(args) {
- date_interval_t interval(args.get<string>(1));
- optional<date_t> begin = interval.begin();
- if (! begin)
+ OPTION_(report_t, now_, DO_(str) {
+ date_interval_t interval(str);
+ if (optional<date_t> begin = interval.begin()) {
+ ledger::epoch = parent->terminus = datetime_t(*begin);
+ } else {
throw_(std::invalid_argument,
_("Could not determine beginning of period '%1'")
- << args.get<string>(1));
- ledger::epoch = parent->terminus = datetime_t(*begin);
+ << str);
+ }
});
- OPTION__
+ OPTION_
(report_t, only_,
- CTOR(report_t, only_) {}
- virtual void on_with(const optional<string>& whence, const value_t& text) {
- if (! handled)
- option_t<report_t>::on_with(whence, text);
- else
- option_t<report_t>::on_with(whence,
- string_value(string("(") + str() + ")&(" +
- text.as_string() + ")"));
+ DO_(str) {
+ if (handled)
+ value = string("(") + value + ")&(" + str + ")";
});
OPTION(report_t, output_); // -o
@@ -741,178 +715,162 @@ public:
setenv("LESS", "-FRSX", 0); // don't overwrite
}
}
- }
- virtual void on_with(const optional<string>& whence, const value_t& text) {
- string cmd(text.to_string());
- if (cmd == "" || cmd == "false" || cmd == "off" ||
- cmd == "none" || cmd == "no" || cmd == "disable")
- option_t<report_t>::off();
- else
- option_t<report_t>::on_with(whence, text);
});
#else // HAVE_ISATTY
- OPTION__
- (report_t, pager_,
- CTOR(report_t, pager_) {
- }
- virtual void on_with(const optional<string>& whence, const value_t& text) {
- string cmd(text.to_string());
- if (cmd == "" || cmd == "false" || cmd == "off" ||
- cmd == "none" || cmd == "no" || cmd == "disable")
- option_t<report_t>::off();
- else
- option_t<report_t>::on_with(whence, text);
- });
+ OPTION(report_t, pager_);
#endif // HAVE_ISATTY
+ OPTION_(report_t, no_pager, DO() {
+ OTHER(pager_).off();
+ });
+
OPTION(report_t, payee_);
OPTION_(report_t, pending, DO() { // -C
- parent->HANDLER(limit_).on(string("--pending"), "pending");
+ OTHER(limit_).on(whence, "pending");
});
OPTION_(report_t, percent, DO() { // -%
- parent->HANDLER(total_)
- .set_expr(string("--percent"),
- "((is_account&parent&parent.total)?"
- " percent(scrub(total), scrub(parent.total)):0)");
+ OTHER(total_)
+ .on(whence,
+ "((is_account&parent&parent.total)?"
+ " percent(scrub(total), scrub(parent.total)):0)");
});
- OPTION__
- (report_t, period_, // -p
- CTOR(report_t, period_) {}
- virtual void on_with(const optional<string>& whence, const value_t& text) {
- if (! handled)
- option_t<report_t>::on_with(whence, text);
- else
- option_t<report_t>::on_with(whence,
- string_value(text.as_string() + " " + str()));
+ OPTION_
+ (report_t, period_,
+ DO_(str) { // -p
+ if (handled)
+ value += 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");
- });
+ 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");
+ });
- OPTION__(report_t, plot_total_format_, CTOR(report_t, plot_total_format_) {
- on(none,
- "%(format_date(date, \"%Y-%m-%d\")) %(quantity(scrub(display_total)))\n");
- });
+ OPTION__
+ (report_t, plot_total_format_,
+ CTOR(report_t, plot_total_format_) {
+ on(none,
+ "%(format_date(date, \"%Y-%m-%d\")) %(quantity(scrub(display_total)))\n");
+ });
OPTION(report_t, prepend_format_);
- OPTION_(report_t, prepend_width_, DO_(args) {
- value = args.get<long>(1);
- });
+ OPTION(report_t, prepend_width_);
OPTION_(report_t, price, DO() { // -I
- parent->HANDLER(amount_).expr.set_base_expr("price");
+ OTHER(amount_).expr.set_base_expr("price");
});
- OPTION__(report_t, prices_format_, CTOR(report_t, prices_format_) {
- on(none,
- "%(date) %-8(display_account) %(justify(scrub(display_amount), 12, "
- " 2 + 9 + 8 + 12, true, color))\n");
- });
+ OPTION__
+ (report_t, prices_format_,
+ CTOR(report_t, prices_format_) {
+ on(none,
+ "%(date) %-8(display_account) %(justify(scrub(display_amount), 12, "
+ " 2 + 9 + 8 + 12, true, color))\n");
+ });
- OPTION__(report_t, pricedb_format_, CTOR(report_t, pricedb_format_) {
- on(none,
- "P %(datetime) %(display_account) %(scrub(display_amount))\n");
- });
+ OPTION__
+ (report_t, pricedb_format_,
+ CTOR(report_t, pricedb_format_) {
+ on(none,
+ "P %(datetime) %(display_account) %(scrub(display_amount))\n");
+ });
OPTION(report_t, primary_date);
OPTION_(report_t, quantity, DO() { // -O
- parent->HANDLER(revalued).off();
- parent->HANDLER(amount_).expr.set_base_expr("amount");
- parent->HANDLER(total_).expr.set_base_expr("total");
+ OTHER(revalued).off();
+
+ OTHER(amount_).expr.set_base_expr("amount");
+ OTHER(total_).expr.set_base_expr("total");
});
OPTION_(report_t, quarterly, DO() {
- parent->HANDLER(period_).on(string("--quarterly"), "quarterly");
+ OTHER(period_).on(whence, "quarterly");
});
OPTION(report_t, raw);
OPTION_(report_t, real, DO() { // -R
- parent->HANDLER(limit_).on(string("--real"), "real");
+ OTHER(limit_).on(whence, "real");
});
- OPTION__(report_t, register_format_, CTOR(report_t, register_format_) {
- on(none,
- "%(ansify_if("
- " ansify_if(justify(format_date(date), date_width),"
- " green if color and date > today),"
- " bold if should_bold))"
- " %(ansify_if("
- " ansify_if(justify(truncated(payee, payee_width), payee_width), "
- " bold if color and !cleared and actual),"
- " bold if should_bold))"
- " %(ansify_if("
- " ansify_if(justify(truncated(display_account, account_width, "
- " abbrev_len), account_width),"
- " blue if color),"
- " bold if should_bold))"
- " %(ansify_if("
- " justify(scrub(display_amount), amount_width, "
- " 3 + meta_width + date_width + payee_width"
- " + account_width + amount_width + prepend_width,"
- " true, color),"
- " bold if should_bold))"
- " %(ansify_if("
- " justify(scrub(display_total), total_width, "
- " 4 + meta_width + date_width + payee_width"
- " + account_width + amount_width + total_width"
- " + prepend_width, true, color),"
- " bold if should_bold))\n%/"
- "%(justify(\" \", date_width))"
- " %(ansify_if("
- " justify(truncated(has_tag(\"Payee\") ? payee : \" \", "
- " payee_width), payee_width),"
- " bold if should_bold))"
- " %$3 %$4 %$5\n");
- });
+ OPTION__
+ (report_t, register_format_,
+ CTOR(report_t, register_format_) {
+ on(none,
+ "%(ansify_if("
+ " ansify_if(justify(format_date(date), int(date_width)),"
+ " green if color and date > today),"
+ " bold if should_bold))"
+ " %(ansify_if("
+ " ansify_if(justify(truncated(payee, int(payee_width)), int(payee_width)), "
+ " bold if color and !cleared and actual),"
+ " bold if should_bold))"
+ " %(ansify_if("
+ " ansify_if(justify(truncated(display_account, int(account_width), "
+ " abbrev_len), int(account_width)),"
+ " blue if color),"
+ " bold if should_bold))"
+ " %(ansify_if("
+ " justify(scrub(display_amount), int(amount_width), "
+ " 3 + int(meta_width) + int(date_width) + int(payee_width)"
+ " + int(account_width) + int(amount_width) + int(prepend_width),"
+ " true, color),"
+ " bold if should_bold))"
+ " %(ansify_if("
+ " justify(scrub(display_total), int(total_width), "
+ " 4 + int(meta_width) + int(date_width) + int(payee_width)"
+ " + int(account_width) + int(amount_width) + int(total_width)"
+ " + int(prepend_width), true, color),"
+ " bold if should_bold))\n%/"
+ "%(justify(\" \", int(date_width)))"
+ " %(ansify_if("
+ " justify(truncated(has_tag(\"Payee\") ? payee : \" \", "
+ " int(payee_width)), int(payee_width)),"
+ " bold if should_bold))"
+ " %$3 %$4 %$5\n");
+ });
OPTION(report_t, related); // -r
OPTION_(report_t, related_all, DO() {
- parent->HANDLER(related).on_only(string("--related-all"));
+ OTHER(related).on(whence);
});
OPTION(report_t, revalued);
OPTION(report_t, revalued_only);
- OPTION__
+ OPTION_
(report_t, revalued_total_,
expr_t expr;
- CTOR(report_t, revalued_total_) {}
- void set_expr(const optional<string>& whence, const string& str) {
+ DO_(str) {
expr = str;
- on(whence, str);
- }
- DO_(args) {
- set_expr(args.get<string>(0), args.get<string>(1));
});
OPTION(report_t, rich_data);
OPTION(report_t, seed_);
- OPTION_(report_t, sort_, DO_(args) { // -S
- on_with(args.get<string>(0), args[1]);
- parent->HANDLER(sort_xacts_).off();
- parent->HANDLER(sort_all_).off();
+ OPTION_(report_t, sort_, DO_(str) { // -S
+ OTHER(sort_xacts_).off();
+ OTHER(sort_all_).off();
});
- OPTION_(report_t, sort_all_, DO_(args) {
- parent->HANDLER(sort_).on_with(string("--sort-all"), args[1]);
- parent->HANDLER(sort_xacts_).off();
+ OPTION_(report_t, sort_all_, DO_(str) {
+ OTHER(sort_).on(whence, str);
+ OTHER(sort_xacts_).off();
});
- OPTION_(report_t, sort_xacts_, DO_(args) {
- parent->HANDLER(sort_).on_with(string("--sort-xacts"), args[1]);
- parent->HANDLER(sort_all_).off();
+ OPTION_(report_t, sort_xacts_, DO_(str) {
+ OTHER(sort_).on(whence, str);
+ OTHER(sort_all_).off();
});
OPTION(report_t, start_of_week_);
@@ -922,18 +880,13 @@ public:
OPTION__
(report_t, total_, // -T
DECL1(report_t, total_, merged_expr_t, expr, ("total_expr", "total")) {}
- void set_expr(const optional<string>& whence, const string& str) {
+ DO_(str) {
expr.append(str);
- on(whence, str);
- }
- DO_(args) {
- set_expr(args.get<string>(0), args.get<string>(1));
});
OPTION(report_t, total_data); // -J
- OPTION_(report_t, truncate_, DO_(args) {
- string style(args.get<string>(1));
+ OPTION_(report_t, truncate_, DO_(style) {
if (style == "leading")
format_t::default_style = format_t::TRUNCATE_LEADING;
else if (style == "middle")
@@ -951,7 +904,7 @@ public:
});
OPTION_(report_t, uncleared, DO() { // -U
- parent->HANDLER(limit_).on(string("--uncleared"), "uncleared|pending");
+ OTHER(limit_).on(whence, "uncleared|pending");
});
OPTION(report_t, unrealized);
@@ -960,48 +913,28 @@ public:
OPTION(report_t, unrealized_losses_);
OPTION_(report_t, unround, DO() {
- parent->HANDLER(amount_)
- .set_expr(string("--unround"), "unrounded(amount_expr)");
- parent->HANDLER(total_)
- .set_expr(string("--unround"), "unrounded(total_expr)");
+ OTHER(amount_).on(whence, "unrounded(amount_expr)");
+ OTHER(total_).on(whence, "unrounded(total_expr)");
});
OPTION_(report_t, weekly, DO() { // -W
- parent->HANDLER(period_).on(string("--weekly"), "weekly");
+ OTHER(period_).on(whence, "weekly");
});
OPTION_(report_t, wide, DO() { // -w
- parent->HANDLER(columns_).on_with(string("--wide"), 132L);
+ OTHER(columns_).on(whence, "132");
});
OPTION_(report_t, yearly, DO() { // -Y
- parent->HANDLER(period_).on(string("--yearly"), "yearly");
+ OTHER(period_).on(whence, "yearly");
});
- OPTION__(report_t, meta_width_,
- bool specified;
- CTOR(report_t, meta_width_) { specified = false; }
- DO_(args) { value = args.get<long>(1); specified = true; });
- OPTION__(report_t, date_width_,
- bool specified;
- CTOR(report_t, date_width_) { specified = false; }
- DO_(args) { value = args.get<long>(1); specified = true; });
- OPTION__(report_t, payee_width_,
- bool specified;
- CTOR(report_t, payee_width_) { specified = false; }
- DO_(args) { value = args.get<long>(1); specified = true; });
- OPTION__(report_t, account_width_,
- bool specified;
- CTOR(report_t, account_width_) { specified = false; }
- DO_(args) { value = args.get<long>(1); specified = true; });
- OPTION__(report_t, amount_width_,
- bool specified;
- CTOR(report_t, amount_width_) { specified = false; }
- DO_(args) { value = args.get<long>(1); specified = true; });
- OPTION__(report_t, total_width_,
- bool specified;
- CTOR(report_t, total_width_) { specified = false; }
- DO_(args) { value = args.get<long>(1); specified = true; });
+ OPTION(report_t, meta_width_);
+ OPTION(report_t, date_width_);
+ OPTION(report_t, payee_width_);
+ OPTION(report_t, account_width_);
+ OPTION(report_t, amount_width_);
+ OPTION(report_t, total_width_);
};
diff --git a/src/session.h b/src/session.h
index b06c4a42..cb981346 100644
--- a/src/session.h
+++ b/src/session.h
@@ -128,28 +128,24 @@ public:
OPTION__
(session_t, price_exp_, // -Z
- CTOR(session_t, price_exp_) { value = 24L * 3600L; }
- DO_(args) {
- value = args.get<long>(1) * 60L;
- });
+ CTOR(session_t, price_exp_) { value = "24"; });
OPTION__
(session_t, file_, // -f
std::list<path> data_files;
CTOR(session_t, file_) {}
- DO_(args) {
- assert(args.size() == 2);
+ DO_(str) {
if (parent->flush_on_next_data_file) {
data_files.clear();
parent->flush_on_next_data_file = false;
}
- data_files.push_back(args.get<string>(1));
+ data_files.push_back(str);
});
- OPTION_(session_t, input_date_format_, DO_(args) {
- // This changes static variables inside times.h, which affects the basic
- // date parser.
- set_input_date_format(args.get<string>(1).c_str());
+ OPTION_(session_t, input_date_format_, DO_(str) {
+ // This changes static variables inside times.h, which affects the
+ // basic date parser.
+ set_input_date_format(str.c_str());
});
OPTION(session_t, explicit);
diff --git a/test/baseline/opt-no-pager.test b/test/baseline/opt-no-pager.test
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/baseline/opt-no-pager.test