docopt.go icon indicating copy to clipboard operation
docopt.go copied to clipboard

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

Open miroswan opened this issue 10 years ago • 6 comments

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.

miroswan avatar Feb 04 '15 12:02 miroswan

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

khrt avatar Feb 11 '15 09:02 khrt

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.

catinello avatar Mar 23 '15 21:03 catinello

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

ghostbar avatar Oct 10 '15 06:10 ghostbar

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

namitmr avatar Sep 07 '17 11:09 namitmr

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.

charz avatar Aug 20 '18 15:08 charz

Awesome !

stenote avatar Sep 13 '19 14:09 stenote