update documentation to new way of specifying defaults

This commit is contained in:
Alex Flint 2019-10-21 23:13:41 -07:00
parent 809e9060d0
commit 7ac060af18
2 changed files with 4 additions and 7 deletions

View File

@ -142,10 +142,9 @@ Options:
```go ```go
var args struct { var args struct {
Foo string Foo string `default:"abc"`
Bar bool Bar bool
} }
args.Foo = "default value"
arg.MustParse(&args) arg.MustParse(&args)
``` ```
@ -307,9 +306,8 @@ func (n *NameDotName) MarshalText() ([]byte, error) {
func main() { func main() {
var args struct { var args struct {
Name NameDotName Name NameDotName `default:"file.txt"`
} }
args.Name = NameDotName{"file", "txt"} // set default value
arg.MustParse(&args) arg.MustParse(&args)
fmt.Printf("%#v\n", args.Name) fmt.Printf("%#v\n", args.Name)
} }

View File

@ -30,12 +30,11 @@ func Example_defaultValues() {
os.Args = split("./example") os.Args = split("./example")
var args struct { var args struct {
Foo string Foo string `default:"abc"`
} }
args.Foo = "default value"
MustParse(&args) MustParse(&args)
fmt.Println(args.Foo) fmt.Println(args.Foo)
// output: default value // output: abc
} }
// This example demonstrates arguments that are required // This example demonstrates arguments that are required