mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
26 lines
766 B
Haskell
26 lines
766 B
Haskell
|
module Options where
|
||
|
|
||
|
import System.Console.GetOpt
|
||
|
import Data.Maybe ( fromMaybe )
|
||
|
|
||
|
data Flag = File String | Version deriving Show
|
||
|
|
||
|
options :: [OptDescr Flag]
|
||
|
options = [
|
||
|
Option ['f'] ["file"] (OptArg inp "FILE") "ledger file, or - to read stdin"
|
||
|
, Option ['v'] ["version"] (NoArg Version) "show version number"
|
||
|
]
|
||
|
|
||
|
inp :: Maybe String -> Flag
|
||
|
inp = File . fromMaybe "stdin"
|
||
|
|
||
|
getOptions :: [String] -> IO ([Flag], [String])
|
||
|
getOptions argv =
|
||
|
case getOpt Permute options argv of
|
||
|
(o,n,[] ) -> return (o,n)
|
||
|
(_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options))
|
||
|
where header = "Usage: hledger [OPTIONS]"
|
||
|
|
||
|
get_content :: Flag -> Maybe String
|
||
|
get_content (File s) = Just s
|