main = CA.cmdArgs defaultArgs >>= \args@(CppGenArgs icef trgtD ovrw _ _ _) -> do
  parseResult <- SlcP.parseFile icef
  createDirectoryIfMissing True trgtD
  case parseResult of
    Left  err -> putStrLn (show err) >> exitFailure
    Right []  -> putStrLn ("Parsing '" ++ icef ++ "' didn't produce any output, probably because the Slice parser is deficient.\nTo improve it, please report your slice file to paul.koerbitz@gmail.com") 
                 >> exitFailure 
    Right asts -> do
      let fctyMthds = if fwdFctMthds args then findFctyMthds asts else Map.empty
          fileData = concatMap (sliceCppGen fctyMthds args) asts
          wrtr     = \(fn,ctnt) -> do putStrLn $ "generating '" ++ fn ++ "'"
                                      (BS.writeFile fn ctnt)
          chkwrtr  = if ovrw 
                       then wrtr
                       else \(fn,ctnt) -> do p <- doesFileExist fn
                                             if p 
                                               then putStrLn ('\'' : fn ++ "' aready exists. To overwrite use '--overwrite=True'")
                                               else wrtr (fn,ctnt)
      mapM_ chkwrtr fileData
main = CA.cmdArgs defaultArgs >>= \args@(CppGenArgs icef trgtD ovrw _ _ _) -> do
  parseResult <- SlcP.parseFile icef
  createDirectoryIfMissing True trgtD
  case parseResult of
    Left  err -> putStrLn (show err) >> exitFailure
    Right []  -> putStrLn ("Parsing '" ++ icef ++ "' didn't produce any output, probably because the Slice parser is deficient.\nTo improve it, please report your slice file to paul.koerbitz@gmail.com") 
                 >> exitFailure 
    Right asts -> do
      let fctyMthds = if fwdFctMthds args then findFctyMthds asts else Map.empty
          fileData = concatMap (sliceCppGen fctyMthds args) asts
          wrtr     = \(fn,ctnt) -> do putStrLn $ "generating '" ++ fn ++ "'"
                                      (BS.writeFile fn ctnt)
          chkwrtr  = if ovrw 
                       then wrtr
                       else \(fn,ctnt) -> do p <- doesFileExist fn
                                             if p 
                                               then putStrLn ('\'' : fn ++ "' aready exists. To overwrite use '--overwrite=True'")
                                               else wrtr (fn,ctnt)
      mapM_ chkwrtr fileData
main = CA.cmdArgs defaultArgs >>= \args@(CppGenArgs icef trgtD ovrw _ _ _) -> do
  parseResult <- SlcP.parseFile icef
  createDirectoryIfMissing True trgtD
  case parseResult of
    Left  err -> putStrLn (show err) >> exitFailure
    Right []  -> putStrLn ("Parsing '" ++ icef ++ "' didn't produce any output, probably because the Slice parser is deficient.\nTo improve it, please report your slice file to paul.koerbitz@gmail.com") 
                 >> exitFailure 
    Right asts -> do
      let fctyMthds = if fwdFctMthds args then findFctyMthds asts else Map.empty
          fileData = concatMap (sliceCppGen fctyMthds args) asts
          wrtr     = \(fn,ctnt) -> do putStrLn $ "generating '" ++ fn ++ "'"
                                      (BS.writeFile fn ctnt)
          chkwrtr  = if ovrw 
                       then wrtr
                       else \(fn,ctnt) -> do p <- doesFileExist fn
                                             if p 
                                               then putStrLn ('\'' : fn ++ "' aready exists. To overwrite use '--overwrite=True'")
                                               else wrtr (fn,ctnt)
      mapM_ chkwrtr fileData