gallery/make-pages/Options.hs

89 lines
2.5 KiB
Haskell
Raw Normal View History

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
}
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 <> dependSingle
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"
mainInfo = progDesc "static gallery site generator" <> fullDesc
parseOptions :: IO Options
parseOptions = execParser optionsParser