module Options where import Data.Text (Text) 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, title :: Text, output :: Maybe FilePath, dataDir :: FilePath } | IndexPage { file :: FilePath, output :: Maybe 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 } 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 <> dependSingle <> dependGallery 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" 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 <*> nsfwG <*> title <*> output <*> dataDir files = many $ strArgument $ metavar "FILE..." <> help "yaml files to read" nsfwG = switch $ short 'n' <> long "nsfw" <> help "nsfw versions are included" title = strOption $ short 't' <> long "title" <> metavar "TITLE" <> help "page title" 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" 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" mainInfo = progDesc "static gallery site generator" <> fullDesc parseOptions :: IO Options parseOptions = execParser optionsParser