X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=Parse.hs;fp=Parse.hs;h=26a0390fc08461919616343928bc52be9b2e1714;hb=5b8e53984e97f64f62f5c5f607322006dbddfabc;hp=0000000000000000000000000000000000000000;hpb=2c8009b8a19ed364cbe6bce607c8a6745d2dd5c0;p=ekitaihs.git diff --git a/Parse.hs b/Parse.hs new file mode 100644 index 0000000..26a0390 --- /dev/null +++ b/Parse.hs @@ -0,0 +1,34 @@ +module Parse ( ekitaiOpts ) where + +import System.Console.GetOpt +import System.Environment +import Data.Maybe +import Data.Either + +data Options = Options + { optHelp :: Bool + , optColor :: Bool + } + +defaultOptions = Options + { optHelp = False + , optColor = False + } + +options :: [OptDescr (Options -> Options)] +options = + [ Option ['h'] ["help"] + (NoArg (\ opts -> opts { optHelp = True })) + "display's this message" + , Option ['c'] ["color", "colour"] + (NoArg (\ opts -> opts { optColor = True })) + "enables color" + ] + +ekitaiOpts :: [String] -> IO (Options, String) +ekitaiOpts argv = + case getOpt RequireOrder options argv of + (o, [n], []) -> return (foldl (flip id) defaultOptions o, n) + (o, _, []) -> ioError $ userError $ "must supply input file" + (_, _, errs) -> ioError $ userError $ (concat errs) +