main = do
  args <- getArgs
  case getOpt Permute mainOptions args of
    (flags, files, []) ->
      let options = foldr ($) defaultOptions flags
          base = (optBaseDir options)
          output = (optOutputFile options)
      in
      if optOnlyParse options
        then do
          doParse base output files
        else if optSimpleMode options
             then doSimpleMode files
             else doMain base output files

    (_, _, errs) -> ioError $ userError $ concat errs ++ usageInfo optHeader mainOptions
 where
   optHeader = "Usage: "
main = do
  args <- getArgs
  case getOpt Permute mainOptions args of
    (flags, files, []) ->
      let options = foldr ($) defaultOptions flags
          base = (optBaseDir options)
          output = (optOutputFile options)
      in
      if optOnlyParse options
        then do
          doParse base output files
        else if optSimpleMode options
             then doSimpleMode files
             else doMain base output files

    (_, _, errs) -> ioError $ userError $ concat errs ++ usageInfo optHeader mainOptions
 where
   optHeader = "Usage: "
main = do
  args <- getArgs
  case getOpt Permute mainOptions args of
    (flags, files, []) ->
      let options = foldr ($) defaultOptions flags
          base = (optBaseDir options)
          output = (optOutputFile options)
      in
      if optOnlyParse options
        then do
          doParse base output files
        else if optSimpleMode options
             then doSimpleMode files
             else doMain base output files

    (_, _, errs) -> ioError $ userError $ concat errs ++ usageInfo optHeader mainOptions
 where
   optHeader = "Usage: "