Implement module in main

This commit is contained in:
Marko Andjelic 2026-01-24 22:43:23 +00:00
commit ffa90e0a3a

View file

@ -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 <file.epub>"
(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