close: don't repeat the description by default (#1165)

You'll almost certainly want the opening/closing descriptions to be
different, for filtering, so making --close-desc and --open-desc fully
independent is a better default.

And more doc cleanups.
This commit is contained in:
Simon Michael 2020-01-22 15:04:05 -08:00
parent ceedcb1a18
commit cda8909aae
2 changed files with 13 additions and 21 deletions

View File

@ -27,10 +27,10 @@ closemode = hledgerCommandMode
$(embedFileRelative "Hledger/Cli/Commands/Close.txt") $(embedFileRelative "Hledger/Cli/Commands/Close.txt")
[flagNone ["closing"] (setboolopt "closing") "show just closing transaction" [flagNone ["closing"] (setboolopt "closing") "show just closing transaction"
,flagNone ["opening"] (setboolopt "opening") "show just opening transaction" ,flagNone ["opening"] (setboolopt "opening") "show just opening transaction"
,flagReq ["close-to"] (\s opts -> Right $ setopt "close-to" s opts) "ACCT" ("account to transfer closing balances to (default: "++defclosingacct++")")
,flagReq ["open-from"] (\s opts -> Right $ setopt "open-from" s opts) "ACCT" ("account to transfer opening balances from (default: "++defopeningacct++")")
,flagReq ["close-desc"] (\s opts -> Right $ setopt "close-desc" s opts) "DESC" ("description for closing transaction (default: "++defclosingdesc++")") ,flagReq ["close-desc"] (\s opts -> Right $ setopt "close-desc" s opts) "DESC" ("description for closing transaction (default: "++defclosingdesc++")")
,flagReq ["open-desc"] (\s opts -> Right $ setopt "open-desc" s opts) "DESC" ("description for opening transaction (default: "++defopeningdesc++")") ,flagReq ["open-desc"] (\s opts -> Right $ setopt "open-desc" s opts) "DESC" ("description for opening transaction (default: "++defopeningdesc++")")
,flagReq ["close-to"] (\s opts -> Right $ setopt "close-to" s opts) "ACCT" ("account to transfer closing balances to (default: "++defclosingacct++")")
,flagReq ["open-from"] (\s opts -> Right $ setopt "open-from" s opts) "ACCT" ("account to transfer opening balances from (default: "++defopeningacct++")")
,flagNone ["explicit","x"] (setboolopt "explicit") "show all amounts explicitly" ,flagNone ["explicit","x"] (setboolopt "explicit") "show all amounts explicitly"
,flagNone ["interleaved"] (setboolopt "interleaved") "keep equity and non-equity postings adjacent" ,flagNone ["interleaved"] (setboolopt "interleaved") "keep equity and non-equity postings adjacent"
,flagNone ["show-costs"] (setboolopt "show-costs") "keep balances with different costs separate" ,flagNone ["show-costs"] (setboolopt "show-costs") "keep balances with different costs separate"
@ -50,6 +50,10 @@ close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
(False, False) -> (True, True) (False, False) -> (True, True)
(o, c) -> (o, c) (o, c) -> (o, c)
-- descriptions to use for the closing/opening transactions
closingdesc = fromMaybe (T.pack defclosingdesc) $ T.pack <$> maybestringopt "close-desc" rawopts
openingdesc = fromMaybe (T.pack defopeningdesc) $ T.pack <$> maybestringopt "open-desc" rawopts
-- accounts to close to and open from -- accounts to close to and open from
-- if only one is specified, it is used for both -- if only one is specified, it is used for both
(closingacct, openingacct) = (closingacct, openingacct) =
@ -61,17 +65,6 @@ close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
(Nothing, Just o) -> (o, o) (Nothing, Just o) -> (o, o)
(Nothing, Nothing) -> (T.pack defclosingacct, T.pack defopeningacct) (Nothing, Nothing) -> (T.pack defclosingacct, T.pack defopeningacct)
-- descriptions to use for the closing/opening transactions
-- if only one is specified, it is used for both
(closingdesc, openingdesc) =
let (mc, mo) =
(T.pack <$> maybestringopt "close-desc" rawopts, T.pack <$> maybestringopt "open-desc" rawopts)
in case (mc, mo) of
(Just c, Just o) -> (c, o)
(Just c, Nothing) -> (c, c)
(Nothing, Just o) -> (o, o)
(Nothing, Nothing) -> (T.pack defclosingdesc, T.pack defopeningdesc)
-- dates of the closing and opening transactions -- dates of the closing and opening transactions
ropts_ = ropts{balancetype_=HistoricalBalance, accountlistmode_=ALFlat} ropts_ = ropts{balancetype_=HistoricalBalance, accountlistmode_=ALFlat}
q = queryFromOpts today ropts_ q = queryFromOpts today ropts_

View File

@ -8,22 +8,21 @@ close out revenues/expenses to retained earnings at the end of a period.
_FLAGS _FLAGS
You can print just one of these transactions by using the You can print just one of these transactions by using the
`--opening` or `--closing` flag. `--closing` or `--opening` flag.
You can customise their descriptions with the
`--close-desc` and `--open-desc` options.
One amountless posting to `equity:opening/closing balances` is added One amountless posting to "equity:opening/closing balances" is added
to balance the transactions, by default. to balance the transactions, by default.
You can customise this account name with the `--close-to` and You can customise this account name with `--close-to` and `--open-from`;
`--open-from` options. (If you specify only one, it is used for both.) if you specify only one of these, it will be used for both.
Similarly, you can customise the transaction descriptions with
`--close-desc` and `--open-desc`.
With `--x/--explicit`, the equity posting's amount will be shown. With `--x/--explicit`, the equity posting's amount will be shown.
And if it involves multiple commodities, a posting for each commodity And if it involves multiple commodities, a posting for each commodity
will be shown (as with the print command). will be shown, as with the print command.
With `--interleaved`, the equity postings are shown next to the With `--interleaved`, the equity postings are shown next to the
postings they balance, which makes troubleshooting easier. postings they balance, which makes troubleshooting easier.
(It can also generate more postings.)
By default, transaction prices in the journal are ignored when By default, transaction prices in the journal are ignored when
generating the closing/opening transactions. generating the closing/opening transactions.