docopts
docopts copied to clipboard
Empty error message when launching script without mandatory argument
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 )
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 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.