ExLedger.LedgerCLI (ex_ledger v0.6.0)

Wrapper for calling the external ledger CLI binary.

Summary

Functions

Runs the ledger CLI with the given arguments.

Runs the ledger CLI for a specific ledger file and command.

Runs ledger xml for a specific ledger file.

Types

cmd_error()

@type cmd_error() :: {non_neg_integer(), String.t()}

Functions

run(args, opts \\ [])

@spec run(
  [String.t()],
  keyword()
) :: {:ok, String.t()} | {:error, cmd_error()}

Runs the ledger CLI with the given arguments.

Returns {:ok, output} on success or {:error, {status, output}} on failure.

run_with_file(file, command, args \\ [], opts \\ [])

@spec run_with_file(String.t(), String.t(), [String.t()], keyword()) ::
  {:ok, String.t()} | {:error, cmd_error()}

Runs the ledger CLI for a specific ledger file and command.

Example:

ExLedger.LedgerCLI.run_with_file("/tmp/ledger.dat", "balance", ["Assets"])

xml(file, args \\ [], opts \\ [])

@spec xml(String.t(), [String.t()], keyword()) ::
  {:ok, String.t()} | {:error, cmd_error()}

Runs ledger xml for a specific ledger file.

Returns the raw XML output from ledger-cli.

Options

  • :ledger_bin - Path to ledger binary (default: "ledger")
  • :cmd_opts - Additional options passed to System.cmd/3

Example

{:ok, xml} = ExLedger.LedgerCLI.xml("/tmp/ledger.dat")