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

ParseArgs fails to compile [--speed=<kn>] #59

Open
fenollp opened this issue May 20, 2018 · 0 comments
Open

ParseArgs fails to compile [--speed=<kn>] #59

fenollp opened this issue May 20, 2018 · 0 comments

Comments

@fenollp
Copy link

fenollp commented May 20, 2018

On commit ee0de3b

package main

import (
	"fmt"
	"os"
	"github.com/docopt/docopt-go"
)

func main() {
	usage := `Naval Fate.

Usage:
  naval_fate.py ship [--speed=<kn>]
  naval_fate.py -h | --help
  naval_fate.py --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
`

	{
		// this works
		args, err := docopt.ParseDoc(usage)
		if err != nil { panic(err) }
		fmt.Printf("%+v\n", args)
		fmt.Println(args["--speed"])
	}

	{
		// this panics
		parser := &docopt.Parser{
			HelpHandler:  docopt.PrintHelpOnly,
			OptionsFirst: true,
		}
		args, err := parser.ParseArgs(usage, os.Args[1:], "naval_fate.py")
		if err != nil { panic(err) }
		fmt.Printf("%+v\n", args)
		fmt.Println(args["--speed"])
	}
}
∀ go run docopt_wat.go ship --speed 23
map[ship:true --speed:23 --help:false --version:false]
23
Usage:
  naval_fate.py ship [--speed=<kn>]
  naval_fate.py -h | --help
  naval_fate.py --version
panic: 

goroutine 1 [running]:
main.main()
	/home/pete/docopt_wat.go:36 +0x2f6
exit status 2
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

1 participant