X-Git-Url: http://gitweb.michael.orlitzky.com/?p=hath.git;a=blobdiff_plain;f=src%2FCommandLine.hs;h=181eb6f01be210605058a1d51e6e246af210c063;hp=c2bbe0c45f15a6e023ab45597de7d8ad82561826;hb=refs%2Ftags%2F0.0.1;hpb=ea257ba2e191df27cf23feb98a8110157987bfb9 diff --git a/src/CommandLine.hs b/src/CommandLine.hs index c2bbe0c..181eb6f 100644 --- a/src/CommandLine.hs +++ b/src/CommandLine.hs @@ -52,13 +52,13 @@ default_options = Options { opt_help = False, -- options :: [OptDescr (Options -> IO Options)] options = - [ Option ['h']["help"] (NoArg set_help) "Prints this help message.", - Option ['i']["input"] (ReqArg set_input "FILE") "Read FILE instead of stdin." ] + [ Option "h" ["help"] (NoArg set_help) "Prints this help message.", + Option "i" ["input"] (ReqArg set_input "FILE") "Read FILE instead of stdin." ] -- | Takes an Options as an argument, and sets its opt_help member to -- True. set_help :: Options -> IO Options -set_help opts = do +set_help opts = return opts { opt_help = True } @@ -67,7 +67,7 @@ set_help opts = do -- default opt_input is to read from stdin, but if this option is -- set, we replace that with readFile. set_input :: String -> Options -> IO Options -set_input arg opts = do +set_input arg opts = return opts { opt_input = readFile arg } @@ -91,9 +91,8 @@ parse_options = do -- list, one after another, on a default_options record. The end -- result should be an Options instance with all of its members set -- correctly. - opts <- foldl (>>=) (return default_options) actions + foldl (>>=) (return default_options) actions - return opts -- | Return the mode if one was given. @@ -101,13 +100,12 @@ parse_mode :: IO Mode parse_mode = do argv <- getArgs let (_, non_options, _) = getOpt Permute options argv - if (null non_options) - then do - -- Default - return Regex - else do - -- Some non-option was given, but were any of them modes? - case (lowercase (non_options !! 0)) of + case non_options of + -- Default + [] -> return Regex + -- Some non-option was given, but were any of them modes? + (x:_) -> + case (lowercase x) of "regex" -> return Regex "regexed" -> return Regex "reduce" -> return Reduce