Print a warning when --site-url is set but none of --open-graph-cards or --rss is set

This commit is contained in:
Tissevert 2020-03-25 19:46:35 +01:00
parent 18d0e73062
commit bc861e3eeb

View file

@ -11,6 +11,7 @@ import qualified Arguments as Arguments (Arguments(..))
import Data.Aeson (ToJSON(..), (.=), pairs) import Data.Aeson (ToJSON(..), (.=), pairs)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import System.Exit (die) import System.Exit (die)
import System.IO (hPutStrLn, stderr)
import Text.Printf (printf) import Text.Printf (printf)
data URL = URL { data URL = URL {
@ -26,13 +27,19 @@ instance ToJSON URL where
build :: Arguments -> IO URL build :: Arguments -> IO URL
build arguments = do build arguments = do
cards <- getSiteURL (Arguments.openGraphCards arguments) "Open Graph cards" cards <- getSiteURL argOGCards "Open Graph cards"
rss <- getSiteURL (Arguments.rss arguments) "RSS feeds" rss <- getSiteURL argRSS "RSS feeds"
checksUsed (argOGCards || argRSS) siteURL
return $ URL {cards, comments, rss} return $ URL {cards, comments, rss}
where where
comments = Arguments.commentsURL arguments comments = Arguments.commentsURL arguments
siteURL = Arguments.siteURL arguments siteURL = Arguments.siteURL arguments
argOGCards = Arguments.openGraphCards arguments
argRSS = Arguments.rss arguments
errorMsg :: String -> String errorMsg :: String -> String
errorMsg = printf "Enabling %s requires setting the site url with --site-url" errorMsg = printf "Enabling %s requires setting the site url with --site-url"
getSiteURL False _ = return Nothing getSiteURL False _ = return Nothing
getSiteURL True name = maybe (die $ errorMsg name) (return . Just) siteURL getSiteURL True name = maybe (die $ errorMsg name) (return . Just) siteURL
checksUsed False (Just _) =
hPutStrLn stderr "Site url is set but not used, did you forget --open-graph-cards or --rss ?"
checksUsed _ _ = return ()