cleanup
This commit is contained in:
parent
ea98a9798f
commit
12a9a03f1a
@ -8,7 +8,7 @@ import Data.Maybe (fromMaybe)
|
|||||||
import Utils
|
import Utils
|
||||||
|
|
||||||
|
|
||||||
usage = "Usage: hledger [OPTIONS] "++commands++" [ACCTPATTERNS] [-- DESCPATTERNS]\nOptions:"
|
usagehdr = "Usage: hledger [OPTIONS] "++commands++" [ACCTPATTERNS] [-- DESCPATTERNS]\nOptions:"
|
||||||
commands = "register|balance"
|
commands = "register|balance"
|
||||||
defaultcmd = "register"
|
defaultcmd = "register"
|
||||||
ledgerFilePath = findFileFromOpts "~/ledger.dat" "LEDGER"
|
ledgerFilePath = findFileFromOpts "~/ledger.dat" "LEDGER"
|
||||||
@ -31,7 +31,7 @@ parseOptions argv =
|
|||||||
case getOpt RequireOrder options argv of
|
case getOpt RequireOrder options argv of
|
||||||
(opts,[],[]) -> return (opts, [defaultcmd])
|
(opts,[],[]) -> return (opts, [defaultcmd])
|
||||||
(opts,args,[]) -> return (opts, args)
|
(opts,args,[]) -> return (opts, args)
|
||||||
(_,_,errs) -> ioError (userError (concat errs ++ showusage))
|
(_,_,errs) -> ioError (userError (concat errs ++ usage))
|
||||||
|
|
||||||
-- testoptions RequireOrder ["foo","-v"]
|
-- testoptions RequireOrder ["foo","-v"]
|
||||||
-- testoptions Permute ["foo","-v"]
|
-- testoptions Permute ["foo","-v"]
|
||||||
@ -42,9 +42,9 @@ parseOptions argv =
|
|||||||
testoptions order cmdline = putStr $
|
testoptions order cmdline = putStr $
|
||||||
case getOpt order options cmdline of
|
case getOpt order options cmdline of
|
||||||
(o,n,[] ) -> "options=" ++ show o ++ " args=" ++ show n
|
(o,n,[] ) -> "options=" ++ show o ++ " args=" ++ show n
|
||||||
(_,_,errs) -> concat errs ++ showusage
|
(_,_,errs) -> concat errs ++ usage
|
||||||
|
|
||||||
showusage = usageInfo usage options
|
usage = usageInfo usagehdr options
|
||||||
|
|
||||||
-- find a file path from options, an env var or a default value
|
-- find a file path from options, an env var or a default value
|
||||||
findFileFromOpts :: FilePath -> String -> [Flag] -> IO String
|
findFileFromOpts :: FilePath -> String -> [Flag] -> IO String
|
||||||
|
|||||||
@ -19,6 +19,7 @@ hledger
|
|||||||
Entry
|
Entry
|
||||||
Transaction
|
Transaction
|
||||||
AccountName
|
AccountName
|
||||||
|
Amount
|
||||||
BasicTypes
|
BasicTypes
|
||||||
Utils
|
Utils
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ main = do
|
|||||||
| cmd `isPrefixOf` "register" = register opts args
|
| cmd `isPrefixOf` "register" = register opts args
|
||||||
| cmd `isPrefixOf` "balance" = balance opts args
|
| cmd `isPrefixOf` "balance" = balance opts args
|
||||||
| cmd `isPrefixOf` "test" = test
|
| cmd `isPrefixOf` "test" = test
|
||||||
| otherwise = putStr showusage
|
| otherwise = putStr usage
|
||||||
|
|
||||||
-- commands
|
-- commands
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user