--
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 }
-- 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 }
-- 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.
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