mdoc-0.1.0.0: src/Mdoc/Dump/Options.hs
{-# OPTIONS_GHC -Wno-ambiguous-fields #-}
-- |
--
-- Module : Mdoc.Dump.Options
-- Copyright : (c) 2026 Patrick Brisbin
-- License : AGPL-3
-- Maintainer : pbrisbin@gmail.com
-- Stability : experimental
-- Portability : POSIX
module Mdoc.Dump.Options
( Options (..)
, parseOptions
-- * For man-page generation
, optionsInfo
, optionsParser
) where
import Prelude
import Mdoc.Dump.Env
import Mdoc.Pretty (Color (..), readColor)
import Options.Applicative
data Options = Options
{ check :: Bool
, updateMdocdate :: Bool
, color :: Maybe Color
, debug :: Bool
, input :: [FilePath]
}
parseOptions :: IO Options
parseOptions = do
env <- parseEnv
opt <-
execParser
$ info (optionsParser <**> helper)
$ fullDesc <> progDesc optionsInfo
pure
(opt :: Options)
{ color = opt.color <|> env.color
, debug = env.debug || opt.debug
}
optionsInfo :: String
optionsInfo = envInfo
optionsParser :: Parser Options
optionsParser =
Options
<$> switch
( mconcat
[ short 'c'
, long "check"
, help "Check that re-rendering parsed as mdoc matches input"
]
)
<*> switch
( mconcat
[ long "update-mdocdate"
, help "Update any $Mdocdate$ macros in the output"
]
)
<*> optional
( option
(eitherReader readColor)
( mconcat
[ long "color"
, help "When to colorize the output"
, metavar "auto|always|never"
]
)
)
<*> switch
( mconcat
[ short 'v'
, long "debug"
, help "Log more verbosely"
]
)
<*> many
( argument
str
( mconcat
[ metavar "FILE"
, help
"Read from the given file (if specified multiple times, output is concatenated; if none are specified, stdin is read)"
]
)
)