docopt / docopt.go

A command-line arguments parser that will make you smile.
http://docopt.org/
MIT License
1.43k stars 108 forks source link

Defaults don't seem to propagate through parsing #28

Closed sofuture closed 9 years ago

sofuture commented 9 years ago

Doesn't look like defaults work. Example below, code: https://gist.github.com/jzellner/6b760f4663441b1abdb0

[jz@blitz:~/dev]$ ./foo --help
Usage: foo [--bar=<value>]

Foo is a test program.

Options:

  --bar  Test value [default: baz].

[jz@blitz:~/dev]$ ./foo --bar=asdf
asdf

[jz@blitz:~/dev]$ ./foo
<nil>
travisjeffery commented 9 years ago
package main

import (
        "fmt"

        "github.com/docopt/docopt-go"
)

func main() {
        args, _ := docopt.Parse(helpText, nil, true, "foo", false)

        fmt.Println(args["--bar"])
}

const helpText = `
Usage: foo [--bar=<value>]

Foo is a test program.

Options:
  --bar value  Test value [default: baz].
`

here's a fixed version of your example (need to remove after "Options:", and add value (or w/e) between --bar and it's description.

sofuture commented 9 years ago

@travisjeffery Thanks. Not sure if those things are specified clearly enough in the docs, but I'll close this out.