X-Git-Url: https://git.danieliu.xyz/?p=ekitaihs.git;a=blobdiff_plain;f=Parse.hs;fp=Parse.hs;h=367caff6d151839d76090125d007648b46fada3c;hp=26a0390fc08461919616343928bc52be9b2e1714;hb=4de2980e358a4ed8bb05e615a3fee16215b03c1f;hpb=76d05eb2de39a69e93c2c342073cde2627c9f50c diff --git a/Parse.hs b/Parse.hs index 26a0390..367caff 100644 --- a/Parse.hs +++ b/Parse.hs @@ -1,34 +1,47 @@ -module Parse ( ekitaiOpts ) where +module Parse ( ekitaiOpts, optTimeStep ) where import System.Console.GetOpt import System.Environment +import System.Exit import Data.Maybe import Data.Either data Options = Options { optHelp :: Bool , optColor :: Bool + , optTimeStep :: Int } defaultOptions = Options { optHelp = False , optColor = False + , optTimeStep = 50000 } options :: [OptDescr (Options -> Options)] options = [ Option ['h'] ["help"] - (NoArg (\ opts -> opts { optHelp = True })) + (NoArg (\opts -> opts { optHelp = True })) "display's this message" , Option ['c'] ["color", "colour"] - (NoArg (\ opts -> opts { optColor = True })) + (NoArg (\opts -> opts { optColor = True })) "enables color" + , Option ['t'] ["timestep"] + (ReqArg (\t opts -> opts { optTimeStep = read t :: Int }) "timestep") + "sets the simulation time step" ] 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) + (o, _, []) -> ioError $ userError $ "missing input file" + (_, _, errs) -> ioError $ userError $ concat errs +-- ++ usageInfo header options +-- where header = "Usage: ekitai [OPTIONS...] simfile" + + -- (o, _, []) -> do + -- opts <- (foldl (flip id) defaultOptions o) + -- if optHelp then userError $ concat usageInfo "Usage: ekitai [OPTIONS...] simfile" options + -- else ioError $ userError $ "missing input file"