如何在optparse-applicative中重写--help标志输出

时间:2020-06-14 11:11:32

标签: haskell optparse optparse-applicative

我正在尝试重写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执行)

但是,我不想完全替换它, 但只能替换自动生成的帮助文本的某些部分。 这怎么可能?

0 个答案:

没有答案