X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Flwn-epub.git;a=blobdiff_plain;f=src%2FConfiguration.hs;h=118f10f3c101513a1a0427f77f35118b7088fea5;hp=b7915073e842136724224a76851715b742209c06;hb=6540c24c10cf9f13aa484c760a810d5eda66cda8;hpb=6cb1920fc40d737b5a13fda62a75bf97a69c1ab6 diff --git a/src/Configuration.hs b/src/Configuration.hs index b791507..118f10f 100644 --- a/src/Configuration.hs +++ b/src/Configuration.hs @@ -28,37 +28,48 @@ import ExitCodes -- | Contains all of our configurable options. data Cfg = Cfg { - article :: String, - output :: FilePath, - password :: Maybe String, - username :: Maybe String } - + article :: String, + cookie_jar :: Maybe FilePath, + full_stories :: Bool, + output :: FilePath, + password :: Maybe String, + username :: Maybe String } instance Monoid Cfg where - mempty = Cfg { article = "", - output = "", - password = Nothing, - username = Nothing } + mempty = Cfg { article = "", + cookie_jar = Nothing, + full_stories = False, + output = "", + password = Nothing, + username = Nothing } mappend c1 c2 = - let article' = (if null article1 then article2 else article1) - output' = (if null output1 then output2 else output1) - password' = password1 `mplus` password2 - username' = username1 `mplus` username2 + let article' = (if null article1 then article2 else article1) + cookie_jar' = cookie_jar1 `mplus` cookie_jar2 + full_stories' = full_stories1 || full_stories2 + output' = (if null output1 then output2 else output1) + password' = password1 `mplus` password2 + username' = username1 `mplus` username2 in - Cfg { article = article', - output = output', - password = password', - username = username' } + Cfg { article = article', + cookie_jar = cookie_jar', + full_stories = full_stories', + output = output', + password = password', + username = username' } where - article1 = article c1 - article2 = article c2 - output1 = output c1 - output2 = output c2 - password1 = password c1 - password2 = password c2 - username1 = username c1 - username2 = username c2 + article1 = article c1 + article2 = article c2 + cookie_jar1 = cookie_jar c1 + cookie_jar2 = cookie_jar c2 + full_stories1 = full_stories c1 + full_stories2 = full_stories c2 + output1 = output c1 + output2 = output c2 + password1 = password c1 + password2 = password c2 + username1 = username c1 + username2 = username c2 use_account :: Cfg -> Bool @@ -105,22 +116,28 @@ parse_config = do case parse_result of Left err -> Left (format_cpe err) Right cp -> - let cp_username = get cp "DEFAULT" "username" + let cp_full_stories = get cp "DEFAULT" "full_stories" cp_password = get cp "DEFAULT" "password" - - cfg_username = either_to_maybe cp_username + cp_username = get cp "DEFAULT" "username" + cfg_password = either_to_maybe cp_password + cfg_full_stories = case cp_full_stories of + Left _ -> False -- default + Right f -> f + cfg_username = either_to_maybe cp_username in - Right $ mempty { username = cfg_username, - password = cfg_password } + Right $ mempty { full_stories = cfg_full_stories, + password = cfg_password, + username = cfg_username } get_cfg :: IO Cfg get_cfg = do cmd_article <- Cmd.apply_args - let arg_cfg = mempty { article = Cmd.article cmd_article, - output = Cmd.output cmd_article } + let arg_cfg = mempty { article = Cmd.article cmd_article, + full_stories = Cmd.full_stories cmd_article, + output = Cmd.output cmd_article } either_file_cfg <- parse_config case either_file_cfg of