Currently, it seems the only way to do this is to create your own version of customExecParser from the Options.Applicative.Extra module . There is an open problem to make it easier.
Something like this should be very close to what you are looking for:
import Options.Applicative import Options.Applicative.Help as AH import Options.Applicative.Types as AT import System.Environment (getArgs, getProgName) import System.Exit (exitWith, ExitCode(..)) import System.IO (hPutStr, stderr) execParserWithHelp :: ParserPrefs -> ParserInfo a -> IO a execParserWithHelp pprefs pinfo = do args <- getArgs case execParserPure pprefs pinfo args of Right a -> return a Left failure -> do progn <- getProgName msg <- AT.errMessage failure progn let extra = if null args then AH.parserHelpText pprefs pinfo else "" let c = errExitCode failure case c of ExitSuccess -> putStr (msg ++ extra) _ -> hPutStr stderr (msg ++ extra) exitWith c main :: IO () main = execParserWithHelp (prefs idm) opts >>= run opts :: ParserInfo Command opts = info (commands <**> helper) idm run :: Command -> IO () run = ...
It is basically just a customExecParser with a small block that checks if the arguments are empty. If they are, it displays the help of the parser.
source share