added --help docs, and fixed some problems with balance reproting
This commit is contained in:
parent
8af33274fb
commit
e1086a3040
6 changed files with 94 additions and 80 deletions
109
config.cc
109
config.cc
|
|
@ -28,8 +28,8 @@ config_t::config_t()
|
||||||
value_expr = "a";
|
value_expr = "a";
|
||||||
total_expr = "O";
|
total_expr = "O";
|
||||||
pricing_leeway = 24 * 3600;
|
pricing_leeway = 24 * 3600;
|
||||||
show_subtotals = true;
|
show_collapsed = false;
|
||||||
show_expanded = false;
|
show_subtotal = false;
|
||||||
show_related = false;
|
show_related = false;
|
||||||
show_inverted = false;
|
show_inverted = false;
|
||||||
show_empty = false;
|
show_empty = false;
|
||||||
|
|
@ -52,59 +52,62 @@ static void show_version(std::ostream& out)
|
||||||
void option_help(std::ostream& out)
|
void option_help(std::ostream& out)
|
||||||
{
|
{
|
||||||
out
|
out
|
||||||
<< "usage: ledger [options] COMMAND [options] [REGEXPS]\n\n\
|
<< "usage: ledger [options] COMMAND [ACCT REGEX]... [-- [PAYEE REGEX]...]\n\n\
|
||||||
Basic options:\n\
|
Basic options:\n\
|
||||||
-h, --help display this help text\n\
|
-h, --help display this help text\n\
|
||||||
-v, --version display version information\n\
|
-v, --version show version information\n\
|
||||||
-i, --init FILE initialize ledger by loading FILE\n\
|
-i, --init FILE initialize ledger by loading FILE (def: ~/.ledgerrc)\n\
|
||||||
-f, --file FILE specify pathname of ledger data file\n\
|
-f, --file FILE read ledger data from FILE\n\
|
||||||
-o, --output FILE write all output to FILE\n\
|
-o, --output FILE write output to FILE\n\
|
||||||
-p, --set-price CONV specifies commodity conversion: COMM=AMOUNT\n\n\
|
-p, --set-price CONV specify a commodity conversion: \"COMM=AMOUNT\"\n\n\
|
||||||
Report filtering:\n\
|
Report filtering:\n\
|
||||||
-b, --begin-date DATE specify a beginning date\n\
|
-b, --begin-date DATE set report begin date\n\
|
||||||
-e, --end-date DATE specify an ending date\n\
|
-e, --end-date DATE set report end date\n\
|
||||||
-c, --current do not show future entries (same as -e TODAY)\n\
|
-c, --current show only current and past entries (not future)\n\
|
||||||
-C, --cleared show only cleared transactions and balances\n\
|
-C, --cleared consider only cleared transactions\n\
|
||||||
-U, --uncleared show only uncleared transactions and balances\n\
|
-U, --uncleared consider only uncleared transactions\n\
|
||||||
-R, --real do not consider virtual transactions: real only\n\n\
|
-R, --real consider only non-virtual transactions\n\n\
|
||||||
|
-r, --related calculate report using related transactions\n\
|
||||||
Output customization:\n\
|
Output customization:\n\
|
||||||
-F, --format STR \n\
|
-F, --format STR use STR as the report format\n\
|
||||||
-y, --date-format STR \n\
|
-y, --date-format STR use STR as the date format (def: %Y/%m/%d)\n\
|
||||||
-E, --empty balance: also show accounts that total to zero\n\
|
-E, --empty balance: show accounts with zero balance\n\
|
||||||
-n, --collapse balance: no parent account totals; register: collapse\n\
|
-n, --collapse register: collapse entries with multiple transactions\n\
|
||||||
-s, --show-all balance: show sub-accounts; register: show subtotals\n\
|
-s, --subtotal balance: show sub-accounts; register: show subtotals\n\
|
||||||
-S, --sort EXPR sort report according to value EXPR\n\
|
-S, --sort EXPR sort report according to the value expression EXPR\n\
|
||||||
-r, --related \n\
|
-z, --interval STR report by interval, based on interval expression STR\n\
|
||||||
-z, --interval EXPR \n\
|
-w, --dow show a days-of-the-week report\n\
|
||||||
-w, --dow print register using day of week sub-totals\n\
|
-W, --weekly show weekly sub-totals\n\
|
||||||
-W, --weekly \" \" weekly sub-totals\n\
|
-M, --monthly show monthly sub-totals\n\
|
||||||
-M, --monthly \" \" monthly sub-totals\n\
|
-Y, --yearly show yearly sub-totals\n\
|
||||||
-Y, --yearly \" \" yearly sub-totals\n\
|
-l, --limit EXPR calculate only transactions matching EXPR\n\
|
||||||
-l, --limit EXPR don't calculate entries for which EXPR yields 0\n\
|
-d, --display EXPR display only transactions matching EXPR\n\
|
||||||
-d, --display EXPR don't print entries for which EXPR yields 0\n\
|
-t, --value EXPR set the value expression for all report types\n\
|
||||||
-t, --value EXPR \n\
|
-T, --total EXPR set the total expression for all report types\n\
|
||||||
-T, --total EXPR \n\
|
-j, --value-data print only raw value data (useful when scripting)\n\
|
||||||
-j, --value-data \n\
|
-J, --total-data print only raw total data\n\n\
|
||||||
-J, --total-data \n\n\
|
|
||||||
Commodity reporting:\n\
|
Commodity reporting:\n\
|
||||||
-P, --price-db FILE sets the price database\n\
|
-P, --price-db FILE sets the price database to FILE (def: ~/.pricedb)\n\
|
||||||
-L, --price-exp MINS with -Q, fetch quotes only if data is older than MINS\n\
|
-L, --price-exp MINS download quotes only if newer than MINS (def: 1440)\n\
|
||||||
-Q, --download download price information from the Internet\n\
|
-Q, --download download price information when needed\n\
|
||||||
(works by running \"getquote SYMBOL\")\n\
|
-O, --quantity report commodity totals (this is the default)\n\
|
||||||
-O, --quantity \n\
|
-B, --basis report commodity cost basis\n\
|
||||||
-B, --basis report cost basis of commodities\n\
|
-V, --market report commodity market value\n\
|
||||||
-V, --market report the market value of commodities\n\
|
-G, --gain report commodity gain/loss\n\
|
||||||
-G, --gain \n\
|
-A, --average report average transaction amount\n\
|
||||||
-A, --average \n\
|
-D, --deviation report deviation from the average\n\
|
||||||
-D, --deviation \n\
|
-X, --trend report average deviation from the average\n\
|
||||||
-X, --trend \n\
|
-Z, --weighted-trend same as trend, but older values less significant\n\n\
|
||||||
-Z, --weighted-trend \n\n\
|
|
||||||
Commands:\n\
|
Commands:\n\
|
||||||
balance show balance totals\n\
|
balance [REGEXP]... show balance totals for matching accounts\n\
|
||||||
register display a register for ACCOUNT\n\
|
register [REGEXP]... show register of matching transactions\n\
|
||||||
print print all ledger entries\n\
|
print [REGEXP]... print all matching entries\n\
|
||||||
entry output a newly formed entry, based on arguments\n\
|
equity [REGEXP]... output equity entries for matching accounts\n\
|
||||||
equity output equity entries for specified accounts\n";
|
entry DATE PAYEE AMT output a derived entry, based on the arguments\n\n\
|
||||||
|
For commands that accepts a list of regular expressions, these match against\n\
|
||||||
|
the account. If the separator \"--\" is specified, regexps after it are\n\
|
||||||
|
matched against the payee name. For even more sophisticated entry matching,\n\
|
||||||
|
use --limit; to affect display only (not calculation), use --display.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -214,12 +217,12 @@ OPT_BEGIN(empty, "E") {
|
||||||
} OPT_END(empty);
|
} OPT_END(empty);
|
||||||
|
|
||||||
OPT_BEGIN(collapse, "n") {
|
OPT_BEGIN(collapse, "n") {
|
||||||
config->show_subtotals = false;
|
config->show_collapsed = true;
|
||||||
} OPT_END(collapse);
|
} OPT_END(collapse);
|
||||||
|
|
||||||
OPT_BEGIN(show_all, "s") {
|
OPT_BEGIN(subtotal, "s") {
|
||||||
config->show_expanded = true;
|
config->show_subtotal = true;
|
||||||
} OPT_END(show_all);
|
} OPT_END(subtotal);
|
||||||
|
|
||||||
OPT_BEGIN(sort, "S:") {
|
OPT_BEGIN(sort, "S:") {
|
||||||
config->sort_string = optarg;
|
config->sort_string = optarg;
|
||||||
|
|
|
||||||
4
config.h
4
config.h
|
|
@ -32,8 +32,8 @@ struct config_t
|
||||||
std::string value_expr;
|
std::string value_expr;
|
||||||
std::string total_expr;
|
std::string total_expr;
|
||||||
unsigned long pricing_leeway;
|
unsigned long pricing_leeway;
|
||||||
bool show_subtotals;
|
bool show_collapsed;
|
||||||
bool show_expanded;
|
bool show_subtotal;
|
||||||
bool show_related;
|
bool show_related;
|
||||||
bool show_inverted;
|
bool show_inverted;
|
||||||
bool show_empty;
|
bool show_empty;
|
||||||
|
|
|
||||||
31
format.cc
31
format.cc
|
|
@ -347,24 +347,30 @@ bool format_account::disp_subaccounts_p(const account_t * account,
|
||||||
disp_pred,
|
disp_pred,
|
||||||
const account_t *& to_show)
|
const account_t *& to_show)
|
||||||
{
|
{
|
||||||
bool display = false;
|
bool display = false;
|
||||||
unsigned int counted = 0;
|
unsigned int counted = 0;
|
||||||
|
bool computed = false;
|
||||||
|
bool matches = disp_pred(account);
|
||||||
|
balance_t acct_total;
|
||||||
|
|
||||||
to_show = NULL;
|
to_show = NULL;
|
||||||
|
|
||||||
for (accounts_map::const_iterator i = account->accounts.begin();
|
for (accounts_map::const_iterator i = account->accounts.begin();
|
||||||
i != account->accounts.end();
|
i != account->accounts.end();
|
||||||
i++) {
|
i++) {
|
||||||
// jww (2004-08-03): How to compute the right figure? It should
|
if (! disp_pred((*i).second))
|
||||||
// be a value expression specified by the user which says, "If
|
|
||||||
// this expression is equivalent between a parent account and a
|
|
||||||
// lone displayed child, don't display the parent."
|
|
||||||
|
|
||||||
if (! (*i).second->total || ! disp_pred((*i).second))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((*i).second->total != account->total || counted > 0) {
|
balance_t result;
|
||||||
display = true;
|
format_t::compute_total(result, details_t((*i).second));
|
||||||
|
|
||||||
|
if (! computed) {
|
||||||
|
format_t::compute_total(acct_total, details_t(account));
|
||||||
|
computed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((result != acct_total) || counted > 0) {
|
||||||
|
display = matches;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
to_show = (*i).second;
|
to_show = (*i).second;
|
||||||
|
|
@ -375,11 +381,12 @@ bool format_account::disp_subaccounts_p(const account_t * account,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool format_account::display_account(const account_t * account,
|
bool format_account::display_account(const account_t * account,
|
||||||
const item_predicate<account_t>& disp_pred)
|
const item_predicate<account_t>& disp_pred,
|
||||||
|
const bool even_top)
|
||||||
{
|
{
|
||||||
// Never display the master account, or an account that has already
|
// Never display the master account, or an account that has already
|
||||||
// been displayed.
|
// been displayed.
|
||||||
if (! account->parent || account->dflags & ACCOUNT_DISPLAYED)
|
if (! (account->parent || even_top) || account->dflags & ACCOUNT_DISPLAYED)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// At this point, one of two possibilities exists: the account is a
|
// At this point, one of two possibilities exists: the account is a
|
||||||
|
|
|
||||||
3
format.h
3
format.h
|
|
@ -161,7 +161,8 @@ class format_account : public item_handler<account_t>
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool display_account(const account_t * account,
|
static bool display_account(const account_t * account,
|
||||||
const item_predicate<account_t>& disp_pred);
|
const item_predicate<account_t>& disp_pred,
|
||||||
|
const bool even_top = false);
|
||||||
|
|
||||||
virtual void flush() {
|
virtual void flush() {
|
||||||
output_stream.flush();
|
output_stream.flush();
|
||||||
|
|
|
||||||
25
main.cc
25
main.cc
|
|
@ -159,7 +159,7 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
process_environment(envp, "LEDGER_");
|
process_environment(envp, "LEDGER_");
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
// These are here until 3.x, for backwards compatability.
|
// These are here for backwards compatability, but are deprecated.
|
||||||
|
|
||||||
if (const char * p = std::getenv("LEDGER"))
|
if (const char * p = std::getenv("LEDGER"))
|
||||||
process_option("file", p);
|
process_option("file", p);
|
||||||
|
|
@ -272,7 +272,7 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
regexps_to_predicate(arg, i, config, true,
|
regexps_to_predicate(arg, i, config, true,
|
||||||
command == "b" && ! config->show_expanded &&
|
command == "b" && ! config->show_subtotal &&
|
||||||
config->display_predicate.empty());
|
config->display_predicate.empty());
|
||||||
if (i != args.end())
|
if (i != args.end())
|
||||||
regexps_to_predicate(i, args.end(), config);
|
regexps_to_predicate(i, args.end(), config);
|
||||||
|
|
@ -284,7 +284,7 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
if (command == "b") {
|
if (command == "b") {
|
||||||
if (! config->show_empty)
|
if (! config->show_empty)
|
||||||
config->display_predicate = "T";
|
config->display_predicate = "T";
|
||||||
if (! config->show_expanded) {
|
if (! config->show_subtotal) {
|
||||||
if (! config->display_predicate.empty())
|
if (! config->display_predicate.empty())
|
||||||
config->display_predicate += "&";
|
config->display_predicate += "&";
|
||||||
config->display_predicate += "!l";
|
config->display_predicate += "!l";
|
||||||
|
|
@ -352,11 +352,12 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
bool show_all_related = false;
|
bool show_all_related = false;
|
||||||
|
|
||||||
if (command == "p" || command == "e") {
|
if (command == "p" || command == "e") {
|
||||||
config->show_related = show_all_related = true;
|
config->show_related =
|
||||||
config->show_expanded = true;
|
show_all_related =
|
||||||
|
config->show_subtotal = true;
|
||||||
}
|
}
|
||||||
else if (command == "E") {
|
else if (command == "E") {
|
||||||
config->show_expanded = true;
|
config->show_subtotal = true;
|
||||||
}
|
}
|
||||||
else if (config->show_related) {
|
else if (config->show_related) {
|
||||||
if (command == "r")
|
if (command == "r")
|
||||||
|
|
@ -469,12 +470,14 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
formatter->flush();
|
formatter->flush();
|
||||||
|
|
||||||
format_account acct_formatter(OUT(), format, config->display_predicate);
|
format_account acct_formatter(OUT(), format, config->display_predicate);
|
||||||
if (config->show_subtotals)
|
sum_accounts(journal->master);
|
||||||
sum_accounts(journal->master);
|
|
||||||
walk_accounts(journal->master, acct_formatter, sort_order.get());
|
walk_accounts(journal->master, acct_formatter, sort_order.get());
|
||||||
acct_formatter.flush();
|
acct_formatter.flush();
|
||||||
|
|
||||||
if (format_account::disp_subaccounts_p(journal->master)) {
|
journal->master->value = journal->master->total;
|
||||||
|
if (format_account::display_account(journal->master,
|
||||||
|
item_predicate<account_t>("T"),
|
||||||
|
true)) {
|
||||||
std::string end_format = "--------------------\n";
|
std::string end_format = "--------------------\n";
|
||||||
format.reset(end_format + f);
|
format.reset(end_format + f);
|
||||||
format.format_elements(OUT(), details_t(journal->master));
|
format.format_elements(OUT(), details_t(journal->master));
|
||||||
|
|
@ -537,7 +540,7 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
// collapse_transactions causes entries with multiple transactions
|
// collapse_transactions causes entries with multiple transactions
|
||||||
// to appear as entries with a subtotaled transaction for each
|
// to appear as entries with a subtotaled transaction for each
|
||||||
// commodity used.
|
// commodity used.
|
||||||
if (! config->show_subtotals)
|
if (config->show_collapsed)
|
||||||
formatter.reset(new collapse_transactions(formatter.release()));
|
formatter.reset(new collapse_transactions(formatter.release()));
|
||||||
|
|
||||||
// subtotal_transactions combines all the transactions it receives
|
// subtotal_transactions combines all the transactions it receives
|
||||||
|
|
@ -551,7 +554,7 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
// dow_transactions is like interval_transactions, except that it
|
// dow_transactions is like interval_transactions, except that it
|
||||||
// reports all the transactions that fall on each subsequent day
|
// reports all the transactions that fall on each subsequent day
|
||||||
// of the week.
|
// of the week.
|
||||||
if (config->show_expanded)
|
if (config->show_subtotal)
|
||||||
formatter.reset(new subtotal_transactions(formatter.release()));
|
formatter.reset(new subtotal_transactions(formatter.release()));
|
||||||
else if (report_interval.get())
|
else if (report_interval.get())
|
||||||
formatter.reset(new interval_transactions(formatter.release(),
|
formatter.reset(new interval_transactions(formatter.release(),
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ void value_expr_t::compute(value_t& result, const details_t& details,
|
||||||
assert(left);
|
assert(left);
|
||||||
left->compute(result, details);
|
left->compute(result, details);
|
||||||
if (result.type == value_t::BALANCE) {
|
if (result.type == value_t::BALANCE) {
|
||||||
// jww (2004-08-17): do something smarter here
|
// jww (2004-08-17): do something smarter here?
|
||||||
result.cast(value_t::AMOUNT);
|
result.cast(value_t::AMOUNT);
|
||||||
}
|
}
|
||||||
if (result.type == value_t::AMOUNT) {
|
if (result.type == value_t::AMOUNT) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue