1 {-# LANGUAGE DoAndIfThenElse #-}
5 import Control.Concurrent.ParallelIO (stopGlobalPool)
6 import System.Directory (doesFileExist)
16 import CommandLine (show_help)
17 import Configuration (Cfg(..), get_cfg)
18 import LWN.Article (real_article_path)
19 import LWN.HTTP (get_login_cookie)
20 import LWN.Page (epublish, page_from_url)
23 -- | If we're given an empty path, return a handle to
24 -- 'stdout'. Otherwise, open the given file and return a read/write
26 get_output_handle :: FilePath -> IO Handle
27 get_output_handle path =
31 openBinaryFile path WriteMode
34 argument_is_file :: Cfg -> IO Bool
35 argument_is_file cfg = do
36 path <- real_article_path (article cfg)
42 aif <- argument_is_file cfg'
44 False -> get_login_cookie cfg'
47 page <- page_from_url cfg (article cfg)
50 output_handle <- get_output_handle (output cfg)
51 epublish p output_handle
53 hPutStrLn stderr "ERROR: could not parse an LWN page from the given URL."
57 -- Necessary, for some reason.