Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pihentagy opened this issue Aug 4, 2020 · 2 comments

Comments

@pihentagy
Copy link

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
Copy link
Collaborator

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 added a commit that referenced this issue Dec 6, 2020
@Sylvain303
Copy link
Collaborator

Should be fixed by c211513

endorama added a commit to endorama/nixpkgs that referenced this issue Nov 3, 2021
Version 0.6.3 was affected by a bug (docopt/docopts#47) that has been resolved in 0.6.4.

Signed-off-by: Edoardo Tenani <edoardo.tenani@pm.me>
thiagokokada pushed a commit to NixOS/nixpkgs that referenced this issue Nov 16, 2021
Version 0.6.3 was affected by a bug (docopt/docopts#47) that has been resolved in 0.6.4.

Signed-off-by: Edoardo Tenani <edoardo.tenani@pm.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants