File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff 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 {
118119fmt.Printf (" Verbosity: %v \n " , opts.Verbose )
119120fmt.Printf (" Offset: %d \n " , opts.Offset )
120121fmt.Printf (" Name: %s \n " , opts.Name )
122+ fmt.Printf (" Animal: %s \n " , opts.Animal )
121123fmt.Printf (" Ptr: %d \n " , *opts.Ptr )
122124fmt.Printf (" StringSlice: %v \n " , opts.StringSlice )
123125fmt.Printf (" PtrSlice: [%v %v ]\n " , *opts.PtrSlice [0 ], *opts.PtrSlice [1 ])
You can’t perform that action at this time.
0 commit comments