module Git.Fmt.Options.Applicative.Parser (
gitFmtPrefs, gitFmtInfo, gitFmt,
) where
import Data.Version (showVersion)
import Options.Applicative
import Options.Applicative.Types (readerAsk)
import Git.Fmt
import Git.Fmt.Version as This
gitFmtPrefs :: ParserPrefs
gitFmtPrefs = prefs $ columns 100
gitFmtInfo :: ParserInfo Options
gitFmtInfo = info (infoOptions <*> gitFmt) fullDesc
where
infoOptions = helper <*> version <*> numericVersion
version = infoOption ("Version " ++ showVersion This.version) $ mconcat [
long "version", short 'V', hidden,
help "Show this binary's version"
]
numericVersion = infoOption (showVersion This.version) $ mconcat [
long "numeric-version", hidden,
help "Show this binary's version (without the prefix)"
]
gitFmt :: Parser Options
gitFmt = Options
<$> (
flag' Quiet (mconcat [
long "quiet", short 'q', hidden,
help "Be quiet"
])
<|> flag Default Verbose (mconcat [
long "verbose", short 'v', hidden,
help "Be verbose"
])
)
<*> switch (mconcat [
long "null", short '0',
help "Input files are delimited by a null terminator instead of white space"
])
<*> modeOption (mconcat [
long "mode", short 'm', metavar "MODE",
value Normal, showDefaultWith $ const "normal",
help "Specify the mode as either `normal' or `dry-run'"
])
<*> many (strArgument $ mconcat [
metavar "-- PATHS..."
])
where
modeOption = option $ readerAsk >>= \opt -> case opt of
"normal" -> return Normal
"dry-run" -> return DryRun
_ -> readerError $ "unrecognised mode `" ++ opt ++ "'"