2020-07-15 14:06:19 -04:00
|
|
|
module Options where
|
|
|
|
|
|
|
|
import Info
|
|
|
|
import Options.Applicative
|
|
|
|
|
|
|
|
data Options =
|
|
|
|
Options {
|
|
|
|
verbose :: Bool,
|
|
|
|
mode :: ModeOptions
|
|
|
|
}
|
|
|
|
deriving Show
|
|
|
|
|
|
|
|
data ModeOptions =
|
|
|
|
SinglePage {
|
|
|
|
file :: FilePath,
|
|
|
|
nsfw :: Bool,
|
|
|
|
output :: Maybe FilePath
|
|
|
|
}
|
|
|
|
| GalleryPage {
|
|
|
|
files :: [FilePath],
|
|
|
|
nsfw :: Bool,
|
|
|
|
output :: Maybe FilePath
|
|
|
|
}
|
|
|
|
| DependSingle {
|
|
|
|
file :: FilePath,
|
|
|
|
nsfw :: Bool,
|
|
|
|
output :: Maybe FilePath,
|
|
|
|
prefix :: FilePath,
|
|
|
|
buildDir :: FilePath,
|
|
|
|
dataDir :: FilePath
|
|
|
|
}
|
2020-07-16 05:48:37 -04:00
|
|
|
| DependGallery {
|
|
|
|
prefix :: FilePath,
|
|
|
|
files :: [FilePath],
|
|
|
|
nsfw :: Bool,
|
|
|
|
who :: Who,
|
|
|
|
output :: Maybe FilePath,
|
|
|
|
buildDir :: FilePath,
|
|
|
|
dataDir :: FilePath
|
|
|
|
}
|
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-16 05:48:37 -04:00
|
|
|
single <> gallery <> 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"
|
|
|
|
|
|
|
|
gallery = command "gallery" $ galleryOpts `info` galleryInfo
|
|
|
|
galleryOpts = GalleryPage <$> files <*> nsfwG <*> output
|
|
|
|
files = many $ strArgument $
|
|
|
|
metavar "FILE..." <> help "yaml files to read"
|
|
|
|
nsfwG = switch $
|
|
|
|
short 'n' <> long "nsfw" <>
|
|
|
|
help "include works with no sfw versions"
|
|
|
|
galleryInfo = progDesc "generate a gallery page"
|
|
|
|
|
|
|
|
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 $
|
|
|
|
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"
|
|
|
|
|
2020-07-16 05:48:37 -04:00
|
|
|
dependGallery = command "depend-gallery" $ dgOpts `info` dgInfo
|
|
|
|
dgOpts =
|
|
|
|
DependGallery <$> prefixArg <*> files <*> nsfwG <*> who
|
|
|
|
<*> output <*> buildDir <*> dataDir
|
|
|
|
prefixArg = strArgument $
|
|
|
|
metavar "PREFIX" <> help "target directory"
|
|
|
|
who = option (maybeReader readWho) $
|
|
|
|
short 'w' <> long "who" <>
|
|
|
|
metavar "mine|not-mine|all" <>
|
|
|
|
value All <>
|
|
|
|
help "select by artist"
|
|
|
|
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
|