cli: simplify command doc inclusion, give them normal heading structure
This commit is contained in:
parent
81f596b1fb
commit
0567935e4b
@ -105,6 +105,7 @@ import Hledger
|
|||||||
import Hledger.Cli.DocFiles
|
import Hledger.Cli.DocFiles
|
||||||
import Hledger.Cli.Version
|
import Hledger.Cli.Version
|
||||||
import Data.Time.Clock.POSIX (POSIXTime)
|
import Data.Time.Clock.POSIX (POSIXTime)
|
||||||
|
import Data.List (isPrefixOf, isSuffixOf)
|
||||||
|
|
||||||
|
|
||||||
-- common cmdargs flags
|
-- common cmdargs flags
|
||||||
@ -371,29 +372,37 @@ hledgerCommandMode doc unnamedflaggroup namedflaggroups hiddenflaggroup argsdesc
|
|||||||
,modeArgs = argsdescr
|
,modeArgs = argsdescr
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Parse a command's documentation, as follows:
|
-- | Parse a command's help text file (Somecommand.txt).
|
||||||
|
-- This is generated from the command's doc source file (Somecommand.md)
|
||||||
|
-- by Shake cmdhelp, and it should be formatted as follows:
|
||||||
--
|
--
|
||||||
-- - First line: the command name then any aliases, as one or more space or comma-separated words
|
-- - First line: main command name
|
||||||
--
|
--
|
||||||
-- - Second line to a line containing just _FLAGS, or the end: the short help
|
-- - Third line: command aliases, comma-and-space separated, in parentheses (optional)
|
||||||
--
|
--
|
||||||
-- - Any lines after _FLAGS: the long help (split into lines for cmdargs)
|
-- - Fifth or third line to the line containing just _FLAGS (or end of file): short command help
|
||||||
--
|
--
|
||||||
-- The CLI help displays the short help, then the cmdargs-generated
|
-- - Any lines after _FLAGS: long command help
|
||||||
-- flags list, then the long help (which some day we might make
|
--
|
||||||
-- optional again). The manual displays the short help followed by
|
-- The CLI --help displays the short help, the flags help generated by cmdargs,
|
||||||
-- the long help, with no flags list.
|
-- then the long help (which some day we might make optional again).
|
||||||
|
-- The manual displays the short help, then the long help (but not the flags list).
|
||||||
--
|
--
|
||||||
parseCommandDoc :: CommandDoc -> Maybe ([Name], String, [String])
|
parseCommandDoc :: CommandDoc -> Maybe ([Name], String, [String])
|
||||||
parseCommandDoc t =
|
parseCommandDoc t =
|
||||||
case lines t of
|
case lines t of
|
||||||
[] -> Nothing
|
[] -> Nothing
|
||||||
(l:ls) -> Just (names, shorthelp, longhelplines)
|
(l1:_:l3:ls) -> Just (cmdname:cmdaliases, shorthelp, longhelplines)
|
||||||
where
|
where
|
||||||
names = words $ map (\c -> if c `elem` [',','\\'] then ' ' else c) l
|
cmdname = strip l1
|
||||||
(shorthelpls, longhelpls) = break (== "_FLAGS") ls
|
(cmdaliases, rest) =
|
||||||
|
if "(" `isPrefixOf` l3 && ")" `isSuffixOf` l3
|
||||||
|
then (words $ filter (/=',') $ drop 1 $ init l3, ls)
|
||||||
|
else ([], l3:ls)
|
||||||
|
(shorthelpls, longhelpls) = break (== "_FLAGS") $ dropWhile (=="") rest
|
||||||
shorthelp = unlines $ reverse $ dropWhile null $ reverse shorthelpls
|
shorthelp = unlines $ reverse $ dropWhile null $ reverse shorthelpls
|
||||||
longhelplines = dropWhile null $ drop 1 longhelpls
|
longhelplines = dropWhile null $ drop 1 longhelpls
|
||||||
|
_ -> Nothing -- error' "misformatted command help text file"
|
||||||
|
|
||||||
-- | Get a mode's usage message as a nicely wrapped string.
|
-- | Get a mode's usage message as a nicely wrapped string.
|
||||||
showModeUsage :: Mode a -> String
|
showModeUsage :: Mode a -> String
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
accounts\
|
## accounts
|
||||||
|
|
||||||
Show account names.
|
Show account names.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
activity\
|
## activity
|
||||||
|
|
||||||
Show an ascii barchart of posting counts per interval.
|
Show an ascii barchart of posting counts per interval.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
add\
|
## add
|
||||||
|
|
||||||
Prompt for transactions and add them to the journal.
|
Prompt for transactions and add them to the journal.
|
||||||
Any arguments will be used as default inputs for the first N prompts.
|
Any arguments will be used as default inputs for the first N prompts.
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
aregister, areg\
|
## aregister
|
||||||
|
|
||||||
|
(areg)
|
||||||
|
|
||||||
Show the transactions and running historical balance of a single account,
|
Show the transactions and running historical balance of a single account,
|
||||||
with each transaction displayed as one line.
|
with each transaction displayed as one line.
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
balance, bal\
|
## balance
|
||||||
|
|
||||||
|
(bal)
|
||||||
|
|
||||||
Show accounts and their balances.
|
Show accounts and their balances.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
balancesheet, bs\
|
## balancesheet
|
||||||
|
|
||||||
|
(bs)
|
||||||
|
|
||||||
This command displays a [balance sheet](https://en.wikipedia.org/wiki/Balance_sheet),
|
This command displays a [balance sheet](https://en.wikipedia.org/wiki/Balance_sheet),
|
||||||
showing historical ending balances of asset and liability accounts.
|
showing historical ending balances of asset and liability accounts.
|
||||||
(To see equity as well, use the [balancesheetequity](#balancesheetequity) command.)
|
(To see equity as well, use the [balancesheetequity](#balancesheetequity) command.)
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
balancesheetequity, bse\
|
## balancesheetequity
|
||||||
|
|
||||||
|
(bse)
|
||||||
|
|
||||||
This command displays a [balance sheet](https://en.wikipedia.org/wiki/Balance_sheet),
|
This command displays a [balance sheet](https://en.wikipedia.org/wiki/Balance_sheet),
|
||||||
showing historical ending balances of asset, liability and equity accounts.
|
showing historical ending balances of asset, liability and equity accounts.
|
||||||
Amounts are shown with normal positive sign, as in conventional
|
Amounts are shown with normal positive sign, as in conventional
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
cashflow, cf\
|
## cashflow
|
||||||
|
|
||||||
|
(cf)
|
||||||
|
|
||||||
This command displays a [cashflow statement](https://en.wikipedia.org/wiki/Cash_flow_statement),
|
This command displays a [cashflow statement](https://en.wikipedia.org/wiki/Cash_flow_statement),
|
||||||
showing the inflows and outflows affecting "cash" (ie, liquid, easily convertible) assets.
|
showing the inflows and outflows affecting "cash" (ie, liquid, easily convertible) assets.
|
||||||
Amounts are shown with normal positive sign, as in conventional
|
Amounts are shown with normal positive sign, as in conventional
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
check\
|
## check
|
||||||
|
|
||||||
Check for various kinds of errors in your data.
|
Check for various kinds of errors in your data.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
close, equity\
|
## close
|
||||||
|
|
||||||
|
(equity)
|
||||||
|
|
||||||
Prints a sample "closing" transaction bringing specified account balances to zero,
|
Prints a sample "closing" transaction bringing specified account balances to zero,
|
||||||
and an inverse "opening" transaction restoring the same account balances.
|
and an inverse "opening" transaction restoring the same account balances.
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
codes\
|
## codes
|
||||||
|
|
||||||
List the codes seen in transactions, in the order parsed.
|
List the codes seen in transactions, in the order parsed.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
commodities\
|
## commodities
|
||||||
|
|
||||||
List all commodity/currency symbols used or declared in the journal.
|
List all commodity/currency symbols used or declared in the journal.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
descriptions\
|
## descriptions
|
||||||
|
|
||||||
List the unique descriptions that appear in transactions.
|
List the unique descriptions that appear in transactions.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
diff\
|
## diff
|
||||||
|
|
||||||
Compares a particular account's transactions in two input files.
|
Compares a particular account's transactions in two input files.
|
||||||
It shows any transactions to this account which are in one file but
|
It shows any transactions to this account which are in one file but
|
||||||
not in the other.
|
not in the other.
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
files\
|
## files
|
||||||
|
|
||||||
List all files included in the journal. With a REGEX argument,
|
List all files included in the journal. With a REGEX argument,
|
||||||
only file names matching the regular expression (case sensitive) are shown.
|
only file names matching the regular expression (case sensitive) are shown.
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
help\
|
## help
|
||||||
|
|
||||||
Show the hledger user manual in the terminal, with `info`, `man`, or a pager.
|
Show the hledger user manual in the terminal, with `info`, `man`, or a pager.
|
||||||
With a TOPIC argument, open it at that topic if possible.
|
With a TOPIC argument, open it at that topic if possible.
|
||||||
TOPIC can be any heading in the manual, or a heading prefix, case insensitive.
|
TOPIC can be any heading in the manual, or a heading prefix, case insensitive.
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import\
|
## import
|
||||||
|
|
||||||
Read new transactions added to each FILE since last run, and add them to
|
Read new transactions added to each FILE since last run, and add them to
|
||||||
the journal. Or with --dry-run, just print the transactions
|
the journal. Or with --dry-run, just print the transactions
|
||||||
that would be added. Or with --catchup, just mark all of the FILEs'
|
that would be added. Or with --catchup, just mark all of the FILEs'
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
incomestatement, is\
|
## incomestatement
|
||||||
|
|
||||||
|
(is)
|
||||||
|
|
||||||
This command displays an
|
This command displays an
|
||||||
[income statement](http://en.wikipedia.org/wiki/Income_statement),
|
[income statement](http://en.wikipedia.org/wiki/Income_statement),
|
||||||
showing revenues and expenses during one or more periods.
|
showing revenues and expenses during one or more periods.
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
notes\
|
## notes
|
||||||
|
|
||||||
List the unique notes that appear in transactions.
|
List the unique notes that appear in transactions.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
payees\
|
## payees
|
||||||
|
|
||||||
List the unique payee/payer names that appear in transactions.
|
List the unique payee/payer names that appear in transactions.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
prices\
|
## prices
|
||||||
|
|
||||||
Print [market price directives](https://hledger.org/hledger.html#market-prices) from the journal.
|
Print [market price directives](https://hledger.org/hledger.html#market-prices) from the journal.
|
||||||
With --infer-market-prices, generate additional market prices from [costs](https://hledger.org/hledger.html#costs).
|
With --infer-market-prices, generate additional market prices from [costs](https://hledger.org/hledger.html#costs).
|
||||||
With --infer-reverse-prices, also generate market prices by inverting known prices.
|
With --infer-reverse-prices, also generate market prices by inverting known prices.
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
print\
|
## print
|
||||||
|
|
||||||
Show transaction journal entries, sorted by date.
|
Show transaction journal entries, sorted by date.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
register, reg\
|
## register
|
||||||
|
|
||||||
|
(reg)
|
||||||
|
|
||||||
Show postings and their running total.
|
Show postings and their running total.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
rewrite\
|
## rewrite
|
||||||
|
|
||||||
Print all transactions, rewriting the postings of matched transactions.
|
Print all transactions, rewriting the postings of matched transactions.
|
||||||
For now the only rewrite available is adding new postings, like print --auto.
|
For now the only rewrite available is adding new postings, like print --auto.
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
roi\
|
## roi
|
||||||
|
|
||||||
Shows the time-weighted (TWR) and money-weighted (IRR) rate of return
|
Shows the time-weighted (TWR) and money-weighted (IRR) rate of return
|
||||||
on your investments.
|
on your investments.
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
stats\
|
## stats
|
||||||
|
|
||||||
Show journal and performance statistics.
|
Show journal and performance statistics.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
tags\
|
## tags
|
||||||
List the [tags](#tags) used in the journal, or their values.
|
|
||||||
|
List the tags used in the journal, or their values.
|
||||||
|
|
||||||
<!-- same section name as Journal > Tags, if reordering these update all #tags[-1] links -->
|
<!-- same section name as Journal > Tags, if reordering these update all #tags[-1] links -->
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
test\
|
## test
|
||||||
|
|
||||||
Run built-in unit tests.
|
Run built-in unit tests.
|
||||||
|
|
||||||
_FLAGS
|
_FLAGS
|
||||||
|
|||||||
@ -1,41 +1,41 @@
|
|||||||
m4_dnl _commands_(HEADINGHASHES)
|
m4_dnl _commands_
|
||||||
m4_dnl Used in the hledger manual to include all command docs.
|
m4_dnl Used in the hledger manual to include all command docs.
|
||||||
m4_dnl Keep synced with Hledger.Cli.Commands.commandsList, hledger.m4.md
|
m4_dnl Keep synced with Hledger.Cli.Commands.commandsList, hledger.m4.md
|
||||||
m4_define({{_commands_}},
|
m4_define({{_commands_}},
|
||||||
{{
|
{{
|
||||||
_command_({{$1 accounts}} ,{{Accounts}})
|
_command_({{Accounts}})
|
||||||
_command_({{$1 activity}} ,{{Activity}})
|
_command_({{Activity}})
|
||||||
_command_({{$1 add}} ,{{Add}})
|
_command_({{Add}})
|
||||||
_command_({{$1 aregister}} ,{{Aregister}})
|
_command_({{Aregister}})
|
||||||
_command_({{$1 balance}} ,{{Balance}})
|
_command_({{Balance}})
|
||||||
_command_({{$1 balancesheet}} ,{{Balancesheet}})
|
_command_({{Balancesheet}})
|
||||||
_command_({{$1 balancesheetequity}} ,{{Balancesheetequity}})
|
_command_({{Balancesheetequity}})
|
||||||
_command_({{$1 cashflow}} ,{{Cashflow}})
|
_command_({{Cashflow}})
|
||||||
_command_({{$1 check}} ,{{Check}})
|
_command_({{Check}})
|
||||||
_command_({{$1 close}} ,{{Close}})
|
_command_({{Close}})
|
||||||
_command_({{$1 codes}} ,{{Codes}})
|
_command_({{Codes}})
|
||||||
_command_({{$1 commodities}} ,{{Commodities}})
|
_command_({{Commodities}})
|
||||||
_command_({{$1 descriptions}} ,{{Descriptions}})
|
_command_({{Descriptions}})
|
||||||
_command_({{$1 diff}} ,{{Diff}})
|
_command_({{Diff}})
|
||||||
_command_({{$1 files}} ,{{Files}})
|
_command_({{Files}})
|
||||||
_command_({{$1 help}} ,{{Help}})
|
_command_({{Help}})
|
||||||
_command_({{$1 import}} ,{{Import}})
|
_command_({{Import}})
|
||||||
_command_({{$1 incomestatement}} ,{{Incomestatement}})
|
_command_({{Incomestatement}})
|
||||||
_command_({{$1 notes}} ,{{Notes}})
|
_command_({{Notes}})
|
||||||
_command_({{$1 payees}} ,{{Payees}})
|
_command_({{Payees}})
|
||||||
_command_({{$1 prices}} ,{{Prices}})
|
_command_({{Prices}})
|
||||||
_command_({{$1 print}} ,{{Print}})
|
_command_({{Print}})
|
||||||
_command_({{$1 register}} ,{{Register}})
|
_command_({{Register}})
|
||||||
_command_({{$1 rewrite}} ,{{Rewrite}})
|
_command_({{Rewrite}})
|
||||||
_command_({{$1 roi}} ,{{Roi}})
|
_command_({{Roi}})
|
||||||
_command_({{$1 stats}} ,{{Stats}})
|
_command_({{Stats}})
|
||||||
_command_({{$1 tags}} ,{{Tags}})
|
_command_({{Tags}})
|
||||||
_command_({{$1 test}} ,{{Test}})
|
_command_({{Test}})
|
||||||
}})m4_dnl
|
}})m4_dnl
|
||||||
m4_dnl
|
m4_dnl
|
||||||
m4_dnl _command_(NAME, MDFILE)
|
m4_dnl _command_(MDFILE)
|
||||||
m4_dnl Create a command heading and include its doc.
|
m4_dnl Include a command's doc. The doc should start with a level two heading.
|
||||||
m4_define({{_command_}},
|
m4_define({{_command_}},
|
||||||
{{$1
|
{{
|
||||||
_include_(hledger/Hledger/Cli/Commands/$2.md)
|
_include_(hledger/Hledger/Cli/Commands/$1.md)
|
||||||
}})m4_dnl
|
}})m4_dnl
|
||||||
|
|||||||
@ -5751,8 +5751,9 @@ m4_dnl _notman_({{
|
|||||||
|
|
||||||
Next, each command is described in detail, in alphabetical order.
|
Next, each command is described in detail, in alphabetical order.
|
||||||
|
|
||||||
m4_dnl cf Hledger/Cli/Commands/commands.m4:
|
m4_dnl Include the command docs. Each starts with a level 2 heading.
|
||||||
_commands_({{##}})
|
m4_dnl (To change that, see Hledger/Cli/Commands/{*.md,commands.m4})
|
||||||
|
_commands_
|
||||||
|
|
||||||
<a name="common-tasks"></a>
|
<a name="common-tasks"></a>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user