docopt / docopts

Shell interpreter for docopt, the command-line interface description language.
Other
504 stars 53 forks source link

Terse error message | panic: no fields found in usage (perhaps a spacing error) #47

Closed pihentagy closed 3 years ago

pihentagy commented 4 years ago

The error message given is too terse for me.

Could you elaborate when can I get this error message?

ansible@iinfra2-test:/tmp$ ./create_workload_user -h
panic: no fields found in usage (perhaps a spacing error).

goroutine 1 [running]:
main.main()
    /tmp/docopts_v0.6.3-rc2.5349/docopts.go:458 +0xfc7
./create_workload_user: line 21: <workload_user>: syntax error: operand expected (error token is "<workload_user>")
./create_workload_user: line 23: user: unbound variable
ansible@iinfra2-test:/tmp$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
ansible@iinfra2-test:/tmp$ docopts --version
docopts v0.6.3-rc2 commit 651ff2c built at 2020-04-05T05:13:14Z
built from: go version go1.14.1 linux/amd64
Copyright (C) 2013 Vladimir Keleshev, Lari Rasku.
Copyleft (Ɔ)  2019 Sylvain Viart (golang version).
License MIT <http://opensource.org/licenses/MIT>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Note, that this works on another machine (with other version of bash)

~/infra/workload-manager on  master! ⌚ 18:53:56
$ ./create_workload_user -h
Usage:
  create_workload_user -h | --help
  create_workload_user
  create_workload_user [--provider=<provider>] <workload_user>

Options:
  --provider=<provider>  Provider used, valid choices are vagrant and docker [default: vagrant]

~/infra/workload-manager on  master! ⌚ 18:54:04
$ bash --version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

~/infra/workload-manager on  master! ⌚ 18:54:15
$ docopts --version
docopts v0.6.3-rc2 commit 651ff2c built at 2020-04-05T05:13:14Z
built from: go version go1.14.1 linux/amd64
Copyright (C) 2013 Vladimir Keleshev, Lari Rasku.
Copyleft (Ɔ)  2019 Sylvain Viart (golang version).
License MIT <http://opensource.org/licenses/MIT>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Relevant script part:

#!/usr/bin/env bash

set -o errexit -o pipefail -o noclobber -o nounset
shopt -s nullglob

# Usage:
#   create_workload_user -h | --help
#   create_workload_user
#   create_workload_user [--provider=<provider>] <workload_user>
#
# Options:
#   --provider=<provider>  Provider used, valid choices are vagrant and docker [default: vagrant]
#

source docopts.sh

usage=$(docopt_get_help_string "$0")
eval "$(docopts -A ARGS -h "$usage" : "$@")"
Sylvain303 commented 4 years ago

Hi @pihentagy

I think it's a problem with the version of docopt_get_help_string and the version of awk it should work with GNU awk but not mawk.

If I save your example in t2.sh

$ . docopts.sh 
$ docopt_get_help_string ./t2.sh
# Usage:
#   create_workload_user -h | --help
#   create_workload_user
#   create_workload_user [--provider=<provider>] <workload_user>
#
# Options:
#   --provider=<provider>  Provider used, valid choices are vagrant and docker [default: vagrant]
#

But after installing gawk:

$ docopt_get_help_string ./t2.sh
Usage:
  create_workload_user -h | --help
  create_workload_user
  create_workload_user [--provider=<provider>] <workload_user>

Options:
  --provider=<provider>  Provider used, valid choices are vagrant and docker [default: vagrant]

The dash from the comment are removed. I must issue this bug. You can try this dirty patch. I must also test mac version.

diff --git a/docopts.sh b/docopts.sh
index 3b7bf55..1208489 100644
--- a/docopts.sh
+++ b/docopts.sh
@@ -71,7 +71,7 @@ docopt_get_help_string() {
                 print usage[i]
             }
         }
-        ' < "$myfname"
+        ' < "$myfname" | sed -e 's/^#//' -e 's/^# //'
 }

 # Doc:
Sylvain303 commented 3 years ago

Should be fixed by https://github.com/docopt/docopts/commit/c21151315bea2852ef3250c70a52352c9cd0d6eb