hledger-1.31: Command-line interface for the hledger accounting system

Safe Haskell | Safe-Inferred
Language | Haskell2010

Hledger.Cli.Main

Description

hledger - a ledger-compatible accounting tool. Copyright (c) 2007-2022 Simon Michael simon@joyful.com Released under GPL version 3 or later.

hledger is a partial haskell clone of John Wiegley's "ledger". It generates ledger-compatible register & balance reports from a plain text journal, and demonstrates a functional implementation of ledger. For more information, see http://hledger.org .

This module provides the main function for the hledger command-line executable. It is exposed here so that it can be imported by eg benchmark scripts.

You can use the command line:

    $ hledger --help

or ghci:

    $ ghci hledger
    > Right j <- readJournalFile definputopts "examples/sample.journal"
    > register [] ["income","expenses"] j
    2008/01/01 income               income:salary                   $-1          $-1
    2008/06/01 gift                 income:gifts                    $-1          $-2
    2008/06/03 eat & shop           expenses:food                    $1          $-1
                                    expenses:supplies                $1            0
    > balance [Depth "1"] [] l
                     $-1  assets
                      $2  expenses
                     $-2  income
                      $1  liabilities
    > j <- defaultJournal

etc.

Synopsis

- mainmode :: [Name] -> Mode RawOpts
- main :: IO ()
- argsToCliOpts :: [String] -> [String] -> IO CliOpts
- moveFlagsAfterCommand :: [String] -> [String]
- isMovableNoArgFlag :: [Char] -> Bool
- isMovableReqArgFlag :: [Char] -> Bool
- isMovableArgFlagAndValue :: [Char] -> Bool
- isValue :: String -> Bool
- flagstomove :: [Flag RawOpts]
- noargflagstomove :: [Name]
- reqargflagstomove :: [Name]
- optargflagstomove :: [Name]

# Documentation

mainmode :: [Name] -> Mode RawOpts #

The overall cmdargs mode describing hledger's command-line options and subcommands.

main :: IO () #

Let's go!

argsToCliOpts :: [String] -> [String] -> IO CliOpts #

Parse hledger CLI options from these command line arguments and add-on command names, or raise any error.

moveFlagsAfterCommand :: [String] -> [String] #

A hacky workaround for cmdargs not accepting flags before the subcommand name: try to detect and move such flags after the command. This allows the user to put them in either position. The order of options is not preserved, but that should be ok.

Since we're not parsing flags as precisely as cmdargs here, this is imperfect. We make a decent effort to: - move all no-argument helpinputreport flags - move all required-argument helpinputreport flags along with their values, space-separated or not - ensure --debug has an argument (because.. "or this all goes to hell") - not confuse things further or cause misleading errors.

isMovableNoArgFlag :: [Char] -> Bool #

isMovableReqArgFlag :: [Char] -> Bool #

isMovableArgFlagAndValue :: [Char] -> Bool #

isValue :: String -> Bool #

flagstomove :: [Flag RawOpts] #

noargflagstomove :: [Name] #

reqargflagstomove :: [Name] #

optargflagstomove :: [Name] #