Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmdArgsRun on an invalid flag should say how to get help #34

Open
ndmitchell opened this issue Aug 17, 2015 · 1 comment
Open

cmdArgsRun on an invalid flag should say how to get help #34

ndmitchell opened this issue Aug 17, 2015 · 1 comment

Comments

@ndmitchell
Copy link
Owner

From http://code.google.com/p/ndmitchell/issues/detail?id=418

Compare ghc (not cmdargs) with Hoogle (cmdargs):

$ ghc -h
ghc: unrecognised flags: -h

Usage: For basic information, try the `--help' option.

$ hoogle -h
Unknown flag: -h

Using cmdArgsRun, it should always output try the --help option (assuming the help option hasn't been renamed). Suggested by Nick Wu.

And an additional possible idea from bug #425 :

An alternative would be to define a variant of cmdArgsRun which interprets null getArgs to mean that it should print the help message (perhaps with a Bool argument to turn this on and off). Ideally, this variant would also allow other configurations like where to direct the printed output, etc, which could all be bundled together into a CmdArgsRunConfig argument.

@jfeltz remarked: This may be totally out of context, but with 0.10.2 I've gotten around this by calling Explicit.process directly:

import qualified System.Console.CmdArgs.Explicit as Exp                                                  

mode :: Mode (CmdArgs ProgramName)
mode = ...

main :: IO ()
main =
    env_args <- getArgs

    case (Exp.process mode env_args) of
      Right res ->
        case (cmdArgsHelp res) of
          Just h -> putStr h
          Nothing -> myHandleResultFunction $ cmdArgsValue res
      Left err  -> putStr $ err ++ "\n " ++ "(--help for assistance)\n"

This seems to work. Though I'm not sure what the full consequences/implications here are, I've just started using the library.

(Thanks @jfeltz for the suggestion, I had missed it on the Google bug tracker, but I've got it written down now for when I go through the GitHub tracker.)

@ntc2
Copy link

ntc2 commented Nov 1, 2017

I completely agree that typing an invalid flag should show help in addition to failing, but why not add -h to the list of default help flags as a step in the right direction? My first impulse after seeing Unknown flag: <flag> is to run the program again with -h. The current defaults are -? and --help, and I can't even type -? in ZSH without escaping it as -\?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants