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
1 changed files with 25 additions and 28 deletions

View File

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