docopts icon indicating copy to clipboard operation
docopts copied to clipboard

Empty error message when launching script without mandatory argument

Open CristianCantoro opened this issue 6 years ago • 2 comments

With the latest docopts-go build:

#!/usr/bin/env bash
# file: atest.sh

arg=''

eval "$(./docopts -V - -h - : "$@" <<EOF
Usage: atest.sh <arg>
       atest.sh ( -h | --help )
       atest.sh ( -V | --version )

      arg				An argument.

Options:
      -h, --help        Show this help message and exits.
      -V, --version     Print version and copyright information.
----
atest 0.1.0
EOF
)"

echo "$arg"

If I launch the script without the mandatory argument no error message is shown:

$ ./atest.
error: 
Usage: atest.sh <arg>
       atest.sh ( -h | --help )
       atest.sh ( -V | --version )

CristianCantoro avatar Jun 25 '18 14:06 CristianCantoro

Yes, thanks reporting.

error: is empty. It seems to be an internal behavior of the go lib docopt-go (or may be even python's docopt lib). I've to investigate in this code. Globally the docopt libs are bad for error reporting. :(

You can have almost same behavior with python's version of docopts:

In your working copy, fetch the tagged previous version (you'll need python interpretor and python's docopt too)

git checkout v0.6.1+fix

And retry your example, it gives:

sylvain@lap40:~/code/go/src/github.com/docopt/docopts/issues/17-Empty-error-without-mandatory-argument$ ./atest.sh 
Usage: atest.sh <arg>
       atest.sh ( -h | --help )
       atest.sh ( -V | --version )

How to fix that? Well, it would be an enhancement, the most advanced docopt lib seems to be the Rust version I've to look at it if they addressed this issue.

I'm creating an issue in golang version of the docopt lib for that too, if the maintainer could help.

https://github.com/Sylvain303/docopts/tree/debug-issues/issues/17-Empty-error-without-mandatory-argument

https://github.com/docopt/docopt.go/issues/61

By design for now, calling without mandatory argument produce an error, but the display is to print, partial usage + exit status non zero. I added an error: part in the docopts code, which is empty in that case, because the lib fail with an empty message.

What would you suggest for docopts HelpHandler?

Sylvain303 avatar Jul 01 '18 07:07 Sylvain303

@Sylvain303 said:

In your working copy, fetch the tagged previous version (you'll need python interpretor and python's docopt too)

Yes, I have seen the difference with the Python-based implementation of docopts.

By design for now, calling without mandatory argument produce an error, but the display is to print, partial usage + exit status non zero. I added an error: part in the docopts code, which is empty in that case, because the lib fail with an empty message.

What would you suggest for docopts HelpHandler?

I would suggest a message like Error: required argument <arg> is missing, or something like that.

CristianCantoro avatar Jul 01 '18 14:07 CristianCantoro