2009-06-02 23:01:21 +04:00
|
|
|
-- #!/usr/bin/env runhaskell <- sp doesn't like
|
2009-01-18 22:02:08 +03:00
|
|
|
{-# OPTIONS_GHC -cpp #-}
|
2008-10-01 11:04:47 +04:00
|
|
|
{-|
|
|
|
|
hledger - a ledger-compatible text-based accounting tool.
|
2007-02-18 21:12:02 +03:00
|
|
|
|
2009-01-18 00:03:34 +03:00
|
|
|
Copyright (c) 2007-2009 Simon Michael <simon@joyful.com>
|
2008-10-01 12:44:23 +04:00
|
|
|
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-05 02:38:36 +04:00
|
|
|
implementation of ledger. For more information, see http:\/\/hledger.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
|
2009-04-04 13:24:49 +04:00
|
|
|
> > l <- readLedger "sample.ledger"
|
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
|
2009-04-04 13:24:49 +04:00
|
|
|
> > balance [Depth "1"] [] l
|
|
|
|
> $-1 assets
|
|
|
|
> $2 expenses
|
|
|
|
> $-2 income
|
|
|
|
> $1 liabilities
|
|
|
|
> > l <- myLedger
|
|
|
|
> > t <- myTimelog
|
2008-10-12 13:17:21 +04:00
|
|
|
|
2009-04-05 02:38:36 +04:00
|
|
|
See "Ledger.Ledger" for more examples.
|
2007-02-18 21:12:02 +03:00
|
|
|
-}
|
2007-01-28 13:30:24 +03:00
|
|
|
|
2009-06-02 23:01:21 +04:00
|
|
|
module Main where
|
2009-06-05 06:07:38 +04:00
|
|
|
import Prelude hiding (putStr, putStrLn)
|
2009-06-02 22:29:01 +04:00
|
|
|
import System.IO.UTF8
|
2008-12-10 00:00:46 +03:00
|
|
|
|
2009-06-02 22:29:01 +04:00
|
|
|
import Commands.All
|
2008-10-10 07:32:12 +04:00
|
|
|
import Ledger
|
2008-10-12 13:17:21 +04:00
|
|
|
import Options
|
2009-01-25 10:06:59 +03:00
|
|
|
import Tests
|
2009-06-02 22:29:01 +04:00
|
|
|
import Utils (withLedgerDo)
|
2009-06-05 06:07:38 +04:00
|
|
|
import Version (versionmsg, binaryfilename)
|
2007-02-09 03:18:20 +03:00
|
|
|
|
|
|
|
main :: IO ()
|
2007-01-30 12:07:12 +03:00
|
|
|
main = do
|
2008-10-08 21:00:22 +04:00
|
|
|
(opts, cmd, args) <- parseArguments
|
|
|
|
run cmd opts args
|
2009-07-31 21:02:47 +04:00
|
|
|
where
|
2008-10-10 07:32:12 +04:00
|
|
|
run cmd opts args
|
2009-09-22 15:55:11 +04:00
|
|
|
| Help `elem` opts = putStr usage
|
2009-06-05 06:07:38 +04:00
|
|
|
| Version `elem` opts = putStrLn versionmsg
|
|
|
|
| BinaryFilename `elem` opts = putStrLn binaryfilename
|
2009-05-17 00:45:05 +04:00
|
|
|
| cmd `isPrefixOf` "balance" = withLedgerDo opts args cmd balance
|
|
|
|
| cmd `isPrefixOf` "convert" = withLedgerDo opts args cmd convert
|
|
|
|
| cmd `isPrefixOf` "print" = withLedgerDo opts args cmd print'
|
|
|
|
| cmd `isPrefixOf` "register" = withLedgerDo opts args cmd register
|
|
|
|
| cmd `isPrefixOf` "histogram" = withLedgerDo opts args cmd histogram
|
|
|
|
| cmd `isPrefixOf` "add" = withLedgerDo opts args cmd add
|
2009-05-29 14:05:09 +04:00
|
|
|
| cmd `isPrefixOf` "stats" = withLedgerDo opts args cmd stats
|
2009-01-20 06:48:05 +03:00
|
|
|
#ifdef VTY
|
2009-05-17 00:45:05 +04:00
|
|
|
| cmd `isPrefixOf` "ui" = withLedgerDo opts args cmd ui
|
2009-01-20 07:04:40 +03:00
|
|
|
#endif
|
2009-11-28 18:37:56 +03:00
|
|
|
#ifdef WEB
|
2009-05-17 00:45:05 +04:00
|
|
|
| cmd `isPrefixOf` "web" = withLedgerDo opts args cmd web
|
2009-01-18 22:02:08 +03:00
|
|
|
#endif
|
2009-04-08 01:16:42 +04:00
|
|
|
| cmd `isPrefixOf` "test" = runtests opts args >> return ()
|
2009-09-22 15:55:11 +04:00
|
|
|
| otherwise = putStr usage
|