mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
make main function importable, for benchmarking. There must be a better way..
This commit is contained in:
parent
357f56d0f4
commit
1bc7a22d57
47
HledgerMain.hs
Normal file
47
HledgerMain.hs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
{-|
|
||||||
|
The main function is in this separate module so it can be imported by
|
||||||
|
benchmark scripts. As a side benefit, this avoids a weakness of sp, which
|
||||||
|
doesn't allow both #! and \{\-\# lines.
|
||||||
|
-}
|
||||||
|
|
||||||
|
module HledgerMain where
|
||||||
|
#if __GLASGOW_HASKELL__ <= 610
|
||||||
|
import Prelude hiding (putStr, putStrLn)
|
||||||
|
import System.IO.UTF8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import Commands.All
|
||||||
|
import Ledger
|
||||||
|
import Options
|
||||||
|
import Tests
|
||||||
|
import Utils (withLedgerDo)
|
||||||
|
import Version (versionmsg, binaryfilename)
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
(opts, cmd, args) <- parseArguments
|
||||||
|
run cmd opts args
|
||||||
|
where
|
||||||
|
run cmd opts args
|
||||||
|
| Help `elem` opts = putStr usage
|
||||||
|
| Version `elem` opts = putStrLn versionmsg
|
||||||
|
| BinaryFilename `elem` opts = putStrLn binaryfilename
|
||||||
|
| 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
|
||||||
|
| cmd `isPrefixOf` "stats" = withLedgerDo opts args cmd stats
|
||||||
|
#ifdef VTY
|
||||||
|
| cmd `isPrefixOf` "ui" = withLedgerDo opts args cmd ui
|
||||||
|
#endif
|
||||||
|
#ifdef WEB
|
||||||
|
| cmd `isPrefixOf` "web" = withLedgerDo opts args cmd web
|
||||||
|
#endif
|
||||||
|
#ifdef CHART
|
||||||
|
| cmd `isPrefixOf` "chart" = withLedgerDo opts args cmd chart
|
||||||
|
#endif
|
||||||
|
| cmd `isPrefixOf` "test" = runtests opts args >> return ()
|
||||||
|
| otherwise = putStr usage
|
@ -82,6 +82,7 @@ executable hledger
|
|||||||
Commands.Print
|
Commands.Print
|
||||||
Commands.Register
|
Commands.Register
|
||||||
Commands.Stats
|
Commands.Stats
|
||||||
|
HledgerMain
|
||||||
Ledger
|
Ledger
|
||||||
Ledger.Account
|
Ledger.Account
|
||||||
Ledger.AccountName
|
Ledger.AccountName
|
||||||
|
46
hledger.hs
46
hledger.hs
@ -1,9 +1,8 @@
|
|||||||
-- #!/usr/bin/env runhaskell <- sp doesn't like
|
#!/usr/bin/env runhaskell
|
||||||
{-# LANGUAGE CPP #-}
|
|
||||||
{-|
|
{-|
|
||||||
hledger - a ledger-compatible text-based accounting tool.
|
hledger - a ledger-compatible text-based accounting tool.
|
||||||
|
|
||||||
Copyright (c) 2007-2009 Simon Michael <simon@joyful.com>
|
Copyright (c) 2007-2010 Simon Michael <simon@joyful.com>
|
||||||
Released under GPL version 3 or later.
|
Released under GPL version 3 or later.
|
||||||
|
|
||||||
hledger is a partial haskell clone of John Wiegley's "ledger" text-based
|
hledger is a partial haskell clone of John Wiegley's "ledger" text-based
|
||||||
@ -33,45 +32,8 @@ or ghci:
|
|||||||
> > t <- myTimelog
|
> > t <- myTimelog
|
||||||
|
|
||||||
See "Ledger.Ledger" for more examples.
|
See "Ledger.Ledger" for more examples.
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Main where
|
module Main where
|
||||||
#if __GLASGOW_HASKELL__ <= 610
|
import HledgerMain (main)
|
||||||
import Prelude hiding (putStr, putStrLn)
|
|
||||||
import System.IO.UTF8
|
|
||||||
#endif
|
|
||||||
|
|
||||||
import Commands.All
|
|
||||||
import Ledger
|
|
||||||
import Options
|
|
||||||
import Tests
|
|
||||||
import Utils (withLedgerDo)
|
|
||||||
import Version (versionmsg, binaryfilename)
|
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = do
|
|
||||||
(opts, cmd, args) <- parseArguments
|
|
||||||
run cmd opts args
|
|
||||||
where
|
|
||||||
run cmd opts args
|
|
||||||
| Help `elem` opts = putStr usage
|
|
||||||
| Version `elem` opts = putStrLn versionmsg
|
|
||||||
| BinaryFilename `elem` opts = putStrLn binaryfilename
|
|
||||||
| 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
|
|
||||||
| cmd `isPrefixOf` "stats" = withLedgerDo opts args cmd stats
|
|
||||||
#ifdef VTY
|
|
||||||
| cmd `isPrefixOf` "ui" = withLedgerDo opts args cmd ui
|
|
||||||
#endif
|
|
||||||
#ifdef WEB
|
|
||||||
| cmd `isPrefixOf` "web" = withLedgerDo opts args cmd web
|
|
||||||
#endif
|
|
||||||
#ifdef CHART
|
|
||||||
| cmd `isPrefixOf` "chart" = withLedgerDo opts args cmd chart
|
|
||||||
#endif
|
|
||||||
| cmd `isPrefixOf` "test" = runtests opts args >> return ()
|
|
||||||
| otherwise = putStr usage
|
|
||||||
|
Loading…
Reference in New Issue
Block a user