docopt.go
docopt.go copied to clipboard
Strange error when parsing usage: unmatched '(', expected: ')' got: ''
package main
import (
"fmt"
"os"
docopt "github.com/docopt/docopt-go"
)
func main() {
usage := `cprint
Enhance terminal output without typing ANSI escape patterns
Usage:
cprint [--attr=<attr>] --color=<color> <word>...
cprint --showattrs
cprint --showcolors
Options:
--attr=<attr> Attribute
--color=<color> Desired color
--showattrs Show attributes
--showcolors Show colors`
args, err := docopt.Parse(usage, nil, true, "0.1", false)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(args)
}
Print statements would indicate that somewhere along the way a parseSeq call attempts to call parseAtom and it fails because the ([ and )] characters are unbalanced in the tokenList. There is an extra ).
If I add a ) char after --showcolors the error goes away.
I've got almost the same error.
map[]
Error: unmatched '[', expected: ']' got: ')'
And I don't know how to balance it.
usage := `go-gist
go-gist lets you upload to https://gist.github.com/. Go clone of the official Gist client.
Usage:
go-gist [-oce] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P] (-f NAME | -t EXT) FILE...
go-gist --login
Options:
--login Authenticate gist on this computer.
-f NAME --filename=NAME Sets the filename and syntax type.
-t EXT --type=EXT Sets the file extension and syntax type.
-p --private Indicates whether the gist is private.
-d DESC --description=DESC Adds a description to your gist.
-s --shorten *Shorten the gist URL using git.io.
-u URL --update=URL Update an existing gist.
-a --anonymous Create an anonymous gist.
-c --copy Copy the resulting URL to the clipboard.
-e --embed *Copy the embed code for the gist to the clipboard.
-o --open *Open the resulting URL in a browser.
-P --paste Paste from the clipboard to gist.
-R --raw *Display raw URL of the new gist.
-l USER --list=USER Lists all gists for a user.
-h --help Show this help message and exit.
--version Show version and exit.`
arguments, err := docopt.Parse(usage, nil, true, "go-gist "+VERSION, false)
fmt.Println(arguments)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
go version go1.3.3 darwin/amd64
Use two spaces to separate options with their informal description.
eg. 4 spaces, "--login", 2 SPACES, followed by optional tabs for formatting, "Authenticate gist on this computer."
--login <TAB><TAB><TAB>Authenticate gist on this computer.
Indeed, Options are not being parsed correctly at all, using the example on the README:
$ curl -OL https://raw.githubusercontent.com/docopt/docopt.go/master/examples/naval_fate/naval_fate.go
$ go run naval_fate.go
Usage:
naval_fate ship new <name>...
naval_fate ship <name> move <x> <y> [--speed=<kn>]
naval_fate ship shoot <x> <y>
naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
naval_fate -h | --help
naval_fate --version
exit status 1
$ go version
go version go1.5.1 darwin/amd64
Which renders the package unusable
@catinello had the exact same issue :
PANI[0000] FailedParsingArguments. Error unmatched '[', expected: ']' got: ')'
Debugging this was a pain, adding 2 spaces before the tab formatting resolved it ! Seems like the bug
still exists.
BTW, thanks for the solution !
I ran into this issue too, just DON'T use <tab>
. It just works very well since I replaced all <tab>
with <space>
. And use 4 spaces for Indenting each line under Options
, Usage
, ... etc.
Awesome !