hledger/hledger.hs

94 lines
2.6 KiB
Haskell
Raw Normal View History

2009-02-27 06:09:16 +03:00
-- sp doesn't like.. #!/usr/bin/env runhaskell
{-# OPTIONS_GHC -cpp #-}
2008-10-01 11:04:47 +04:00
{-|
hledger - a ledger-compatible text-based accounting tool.
2009-01-18 00:03:34 +03:00
Copyright (c) 2007-2009 Simon Michael <simon@joyful.com>
Released under GPL version 3 or later.
2008-10-01 11:04:47 +04:00
2009-04-03 01:02:27 +04:00
hledger is a partial haskell clone of John Wiegley's "ledger" text-based
accounting tool. It generates ledger-compatible register & balance
2009-04-03 09:58:14 +04:00
reports from a plain text journal, and demonstrates a functional
2009-04-03 01:02:27 +04:00
implementation of ledger. For more information, see ledger.org .
2008-10-01 11:04:47 +04:00
2008-10-12 13:17:21 +04:00
You can use the command line:
> $ hledger --help
or ghci:
> $ ghci hledger
2008-12-05 11:51:14 +03:00
> > l <- ledgerfromfilewithopts [] [] "sample.ledger"
2008-10-12 13:17:21 +04:00
> > balance [] [] l
> $-1 assets
> $2 expenses
> $-2 income
2008-12-05 11:51:14 +03:00
> $1 liabilities
2008-10-12 13:17:21 +04:00
> > register [] ["income","expenses"] l
2008-12-05 11:51:14 +03:00
> 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
2008-10-12 13:17:21 +04:00
> expenses:supplies $1 0
-}
2007-01-28 13:30:24 +03:00
2008-10-12 13:17:21 +04:00
module Main (
2009-01-25 15:52:28 +03:00
-- for easy ghci access
module Main,
2008-10-12 13:17:21 +04:00
module Utils,
module Options,
module BalanceCommand,
module PrintCommand,
module RegisterCommand,
module HistogramCommand,
#ifdef VTY
module UICommand,
#endif
2009-01-25 15:52:28 +03:00
#ifdef HAPPS
module WebCommand,
#endif
2008-10-12 13:17:21 +04:00
)
2007-02-10 22:16:56 +03:00
where
2008-12-10 00:00:46 +03:00
import Control.Monad.Error
2008-09-28 07:43:59 +04:00
import qualified Data.Map as Map (lookup)
2008-12-10 00:00:46 +03:00
import System.IO
import Version (versionmsg)
import Ledger
import Utils (withLedgerDo)
2008-10-12 13:17:21 +04:00
import Options
import Tests
import BalanceCommand
import PrintCommand
import RegisterCommand
import HistogramCommand
#ifdef VTY
2009-01-25 15:52:28 +03:00
import UICommand
#endif
#ifdef HAPPS
2009-01-25 15:52:28 +03:00
import WebCommand
#endif
2007-02-09 03:18:20 +03:00
2007-02-09 03:18:20 +03:00
main :: IO ()
2007-01-30 12:07:12 +03:00
main = do
(opts, cmd, args) <- parseArguments
run cmd opts args
where
run cmd opts args
| Help `elem` opts = putStr $ usage
| Version `elem` opts = putStr versionmsg
| cmd `isPrefixOf` "balance" = withLedgerDo opts args balance
| cmd `isPrefixOf` "print" = withLedgerDo opts args print'
| cmd `isPrefixOf` "register" = withLedgerDo opts args register
| cmd `isPrefixOf` "histogram" = withLedgerDo opts args histogram
#ifdef VTY
| cmd `isPrefixOf` "ui" = withLedgerDo opts args ui
#endif
#ifdef HAPPS
| cmd `isPrefixOf` "web" = withLedgerDo opts args web
#endif
| cmd `isPrefixOf` "test" = runtests opts args >> return ()
| otherwise = putStr $ usage