diff --git a/app/Main.hs b/app/Main.hs index f16f6f5..7344b41 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,4 +1,35 @@ module Main (main) where +import System.Environment (getArgs) +import Control.Monad.Reader (runReaderT, liftIO) +import EpubParser +import qualified Data.Text.IO as TIO + main :: IO () -main = putStrLn "Hello, Haskell!" +main = do + args <- getArgs + case args of + [] -> putStrLn "Usage: svitak " + (path:_) -> runSvitak path + +runSvitak path = do + result <- openEpub path + case result of + Left err -> putStrLn err + Right arch -> do + let maybeOpfPath = getOpfPath arch + case maybeOpfPath of + Nothing -> putStrLn "Error: Could not find OPF metadata file." + Just opfPath -> do + let tags = getOpfTags arch opfPath + let env = myEnv arch tags + runReaderT printFirstChapter env + +printFirstChapter :: EpubAction () +printFirstChapter = + resolveSpine >>= \chapterPaths -> case chapterPaths of + + [] -> liftIO $ putStrLn $ "Nothing found" + (firstFile:_) -> do + text <- getChapter firstFile + liftIO $ TIO.putStrLn text