From: Daniel Liu Date: Fri, 30 Apr 2021 23:48:39 +0000 (-0400) Subject: abstract + basic arg X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=5b8e53984e97f64f62f5c5f607322006dbddfabc;p=ekitaihs.git abstract + basic arg --- diff --git a/Ekitai.hs b/Ekitai.hs new file mode 100644 index 0000000..e413b67 --- /dev/null +++ b/Ekitai.hs @@ -0,0 +1,10 @@ +import System.Environment + +import Parse + +main = do + argv <- getArgs + (opts, fname) <- ekitaiOpts argv + putStrLn fname + return 0 + diff --git a/ekitai.hs b/Parse.hs similarity index 68% rename from ekitai.hs rename to Parse.hs index 9f24440..26a0390 100644 --- a/ekitai.hs +++ b/Parse.hs @@ -1,11 +1,10 @@ +module Parse ( ekitaiOpts ) where + import System.Console.GetOpt import System.Environment -import System.Exit import Data.Maybe import Data.Either -data Flag - data Options = Options { optHelp :: Bool , optColor :: Bool @@ -26,13 +25,10 @@ options = "enables color" ] -ekitaiOpts :: [String] -> Either String (Options, String) +ekitaiOpts :: [String] -> IO (Options, String) ekitaiOpts argv = case getOpt RequireOrder options argv of - (o, n, []) -> undefined - (_, _, err) -> Left "invalid" - -main = do - argv <- getArgs - return 0 + (o, [n], []) -> return (foldl (flip id) defaultOptions o, n) + (o, _, []) -> ioError $ userError $ "must supply input file" + (_, _, errs) -> ioError $ userError $ (concat errs)