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

Strange error when parsing usage: unmatched '(', expected: ')' got: '' #26

Open
miroswan opened this issue Feb 4, 2015 · 6 comments
Open
Labels

Comments

@miroswan
Copy link

miroswan commented Feb 4, 2015

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.

@khrt
Copy link

khrt commented Feb 11, 2015

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

@catinello
Copy link

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.

@mboersma mboersma added the bug label Jun 19, 2015
@ghostbar
Copy link

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

@namitmr
Copy link

namitmr commented Sep 7, 2017

@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 !

@charz
Copy link

charz commented Aug 20, 2018

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.

@stenote
Copy link

stenote commented Sep 13, 2019

Awesome !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants