Implement module in main
This commit is contained in:
parent
f6c7d9065e
commit
ffa90e0a3a
1 changed files with 32 additions and 1 deletions
33
app/Main.hs
33
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 <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
|
||||
|
|
|
|||
Loading…
Reference in a new issue