1 -- #!/usr/bin/env runhaskell <- sp doesn't like 2 {-# OPTIONS_GHC -cpp #-} 3 {-| 4 hledger - a ledger-compatible text-based accounting tool. 5 6 Copyright (c) 2007-2009 Simon Michael <simon@joyful.com> 7 Released under GPL version 3 or later. 8 9 hledger is a partial haskell clone of John Wiegley's "ledger" text-based 10 accounting tool. It generates ledger-compatible register & balance 11 reports from a plain text journal, and demonstrates a functional 12 implementation of ledger. For more information, see http:\/\/hledger.org . 13 14 You can use the command line: 15 16 > $ hledger --help 17 18 or ghci: 19 20 > $ ghci hledger 21 > > l <- readLedger "sample.ledger" 22 > > register [] ["income","expenses"] l 23 > 2008/01/01 income income:salary $-1 $-1 24 > 2008/06/01 gift income:gifts $-1 $-2 25 > 2008/06/03 eat & shop expenses:food $1 $-1 26 > expenses:supplies $1 0 27 > > balance [Depth "1"] [] l 28 > $-1 assets 29 > $2 expenses 30 > $-2 income 31 > $1 liabilities 32 > > l <- myLedger 33 > > t <- myTimelog 34 35 See "Ledger.Ledger" for more examples. 36 -} 37 38 module Main where 39 import Control.Monad.Error 40 import Prelude hiding (putStr) 41 import System.IO (stderr) 42 import System.IO.UTF8 43 import qualified Data.Map as Map (lookup) 44 45 import Commands.All 46 import Ledger 47 import Options 48 import Tests 49 import Utils (withLedgerDo) 50 import Version (versionmsg) 51 52 main :: IO () 53 main = do 54 (opts, cmd, args) <- parseArguments 55 run cmd opts args 56 where 57 run cmd opts args 58 | Help `elem` opts = putStr $ usage 59 | Version `elem` opts = putStr versionmsg 60 | cmd `isPrefixOf` "balance" = withLedgerDo opts args cmd balance 61 | cmd `isPrefixOf` "convert" = withLedgerDo opts args cmd convert 62 | cmd `isPrefixOf` "print" = withLedgerDo opts args cmd print' 63 | cmd `isPrefixOf` "register" = withLedgerDo opts args cmd register 64 | cmd `isPrefixOf` "histogram" = withLedgerDo opts args cmd histogram 65 | cmd `isPrefixOf` "add" = withLedgerDo opts args cmd add 66 | cmd `isPrefixOf` "stats" = withLedgerDo opts args cmd stats 67 #ifdef VTY 68 | cmd `isPrefixOf` "ui" = withLedgerDo opts args cmd ui 69 #endif 70 #ifdef HAPPS 71 | cmd `isPrefixOf` "web" = withLedgerDo opts args cmd web 72 #endif 73 | cmd `isPrefixOf` "test" = runtests opts args >> return () 74 | otherwise = putStr $ usage