Documentation
¶
Index ¶
- func Install(ctx context.Context, opts *InstallHledgerOption) (string, error)
- func IsInstalled() (string, bool)
- type AccountType
- type Command
- type CommandError
- type Hledger
- type InstallHledgerOption
- type NewHledgerOption
- type Option
- func WithAccount(account ...string) Option
- func WithAccountTypes(acctTypes ...AccountType) Option
- func WithAlias(a, b string) Option
- func WithArg(arg ...string) Option
- func WithAuto() Option
- func WithAverage() Option
- func WithBudget(descPattern ...string) Option
- func WithCommodityStyle(style string) Option
- func WithCost() Option
- func WithCount() Option
- func WithCumulative() Option
- func WithDate(dateStr string) Option
- func WithDeclared() Option
- func WithDepth(level int, filter string) Option
- func WithDrop(n int) Option
- func WithEmpty() Option
- func WithForecast(period ...string) Option
- func WithFormat(format string) Option
- func WithHistorical() Option
- func WithIgnoreAssertions() Option
- func WithInferMarketPrice() Option
- func WithInvert() Option
- func WithNoTotal() Option
- func WithNotQuery(queryType QueryType, value string) Option
- func WithOutputType(outputType OutputType) Option
- func WithPercent() Option
- func WithPeriod(p PeriodType) Option
- func WithPivot(tagName string) Option
- func WithPretty() Option
- func WithQuery(queryType QueryType, value string) Option
- func WithRowTotal() Option
- func WithSortAmount() Option
- func WithStatus(trStatus TrStatusType) Option
- func WithStrict() Option
- func WithToday(date string) Option
- func WithTree() Option
- func WithTxnBalancing(balancingType TxnBalancingType) Option
- func WithValuation(commodity string, valType ValuationType) Option
- func WithValueChange() Option
- type OutputType
- type PeriodType
- type QueryType
- type TrStatusType
- type TxnBalancingType
- type ValuationType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Install ¶
func Install(ctx context.Context, opts *InstallHledgerOption) (string, error)
Install downloads the hledger binary to the given path.
Use this before New or manually install hledger.
func IsInstalled ¶
Types ¶
type AccountType ¶
type AccountType string
const ( AccountTypeAsset AccountType = "A" AccountTypeLiability AccountType = "L" AccountTypeEquity AccountType = "E" AccountTypeRevenue AccountType = "R" AccountTypeExpense AccountType = "X" AccountTypeCash AccountType = "C" AccountTypeConversion AccountType = "V" )
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
func (*Command) Run ¶
Run executes the hledger command and captures its stdout and stderr. It returns the stdout output as a byte slice.
If the command fails, it returns a *CommandError containing the command's stderr.
func (*Command) Stream ¶
Stream executes the hledger command and writes its stdout directly to the provided io.Writer. This is typically used for generating large reports (like CSV or JSON) to avoid buffering the entire output into memory.
If the command fails, it returns a *CommandError containing the command's stderr.
type CommandError ¶
func (*CommandError) Error ¶
func (e *CommandError) Error() string
func (*CommandError) Unwrap ¶
func (e *CommandError) Unwrap() error
type Hledger ¶
func New ¶
func New(opts *NewHledgerOption) (*Hledger, error)
New starts a Hledger instance.
Requires hledger installation. New will check the user cache directory if hledger is not available on PATH or if no explicit binary path is given.
If multiple hledger versions are found in the cache directory, New will use the latest version determined with semver
func (*Hledger) NewCommand ¶
NewCommand returns a *Command instance with the given options applied.
command can be an empty string(e.g. to use --version flag)
type InstallHledgerOption ¶
type InstallHledgerOption struct {
Dir string
Version string
Logger *slog.Logger
LogLevel slog.Level
}
if Logger is not nil, LogLevel will be ignored.
type NewHledgerOption ¶
type Option ¶
type Option func(*Command)
func WithAccount ¶
func WithAccountTypes ¶
func WithAccountTypes(acctTypes ...AccountType) Option
func WithArg ¶
WithArg will simply append given string arguments. Use WithArg if a specific argument option is not implemented by the library.
func WithAverage ¶
func WithAverage() Option
func WithBudget ¶
descPattern is optional. It will only parse the very first argument
func WithCommodityStyle ¶
func WithCumulative ¶
func WithCumulative() Option
func WithDeclared ¶
func WithDeclared() Option
func WithDepth ¶
show only top `level` levels of accounts. If `filter` is set, only apply limiting to accounts matching the regular expression.
func WithForecast ¶
Period is optional. It will only parse the very first argument.
func WithFormat ¶
func WithHistorical ¶
func WithHistorical() Option
Calculate with postings from journal start to column end, ie "all postings from before report start date until this column's end"
func WithIgnoreAssertions ¶
func WithIgnoreAssertions() Option
func WithInferMarketPrice ¶
func WithInferMarketPrice() Option
func WithInvert ¶
func WithInvert() Option
func WithNoTotal ¶
func WithNoTotal() Option
func WithNotQuery ¶
WithNotQuery prepends `not:` to a query to negate the match.
func WithOutputType ¶
func WithOutputType(outputType OutputType) Option
See https://hledger.org/1.50/hledger.html#output-format for supported formats. Note that this library will not check the availability.
func WithPercent ¶
func WithPercent() Option
func WithPeriod ¶
func WithPeriod(p PeriodType) Option
See https://hledger.org/1.50/hledger.html#report-start--end-date
func WithPivot ¶
With --pivot PIVOTEXPR, some other field's (or multiple fields') value is used as a synthetic account name, causing different grouping and display.
func WithPretty ¶
func WithPretty() Option
func WithQuery ¶
Check https://hledger.org/1.50/hledger.html#queries for more information.
func WithSortAmount ¶
func WithSortAmount() Option
func WithStatus ¶
func WithStatus(trStatus TrStatusType) Option
Match unmarked, pending, or cleared transactions respectively.
func WithStrict ¶
func WithStrict() Option
func WithTxnBalancing ¶
func WithTxnBalancing(balancingType TxnBalancingType) Option
func WithValuation ¶
func WithValuation(commodity string, valType ValuationType) Option
show amounts converted to their value on the specified date(s) in their default valuation
func WithValueChange ¶
func WithValueChange() Option
type OutputType ¶
type OutputType string
const ( OutputTXT OutputType = "txt" OutputCSV OutputType = "csv" OutputHTML OutputType = "html" OutputTSV OutputType = "tsv" OutputJSON OutputType = "json" OutputFODS OutputType = "fods" )
type PeriodType ¶
type PeriodType string
const ( PeriodDaily PeriodType = "--daily" PeriodWeekly PeriodType = "--weekly" PeriodMonthly PeriodType = "--monthly" PeriodQuarterly PeriodType = "--quarterly" PeriodYearly PeriodType = "--yearly" )
func NewCmdPeriod ¶
func NewCmdPeriod(periodStr string) PeriodType
See https://hledger.org/1.50/hledger.html#period-expressions
type QueryType ¶
type QueryType string
const ( QueryTypeAcct QueryType = "acct" // acct:REGEX QueryTypeAmt QueryType = "amt" // amt:N, amt:'<N', amt:'<=N', amt:'>N', amt:'>=N' QueryTypeCode QueryType = "code" // code:REGEX QueryTypeCur QueryType = "cur" // cur:REGEX QueryTypeDesc QueryType = "desc" // desc:REGEX QueryTypeDate2 QueryType = "date2" // date2:PERIODEXPR QueryTypeNote QueryType = "note" // note:REGEX QueryTypePayee QueryType = "payee" // payee:REGEX QueryTypeReal QueryType = "real" // real:, real:0 QueryTypeTag QueryType = "tag" // tag:NAMEREGEX[=VALREGEX] )
type TrStatusType ¶
type TrStatusType string
const ( TrStatusUnmarked TrStatusType = "" TrStatusPending TrStatusType = "!" TrStatusCleared TrStatusType = "*" )
type TxnBalancingType ¶
type TxnBalancingType string
const ( TxnBalancingOld TxnBalancingType = "old" TxnBalancingExact TxnBalancingType = "exact" )
type ValuationType ¶
type ValuationType string
You can also do
WithValuation(ValuationType("YYYY-mm-dd"))
to use custom date.
const ( // Convert amounts to their value in the default valuation commodity using current market prices (as of when report is generated). ValuationNow ValuationType = "now" // Convert amounts to their value in the default valuation commodity, using market prices on the last day of the report period (or if unspecified, the journal's end date); or in multiperiod reports, market prices on the last day of each subperiod. ValuationEnd ValuationType = "end" // Convert amounts to their value in the default valuation commodity, using market prices on each posting's date. ValuationThen ValuationType = "then" )
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
command_err
command
|
|
|
default_args
command
|
|
|
install
command
|
|
|
simple_execution
command
|
|
|
stream
command
|