ndmitchell / cmdargs

Haskell library for command line argument processing
Other
91 stars 12 forks source link

Generate help text if no default mode was specified #50

Closed GianlucaGuarini closed 6 years ago

GianlucaGuarini commented 6 years ago

Hi thank you for this awesome helper. I am struggling trying to get the help text as default command if no options were specified for example:

$ mycli

should generate the same output as

$ mycli --help

Do you have any hint to lead me to a possible solution? Thank you

GianlucaGuarini commented 6 years ago

never mind i have found a simple solution:

import System.Console.CmdArgs (cmdArgsRun)
import System.Console.CmdArgs.Explicit(helpText, HelpFormat(..))

main :: IO()
main = do
  args <- getArgs
  if null args then exitWithHelp
  else parse =<< cmdArgsRun mode

exitWithHelp :: IO a
exitWithHelp = do
  putStr $ show $ helpText [] HelpFormatAll mode
  exitSuccess
Synthetica9 commented 5 years ago

Would be really nice if this were somewhere in the library itself... Any chance of that?