Skip to content

Commit 594cb3b

Browse files
committed
Update README.md
1 parent 5de817a commit 594cb3b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var opts struct {
6262
Name string `short:"n" long:"name" description:"A name" required:"true"`
6363

6464
// Example of a flag restricted to a pre-defined set of strings
65-
Name string `long:"animal" choice:"cat" choice:"dog"`
65+
Animal string `long:"animal" choice:"cat" choice:"dog"`
6666

6767
// Example of a value name
6868
File string `short:"f" long:"file" description:"A file" value-name:"FILE"`
@@ -94,6 +94,7 @@ args := []string{
9494
"-vv",
9595
"--offset=5",
9696
"-n", "Me",
97+
"--animal", "dog", // anything other than "cat" or "dog" will raise an error
9798
"-p", "3",
9899
"-s", "hello",
99100
"-s", "world",
@@ -118,6 +119,7 @@ if err != nil {
118119
fmt.Printf("Verbosity: %v\n", opts.Verbose)
119120
fmt.Printf("Offset: %d\n", opts.Offset)
120121
fmt.Printf("Name: %s\n", opts.Name)
122+
fmt.Printf("Animal: %s\n", opts.Animal)
121123
fmt.Printf("Ptr: %d\n", *opts.Ptr)
122124
fmt.Printf("StringSlice: %v\n", opts.StringSlice)
123125
fmt.Printf("PtrSlice: [%v %v]\n", *opts.PtrSlice[0], *opts.PtrSlice[1])

0 commit comments

Comments
 (0)