module Options where import Data.Text (Text) import Options.Applicative data Options = Options { verbose :: Bool, mode :: ModeOptions } deriving Show data ModeOptions = SinglePage { file :: FilePath, dataDir :: FilePath, nsfw :: Bool, output :: Maybe FilePath } | GalleryPage { files :: [FilePath], prefix :: FilePath, index :: FilePath, output :: Maybe FilePath, dataDir :: FilePath } | IndexPage { 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, buildDir :: FilePath, dataDir :: FilePath } | DependGallery { file :: FilePath, output :: Maybe FilePath, buildDir :: FilePath, dataDir :: FilePath, tmpDir :: FilePath, infoName :: FilePath } | ListTags { dataDir :: FilePath, infoName :: FilePath, nsfw :: Bool, listUntagged :: Bool } 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 <$> file <*> dataDir <*> 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" index = command "index" $ indexOpts `info` indexInfo indexOpts = IndexPage <$> file <*> output indexInfo = progDesc "generate an index page for all galleries" gallery = command "gallery" $ galleryOpts `info` galleryInfo galleryOpts = GalleryPage <$> files <*> prefix <*> indexFile <*> output <*> dataDir prefix = strOption $ short 'p' <> long "prefix" <> metavar "DIR" <> value "" <> help "output directory prefix" indexFile = strOption $ short 'i' <> long "index" <> metavar "FILE" <> help "path to index file" 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 root = strOption $ short 'R' <> long "root" <> metavar "URL" <> help "website root (no trailing slash)" rssInfo = progDesc "generate an rss file for a gallery" dependSingle = command "depend-single" $ dsOpts `info` dsInfo dsOpts = DependSingle <$> file <*> nsfwS <*> output <*> prefix <*> 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 <*> nsfwT <*> listUntagged_ nsfwT = switch $ short 'n' <> long "nsfw" <> help "include nsfw tags" listUntagged_ = switch $ short 'U' <> long "untagged" <> help "list files with no tags" ltInfo = progDesc "list all tags used by frequency" mainInfo = progDesc "static gallery site generator" <> fullDesc parseOptions :: IO Options parseOptions = execParser optionsParser