hablo/src/Arguments.hs

46 lines
1.1 KiB
Haskell
Raw Normal View History

2019-01-27 21:41:21 +01:00
{-# LANGUAGE NamedFieldPuns #-}
module Arguments (
Arguments(..)
, configuration
2019-01-27 21:41:21 +01:00
) where
import Options.Applicative
import System.FilePath.Posix (dropTrailingPathSeparator, isValid)
2019-01-27 21:41:21 +01:00
data Arguments = Arguments {
2019-01-27 21:41:21 +01:00
sourceDir :: FilePath
, blogName :: Maybe String
, previewCountArg :: Int
2019-01-27 21:41:21 +01:00
}
arguments :: Parser Arguments
2019-01-27 21:41:21 +01:00
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 $
2019-01-27 21:41:21 +01:00
info (arguments <**> helper)
( fullDesc
)