How can I rewrite the --help flag output in optparse-applicative

65 Views Asked by At

I'm trying to rewrite the automatically generated help output from optparse-applicative. Following code lets me replace the help output:

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

(Can be executed with stack script --resolver=lts-16 main.hs -- --help)

However, I don't want to replace it completely, but only replace certain parts of the automatically generated help text. How is this possible?

0

There are 0 best solutions below