docopt.hs icon indicating copy to clipboard operation
docopt.hs copied to clipboard

Prints whole usage string on incorrect arguments

Open jpdoyle opened this issue 7 years ago • 1 comments

Consider this example.

Per the reference implementation, an incorrect sequence of arguments should output the brief usage description. I adapted the example from the readme:

{-# LANGUAGE QuasiQuotes #-}
module Main where
import System.Console.Docopt
import System.Environment (getArgs)

optparser :: Docopt
optparser = [docopt|
Naval Fate.

Usage:
  naval_fate.py ship new <name>...
  naval_fate.py ship <name> move <x> <y> [--speed=<kn>]
  naval_fate.py ship shoot <x> <y>
  naval_fate.py mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate.py -h | --help
  naval_fate.py --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.
|]

getArgOrExit = getArgOrExitWith optparser

main :: IO ()
main = do
  args <- parseArgsOrExit optparser =<< getArgs

  print args

However, when I execute it with no arguments I get:

Naval Fate.

Usage:
  naval_fate.py ship new <name>...
  naval_fate.py ship <name> move <x> <y> [--speed=<kn>]
  naval_fate.py ship shoot <x> <y>
  naval_fate.py mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate.py -h | --help
  naval_fate.py --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.

instead of the expected:

Usage:
  naval_fate.py ship new <name>...
  naval_fate.py ship <name> move <x> <y> [--speed=<kn>]
  naval_fate.py ship shoot <x> <y>
  naval_fate.py mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate.py -h | --help
  naval_fate.py --version

jpdoyle avatar Nov 02 '18 02:11 jpdoyle

This is definitely a mismatch of behavior from what the original docopt intended. On incorrect arguments it should print only the usage section without the options section. The options section should only be included as an output if someone types --help in the example link.

FullstackGJJ avatar Sep 25 '21 21:09 FullstackGJJ