我正在尝试重写optparse-applicative的自动生成的帮助输出。 以下代码可让我替换帮助输出:
import Options.Applicative
import Data.Semigroup ((<>))
data Opts = Opts { optFast :: Bool, optHelp :: Bool }
sample :: Parser Opts
sample = Opts
<$> switch
( long "fast"
<> short 'f'
<> help "Whether to be fast" )
<*> switch
( long "help"
<> short 'h'
<> help $ info )
doSomething :: Opts -> IO ()
doSomething (Opts { optFast = True }) = putStrLn $ "Very fast execution!"
doSomething (Opts { optHelp = True }) = putStrLn $ "Some help for you!"
doSomething _ = putStrLn $ "Rather slow execution."
main :: IO ()
main =
let
opts = info (sample)
( fullDesc
<> progDesc "Print execution speed"
<> header "Hello - A test for optparse-applicative" )
in
doSomething =<< execParser opts
(可以用stack script --resolver=lts-16 main.hs -- --help
执行)
但是,我不想完全替换它, 但只能替换自动生成的帮助文本的某些部分。 这怎么可能?