main :: IO ()
main = do
  args <- getArgs
  when (null args) $ do
    hPutStrLn stderr "Not enough arguments. (Try ct2hs --help.)"
    exitFailure
  let basename = head args
  when (basename == "-h" || basename == "--help") $ do
    putStrLn "ct2hs NAME [MODULE]"
    putStrLn ""
    putStrLn "NAME should specify a .ct file WITHOUT the .ct extension."
    putStrLn "MODULE determines the haskell module name; it defaults to NAME."
    putStrLn "Output will be written to stdout; redirect it as neccessary."
    putStrLn ""
    putStrLn "example:"
    putStrLn " > ct2hs Omega Precommit.Omega > Omega.hs"
    exitSuccess
  when (length args > 2) $ do
    hPutStrLn stderr "Too many arguments. (Try ct2hs --help.)"
    exitFailure
  let modname = if length args > 1 then args !! 1 else basename
  let filename = basename <> ".ct"
  contents <- readFile filename
  case load filename contents of
    Left e -> putStrLn e
    Right f -> either print (printModule modname $ names f) (convert f)
main :: IO ()
main = do
  args <- getArgs
  when (null args) $ do
    hPutStrLn stderr "Not enough arguments. (Try ct2hs --help.)"
    exitFailure
  let basename = head args
  when (basename == "-h" || basename == "--help") $ do
    putStrLn "ct2hs NAME [MODULE]"
    putStrLn ""
    putStrLn "NAME should specify a .ct file WITHOUT the .ct extension."
    putStrLn "MODULE determines the haskell module name; it defaults to NAME."
    putStrLn "Output will be written to stdout; redirect it as neccessary."
    putStrLn ""
    putStrLn "example:"
    putStrLn " > ct2hs Omega Precommit.Omega > Omega.hs"
    exitSuccess
  when (length args > 2) $ do
    hPutStrLn stderr "Too many arguments. (Try ct2hs --help.)"
    exitFailure
  let modname = if length args > 1 then args !! 1 else basename
  let filename = basename <> ".ct"
  contents <- readFile filename
  case load filename contents of
    Left e -> putStrLn e
    Right f -> either print (printModule modname $ names f) (convert f)
main = do
  args <- getArgs
  when (null args) $ do
    hPutStrLn stderr "Not enough arguments. (Try ct2hs --help.)"
    exitFailure
  let basename = head args
  when (basename == "-h" || basename == "--help") $ do
    putStrLn "ct2hs NAME [MODULE]"
    putStrLn ""
    putStrLn "NAME should specify a .ct file WITHOUT the .ct extension."
    putStrLn "MODULE determines the haskell module name; it defaults to NAME."
    putStrLn "Output will be written to stdout; redirect it as neccessary."
    putStrLn ""
    putStrLn "example:"
    putStrLn " > ct2hs Omega Precommit.Omega > Omega.hs"
    exitSuccess
  when (length args > 2) $ do
    hPutStrLn stderr "Too many arguments. (Try ct2hs --help.)"
    exitFailure
  let modname = if length args > 1 then args !! 1 else basename
  let filename = basename <> ".ct"
  contents <- readFile filename
  case load filename contents of
    Left e -> putStrLn e
    Right f -> either print (printModule modname $ names f) (convert f)