hledger package:hledger
Command-line interface for the hledger accounting system
The command-line interface for the hledger accounting system. Its
basic function is to read a plain text file describing financial
transactions and produce useful reports.
hledger is a robust, cross-platform set of tools for tracking money,
time, or any other commodity, using double-entry accounting and a
simple, editable file format, with command-line, terminal and web
interfaces. It is a Haskell rewrite of Ledger, and one of the leading
implementations of Plain Text Accounting. Read more at:
https://hledger.org
Build a cmdarg mode for a hledger command, from a help template and
flag/argument specifications. Reduces boilerplate a little, though the
complicated cmdargs flag and argument specs are still required.
The name and package version of a hledger binary, and the build's git
hash, the release date, and the binary's intended operating machine
and machine architecture, if we can detect these. Also, a copy of the
--version output from which it was parsed.
A hledger version string, as shown by hledger --version. This can
vary; some examples:
- dev builds: hledger 1.42.99-g2288f5193-20250422, mac-aarch64
- release builds: hledger 1.42.1, mac-aarch64
- older versions: hledger 1.21
A helper for addon commands: this parses options and arguments from
the current command line using the given hledger-style cmdargs mode,
and returns a CliOpts. Or, with --help or -h present, it prints long
or short help, and exits the program. When --debug is present, also
prints some debug output. Note this is not used by the main hledger
executable.
The help texts are generated from the mode. Long help includes the
full usage description generated by cmdargs (including all supported
options), framed by whatever pre- and postamble text the mode
specifies. It's intended that this forms a complete help document or
manual.
Short help is a truncated version of the above: the preamble and the
first part of the usage, up to the first line containing "flags:"
(normally this marks the start of the common hledger flags); plus a
mention of --help and the (presumed supported) common hledger options
not displayed.
Tips: Empty lines in the pre/postamble are removed by cmdargs; add a
space character to preserve them.
Parse hledger's --version output.
>>> isRight $ parseHledgerVersion "hledger 1.21"
True
>>> isRight $ parseHledgerVersion "hledger 1.42.1, mac-aarch64"
True
>>> isRight $ parseHledgerVersion "hledger 1.42.99-g2288f5193-20250422, mac-aarch64"
True