]> gitweb.michael.orlitzky.com - dead/lwn-epub.git/blob - src/Main.hs
Move the main processing functions into the LWN.Page module.
[dead/lwn-epub.git] / src / Main.hs
1 {-# LANGUAGE DoAndIfThenElse #-}
2 module Main
3 where
4
5 import System.IO (
6 Handle,
7 IOMode (WriteMode),
8 openBinaryFile,
9 stdout)
10
11 import CommandLine (show_help)
12 import Configuration (Cfg(..), get_cfg)
13 import LWN.Page (epublish, page_from_url)
14
15
16 -- | If we're given an empty path, return a handle to
17 -- 'stdout'. Otherwise, open the given file and return a read/write
18 -- handle to that.
19 get_output_handle :: FilePath -> IO Handle
20 get_output_handle path =
21 if (null path) then
22 return stdout
23 else
24 openBinaryFile path WriteMode
25
26
27 main :: IO ()
28 main = do
29 cfg <- get_cfg
30 page <- page_from_url cfg (article cfg)
31 case page of
32 Just p -> do
33 output_handle <- get_output_handle (output cfg)
34 epublish p output_handle
35 Nothing -> do
36 _ <- show_help
37 return ()