174 lines
5.3 KiB
Haskell
174 lines
5.3 KiB
Haskell
module Options where
|
|
|
|
import Data.Text (Text)
|
|
import Options.Applicative
|
|
|
|
data Options =
|
|
Options {
|
|
verbose :: Bool,
|
|
mode :: ModeOptions
|
|
}
|
|
deriving Show
|
|
|
|
data ModeOptions =
|
|
SinglePage {
|
|
root :: Text,
|
|
file :: FilePath,
|
|
prefix :: FilePath,
|
|
index :: FilePath,
|
|
dataDir :: FilePath,
|
|
nsfw :: Bool,
|
|
output :: Maybe FilePath
|
|
}
|
|
| GalleryPage {
|
|
root :: Text,
|
|
files :: [FilePath],
|
|
prefix :: FilePath,
|
|
index :: FilePath,
|
|
output :: Maybe FilePath,
|
|
dataDir :: FilePath
|
|
}
|
|
| IndexPage {
|
|
root :: Text,
|
|
file :: FilePath,
|
|
output :: Maybe FilePath
|
|
}
|
|
| RSS {
|
|
files :: [FilePath],
|
|
root :: Text,
|
|
index :: FilePath,
|
|
prefix :: FilePath,
|
|
output :: Maybe FilePath,
|
|
dataDir :: FilePath
|
|
}
|
|
| DependSingle {
|
|
file :: FilePath,
|
|
nsfw :: Bool,
|
|
output :: Maybe FilePath,
|
|
prefix :: FilePath,
|
|
index :: FilePath,
|
|
buildDir :: FilePath,
|
|
dataDir :: FilePath
|
|
}
|
|
| DependGallery {
|
|
file :: FilePath,
|
|
output :: Maybe FilePath,
|
|
buildDir :: FilePath,
|
|
dataDir :: FilePath,
|
|
tmpDir :: FilePath,
|
|
infoName :: FilePath
|
|
}
|
|
| ListTags {
|
|
dataDir :: FilePath,
|
|
infoName :: FilePath,
|
|
index :: FilePath,
|
|
nsfw :: Bool,
|
|
listUntagged :: Bool,
|
|
showWarnings :: Bool,
|
|
sortBy :: TagSort
|
|
}
|
|
deriving Show
|
|
|
|
data TagSort = SortFreq | SortName 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 $
|
|
single <> gallery <> index <> rss <> dependSingle <> dependGallery <>
|
|
listTags
|
|
|
|
single = command "single" $ singleOpts `info` singleInfo
|
|
singleOpts =
|
|
SinglePage <$> root <*> file <*> prefix <*> indexFile
|
|
<*> dataDir <*> nsfwS <*> output
|
|
root = strOption $
|
|
short 'R' <> long "root" <> metavar "URL" <>
|
|
help "website root (no trailing slash)"
|
|
file = strArgument $
|
|
metavar "FILE" <> help "yaml file to read"
|
|
prefix = strOption $
|
|
short 'p' <> long "prefix" <> metavar "DIR" <>
|
|
value "" <>
|
|
help "gallery directory prefix"
|
|
indexFile = strOption $
|
|
short 'i' <> long "index" <> metavar "FILE" <>
|
|
help "path to index file"
|
|
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"
|
|
|
|
index = command "index" $ indexOpts `info` indexInfo
|
|
indexOpts = IndexPage <$> root <*> file <*> output
|
|
indexInfo = progDesc "generate an index page for all galleries"
|
|
|
|
gallery = command "gallery" $ galleryOpts `info` galleryInfo
|
|
galleryOpts =
|
|
GalleryPage <$> root <*> files <*> prefix
|
|
<*> indexFile <*> output <*> dataDir
|
|
files = many $ strArgument $
|
|
metavar "FILE..." <> help "yaml files to read"
|
|
galleryInfo = progDesc "generate a gallery page"
|
|
|
|
rss = command "rss" $ rssOpts `info` rssInfo
|
|
rssOpts = RSS <$> files <*> root <*> indexFile
|
|
<*> prefix <*> output <*> dataDir
|
|
rssInfo = progDesc "generate an rss file for a gallery"
|
|
|
|
dependSingle = command "depend-single" $ dsOpts `info` dsInfo
|
|
dsOpts =
|
|
DependSingle <$> file <*> nsfwS <*> output <*> prefix
|
|
<*> indexFile <*> buildDir <*> dataDir
|
|
buildDir = strOption $
|
|
short 'B' <> long "build-dir" <> metavar "DIR" <> value "_build" <>
|
|
help "build directory (default: _build)"
|
|
dataDir = strOption $
|
|
short 'D' <> long "data-dir" <> metavar "DIR" <> value "data" <>
|
|
help "data directory (default: data)"
|
|
dsInfo = progDesc "generate makefile dependencies for a single page"
|
|
|
|
dependGallery = command "depend-gallery" $ dgOpts `info` dgInfo
|
|
dgOpts =
|
|
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)"
|
|
dgInfo = progDesc "generate makefile dependencies for a gallery"
|
|
|
|
listTags = command "list-tags" $ ltOpts `info` ltInfo
|
|
ltOpts = ListTags <$> dataDir <*> infoName <*> indexFile <*> nsfwT
|
|
<*> listUntagged <*> showWarnings <*> listSort
|
|
nsfwT = switch $
|
|
short 'n' <> long "nsfw" <>
|
|
help "include nsfw tags"
|
|
listUntagged = switch $
|
|
short 'U' <> long "untagged" <>
|
|
help "list files with no tags"
|
|
showWarnings = switch $
|
|
short 'W' <> long "warnings" <>
|
|
help "show tag warnings"
|
|
listSort = fmap toSort $ switch $
|
|
short 'a' <> long "alpha" <>
|
|
help "sort alphabetically instead of by frequency"
|
|
where toSort x = if x then SortName else SortFreq
|
|
ltInfo = progDesc "list all tags used by frequency"
|
|
|
|
mainInfo = progDesc "static gallery site generator" <> fullDesc
|
|
|
|
|
|
parseOptions :: IO Options
|
|
parseOptions = execParser optionsParser
|