docopt.hs
docopt.hs copied to clipboard
Prints whole usage string on incorrect arguments
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
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.