gallery/make-pages/Options.hs

142 lines
4.3 KiB
Haskell
Raw Normal View History

2020-07-15 14:06:19 -04:00
module Options where
2020-07-16 10:07:28 -04:00
import Data.Text (Text)
2020-07-15 14:06:19 -04:00
import Options.Applicative
data Options =
Options {
verbose :: Bool,
mode :: ModeOptions
}
deriving Show
data ModeOptions =
SinglePage {
file :: FilePath,
nsfw :: Bool,
output :: Maybe FilePath
}
| GalleryPage {
2020-07-16 10:07:28 -04:00
files :: [FilePath],
nsfw :: Bool,
2020-07-16 10:07:28 -04:00
title :: Text,
output :: Maybe FilePath,
dataDir :: FilePath
2020-07-15 14:06:19 -04:00
}
2020-07-16 10:29:32 -04:00
| IndexPage {
file :: FilePath,
output :: Maybe FilePath
}
2020-07-19 12:04:40 -04:00
| RSS {
files :: [FilePath],
title :: Text,
description :: Text,
root :: Text,
prefix :: FilePath,
output :: Maybe FilePath,
dataDir :: FilePath
}
2020-07-15 14:06:19 -04:00
| DependSingle {
file :: FilePath,
nsfw :: Bool,
output :: Maybe FilePath,
prefix :: FilePath,
buildDir :: FilePath,
dataDir :: FilePath
}
2020-07-16 05:48:37 -04:00
| DependGallery {
2020-07-16 10:07:28 -04:00
file :: FilePath,
2020-07-16 05:48:37 -04:00
output :: Maybe FilePath,
buildDir :: FilePath,
2020-07-16 10:07:28 -04:00
dataDir :: FilePath,
tmpDir :: FilePath,
infoName :: FilePath
2020-07-16 05:48:37 -04:00
}
2020-07-15 14:06:19 -04:00
deriving Show
optionsParser :: ParserInfo Options
optionsParser = globalOpts `info` mainInfo where
globalOpts = Options <$> verboseOpt <*> subcommands <**> helper
verboseOpt = switch $
short 'v' <> long "verbose" <>
help "print extra stuff to stderr"
subcommands = hsubparser $
2020-07-19 12:04:40 -04:00
single <> gallery <> index <> rss <> dependSingle <> dependGallery
2020-07-15 14:06:19 -04:00
single = command "single" $ singleOpts `info` singleInfo
singleOpts = SinglePage <$> file <*> nsfwS <*> output
file = strArgument $
metavar "FILE" <> help "yaml file to read"
nsfwS = switch $
short 'n' <> long "nsfw" <>
help "include nsfw versions"
output = option (Just <$> str) $
short 'o' <> long "output" <> metavar "FILE" <>
value Nothing <>
help "output file (default: stdout)"
singleInfo = progDesc "generate a page for a single work"
2020-07-16 10:29:32 -04:00
index = command "index" $ indexOpts `info` indexInfo
indexOpts = IndexPage <$> file <*> output
indexInfo = progDesc "generate an index page for all galleries"
2020-07-15 14:06:19 -04:00
gallery = command "gallery" $ galleryOpts `info` galleryInfo
galleryOpts =
GalleryPage <$> files <*> nsfwG <*> title <*> output <*> dataDir
2020-07-15 14:06:19 -04:00
files = many $ strArgument $
metavar "FILE..." <> help "yaml files to read"
nsfwG = switch $
short 'n' <> long "nsfw" <>
help "nsfw versions are included"
2020-07-16 10:07:28 -04:00
title = strOption $
short 't' <> long "title" <> metavar "TITLE" <>
help "page title"
2020-07-15 14:06:19 -04:00
galleryInfo = progDesc "generate a gallery page"
2020-07-19 12:04:40 -04:00
rss = command "rss" $ rssOpts `info` rssInfo
rssOpts = RSS <$> files <*> title <*> desc <*> root
<*> prefix <*> output <*> dataDir
desc = strOption $
short 'd' <> long "desc" <> metavar "DESC" <>
help "gallery description"
root = strOption $
short 'R' <> long "root" <> metavar "URL" <>
help "website root (no trailing slash)"
rssInfo = progDesc "generate an rss file for a gallery"
2020-07-15 14:06:19 -04:00
dependSingle = command "depend-single" $ dsOpts `info` dsInfo
dsOpts =
DependSingle <$> file <*> nsfwS <*> output <*> prefix
<*> buildDir <*> dataDir
prefix = strOption $
short 'p' <> long "prefix" <> metavar "DIR" <>
value "" <>
help "output directory prefix"
buildDir = strOption $
2020-07-16 10:07:28 -04:00
short 'B' <> long "build-dir" <> metavar "DIR" <> value "_build" <>
2020-07-15 14:06:19 -04:00
help "build directory (default: _build)"
dataDir = strOption $
2020-07-16 10:07:28 -04:00
short 'D' <> long "data-dir" <> metavar "DIR" <> value "data" <>
2020-07-15 14:06:19 -04:00
help "data directory (default: data)"
dsInfo = progDesc "generate makefile dependencies for a single page"
2020-07-16 05:48:37 -04:00
dependGallery = command "depend-gallery" $ dgOpts `info` dgInfo
dgOpts =
2020-07-16 10:07:28 -04:00
DependGallery <$> file <*> output
<*> buildDir <*> dataDir <*> tmpDir <*> infoName
infoName = strOption $
short 'I' <> long "info" <> metavar "NAME" <>
value "info.yaml" <>
help "filename of artwork info files (default: info.yaml)"
tmpDir = strOption $
short 'T' <> long "tmp-dir" <> metavar "DIR" <> value "_tmp" <>
help "temporary directory (default: _tmp)"
2020-07-16 05:48:37 -04:00
dgInfo = progDesc "generate makefile dependencies for a gallery"
2020-07-15 14:06:19 -04:00
mainInfo = progDesc "static gallery site generator" <> fullDesc
parseOptions :: IO Options
parseOptions = execParser optionsParser