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 {
|
2020-08-11 14:29:54 -04:00
|
|
|
root :: Text,
|
2020-07-21 18:13:02 -04:00
|
|
|
file :: FilePath,
|
2020-08-11 14:29:54 -04:00
|
|
|
prefix :: FilePath,
|
2022-08-10 19:54:12 -04:00
|
|
|
index :: FilePath,
|
2020-07-21 18:13:02 -04:00
|
|
|
dataDir :: FilePath,
|
|
|
|
nsfw :: Bool,
|
|
|
|
output :: Maybe FilePath
|
2020-07-15 14:06:19 -04:00
|
|
|
}
|
|
|
|
| GalleryPage {
|
2020-08-11 14:29:54 -04:00
|
|
|
root :: Text,
|
2020-07-16 10:07:28 -04:00
|
|
|
files :: [FilePath],
|
2020-07-23 13:51:53 -04:00
|
|
|
prefix :: FilePath,
|
2020-08-03 20:25:59 -04:00
|
|
|
index :: FilePath,
|
2020-07-16 10:07:28 -04:00
|
|
|
output :: Maybe FilePath,
|
|
|
|
dataDir :: FilePath
|
2020-07-15 14:06:19 -04:00
|
|
|
}
|
2020-07-16 10:29:32 -04:00
|
|
|
| IndexPage {
|
2020-08-11 14:29:54 -04:00
|
|
|
root :: Text,
|
2020-07-16 10:29:32 -04:00
|
|
|
file :: FilePath,
|
|
|
|
output :: Maybe FilePath
|
|
|
|
}
|
2020-07-19 12:04:40 -04:00
|
|
|
| RSS {
|
2020-07-24 19:17:47 -04:00
|
|
|
files :: [FilePath],
|
|
|
|
root :: Text,
|
2020-08-03 20:25:59 -04:00
|
|
|
index :: FilePath,
|
2020-07-24 19:17:47 -04:00
|
|
|
prefix :: FilePath,
|
|
|
|
output :: Maybe FilePath,
|
|
|
|
dataDir :: FilePath
|
2020-07-19 12:04:40 -04:00
|
|
|
}
|
2020-07-15 14:06:19 -04:00
|
|
|
| DependSingle {
|
|
|
|
file :: FilePath,
|
|
|
|
nsfw :: Bool,
|
|
|
|
output :: Maybe FilePath,
|
|
|
|
prefix :: FilePath,
|
2022-08-10 19:54:12 -04:00
|
|
|
index :: FilePath,
|
2020-07-15 14:06:19 -04:00
|
|
|
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-25 09:05:38 -04:00
|
|
|
| ListTags {
|
|
|
|
dataDir :: FilePath,
|
|
|
|
infoName :: FilePath,
|
2024-11-04 18:21:35 -05:00
|
|
|
index :: FilePath,
|
2020-07-25 09:05:38 -04:00
|
|
|
nsfw :: Bool,
|
2021-03-07 14:51:44 -05:00
|
|
|
listUntagged :: Bool,
|
2024-11-04 18:21:35 -05:00
|
|
|
showWarnings :: Bool,
|
2021-03-07 14:51:44 -05:00
|
|
|
sortBy :: TagSort
|
2020-07-25 09:05:38 -04:00
|
|
|
}
|
2020-07-15 14:06:19 -04:00
|
|
|
deriving Show
|
|
|
|
|
2021-03-07 14:51:44 -05:00
|
|
|
data TagSort = SortFreq | SortName deriving Show
|
|
|
|
|
2020-07-15 14:06:19 -04:00
|
|
|
|
|
|
|
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-25 09:05:38 -04:00
|
|
|
single <> gallery <> index <> rss <> dependSingle <> dependGallery <>
|
|
|
|
listTags
|
2020-07-15 14:06:19 -04:00
|
|
|
|
|
|
|
single = command "single" $ singleOpts `info` singleInfo
|
2020-08-11 14:29:54 -04:00
|
|
|
singleOpts =
|
2022-08-10 19:54:12 -04:00
|
|
|
SinglePage <$> root <*> file <*> prefix <*> indexFile
|
|
|
|
<*> dataDir <*> nsfwS <*> output
|
2020-08-11 14:29:54 -04:00
|
|
|
root = strOption $
|
|
|
|
short 'R' <> long "root" <> metavar "URL" <>
|
|
|
|
help "website root (no trailing slash)"
|
2020-07-15 14:06:19 -04:00
|
|
|
file = strArgument $
|
|
|
|
metavar "FILE" <> help "yaml file to read"
|
2020-08-11 14:29:54 -04:00
|
|
|
prefix = strOption $
|
|
|
|
short 'p' <> long "prefix" <> metavar "DIR" <>
|
|
|
|
value "" <>
|
|
|
|
help "gallery directory prefix"
|
2022-08-10 19:54:12 -04:00
|
|
|
indexFile = strOption $
|
|
|
|
short 'i' <> long "index" <> metavar "FILE" <>
|
|
|
|
help "path to index file"
|
2020-07-15 14:06:19 -04:00
|
|
|
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
|
2020-08-11 14:29:54 -04:00
|
|
|
indexOpts = IndexPage <$> root <*> file <*> output
|
2020-07-16 10:29:32 -04:00
|
|
|
indexInfo = progDesc "generate an index page for all galleries"
|
|
|
|
|
2020-07-15 14:06:19 -04:00
|
|
|
gallery = command "gallery" $ galleryOpts `info` galleryInfo
|
2020-07-18 05:40:56 -04:00
|
|
|
galleryOpts =
|
2020-08-11 14:29:54 -04:00
|
|
|
GalleryPage <$> root <*> files <*> prefix
|
|
|
|
<*> indexFile <*> output <*> dataDir
|
2020-07-15 14:06:19 -04:00
|
|
|
files = many $ strArgument $
|
|
|
|
metavar "FILE..." <> help "yaml files to read"
|
|
|
|
galleryInfo = progDesc "generate a gallery page"
|
|
|
|
|
2020-07-19 12:04:40 -04:00
|
|
|
rss = command "rss" $ rssOpts `info` rssInfo
|
2020-08-03 20:25:59 -04:00
|
|
|
rssOpts = RSS <$> files <*> root <*> indexFile
|
2020-07-19 12:04:40 -04:00
|
|
|
<*> prefix <*> output <*> dataDir
|
|
|
|
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
|
2022-08-10 19:54:12 -04:00
|
|
|
<*> indexFile <*> buildDir <*> dataDir
|
2020-07-15 14:06:19 -04:00
|
|
|
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-25 09:05:38 -04:00
|
|
|
listTags = command "list-tags" $ ltOpts `info` ltInfo
|
2024-11-04 18:21:35 -05:00
|
|
|
ltOpts = ListTags <$> dataDir <*> infoName <*> indexFile <*> nsfwT
|
|
|
|
<*> listUntagged <*> showWarnings <*> listSort
|
2020-07-25 09:05:38 -04:00
|
|
|
nsfwT = switch $
|
|
|
|
short 'n' <> long "nsfw" <>
|
|
|
|
help "include nsfw tags"
|
2024-11-04 18:21:35 -05:00
|
|
|
listUntagged = switch $
|
2020-07-25 09:05:38 -04:00
|
|
|
short 'U' <> long "untagged" <>
|
|
|
|
help "list files with no tags"
|
2024-11-04 18:21:35 -05:00
|
|
|
showWarnings = switch $
|
|
|
|
short 'W' <> long "warnings" <>
|
|
|
|
help "show tag warnings"
|
2021-03-07 14:51:44 -05:00
|
|
|
listSort = fmap toSort $ switch $
|
|
|
|
short 'a' <> long "alpha" <>
|
|
|
|
help "sort alphabetically instead of by frequency"
|
|
|
|
where toSort x = if x then SortName else SortFreq
|
2020-07-25 09:05:38 -04:00
|
|
|
ltInfo = progDesc "list all tags used by frequency"
|
|
|
|
|
2020-07-15 14:06:19 -04:00
|
|
|
mainInfo = progDesc "static gallery site generator" <> fullDesc
|
|
|
|
|
|
|
|
|
|
|
|
parseOptions :: IO Options
|
|
|
|
parseOptions = execParser optionsParser
|