Add options to choose a favicon and a card image

This commit is contained in:
Tissevert 2019-02-07 17:48:34 +01:00
parent 633431f8cb
commit 7beb159a24

View file

@ -1,4 +1,3 @@
{-# LANGUAGE NamedFieldPuns #-}
module Arguments ( module Arguments (
Arguments(..) Arguments(..)
, get , get
@ -6,7 +5,9 @@ module Arguments (
import Data.Monoid ((<>)) import Data.Monoid ((<>))
import Data.Version (showVersion) import Data.Version (showVersion)
import Options.Applicative import Control.Applicative ((<|>), (<**>), optional)
import Options.Applicative (Parser, ReadM, argument, auto, eitherReader, execParser, flag', fullDesc, header, help, helper, info, long, metavar, short, str, value)
import qualified Options.Applicative as Optparse (option)
import qualified Paths_hablo as Hablo (version) import qualified Paths_hablo as Hablo (version)
import System.Directory (doesDirectoryExist, doesFileExist, makeAbsolute) import System.Directory (doesDirectoryExist, doesFileExist, makeAbsolute)
import System.Exit (die, exitSuccess) import System.Exit (die, exitSuccess)
@ -14,52 +15,48 @@ import System.FilePath.Posix (dropTrailingPathSeparator, isValid)
data Arguments = BlogConfig { data Arguments = BlogConfig {
sourceDir :: FilePath sourceDir :: FilePath
, blogName :: Maybe String , bannerPath :: Maybe FilePath
, cardImage :: Maybe FilePath
, favicon :: Maybe FilePath
, headPath :: Maybe FilePath
, name :: Maybe String
, previewArticlesCount :: Int , previewArticlesCount :: Int
, previewLinesCount :: Int , previewLinesCount :: Int
, bannerPath :: Maybe FilePath
, headPath :: Maybe FilePath
} }
| Version | Version
option :: ReadM a -> Char -> String -> String -> String -> Parser (Maybe a)
option readM aShort aLong aMetavar aHelpMessage =
Optparse.option (optional readM) (
metavar aMetavar
<> value Nothing
<> short aShort
<> long aLong
<> help aHelpMessage
)
blogConfig :: Parser Arguments blogConfig :: Parser Arguments
blogConfig = BlogConfig blogConfig = BlogConfig
<$> argument filePath (metavar "INPUT_DIR") <$> argument filePath (metavar "INPUT_DIR")
<*> option (optional str) ( <*> option filePath 'b' "banner" "BANNER_PATH" "path to the file to use for the blog's banner"
metavar "BLOG_NAME" <*> option filePath 'c' "card-image" "CARD_IMAGE" "path to the image to use for the blog's card"
<> value Nothing <*> option filePath 'f' "favicon" "FAVICON" "path to the image to use for the blog's favicon"
<> short 'n' <*> option filePath 'H' "head" "HEAD_PATH" "path to the file to add in the blog's head"
<> long "name" <*> option str 'n' "name" "BLOG_NAME" "name of the blog"
<> help "name of the blog" <*> Optparse.option auto (
)
<*> option auto (
metavar "PREVIEW_ARTICLES_COUNT" metavar "PREVIEW_ARTICLES_COUNT"
<> value 3 <> value 3
<> short 'a' <> short 'a'
<> long "preview-articles" <> long "preview-articles"
<> help "number of articles listed on the page of each category" <> help "number of articles listed on the page of each category"
) )
<*> option auto ( <*> Optparse.option auto (
metavar "PREVIEW_LINES_COUNT" metavar "PREVIEW_LINES_COUNT"
<> value 10 <> value 10
<> short 'l' <> short 'l'
<> long "preview-lines" <> long "preview-lines"
<> help "number of lines to display in articles preview" <> help "number of lines to display in articles preview"
) )
<*> option (optional filePath) (
metavar "BANNER_PATH"
<> value Nothing
<> short 'b'
<> long "banner"
<> help "path to the file to use for the blog's banner"
)
<*> option (optional filePath) (
metavar "HEAD_PATH"
<> value Nothing
<> short 'H'
<> long "head"
<> help "path to the file to add in the blog's head"
)
version :: Parser Arguments version :: Parser Arguments
version = flag' Version ( version = flag' Version (