hablo/src/Arguments.hs

47 lines
1.1 KiB
Haskell

{-# LANGUAGE NamedFieldPuns #-}
module Arguments (
Arguments(..)
, configuration
) where
import Data.Monoid ((<>))
import Options.Applicative
import System.FilePath.Posix (dropTrailingPathSeparator, isValid)
data Arguments = Arguments {
sourceDir :: FilePath
, blogName :: Maybe String
, previewCountArg :: Int
}
arguments :: Parser Arguments
arguments = Arguments
<$> argument directory (metavar "INPUT_DIR")
<*> option (optional str) (
metavar "BLOG_NAME"
<> value Nothing
<> short 'n'
<> long "name"
<> help "name of the blog"
)
<*> option auto (
metavar "PREVIEW_COUNT"
<> value 3
<> short 'p'
<> long "preview-count"
<> help "number of articles listed on the page of each category"
)
directory :: ReadM FilePath
directory = eitherReader $ \path ->
if isValid path
then Right $ dropTrailingPathSeparator path
else Left "This string doesn't represent a valid path"
configuration :: IO Arguments
configuration =
execParser $
info (arguments <**> helper)
( fullDesc
)