Currently, it looks like the only way to do this is to create your own version of customExecParser
from the Options.Applicative.Extra module. There is an open issue to make this simpler.
Something like this should be pretty close to what you're 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 = ...
This is basically just customExecParser
with a small block that checks if the args are empty. If they are, it displays the parser help.