Golang flag.FlagSet.VisitAll() function example
package flag
VisitAll visits the flags in lexicographical order, calling fn for each. It visits all flags, even those not set.
Golang flag.FlagSet.VisitAll() function usage example
package main
import (
"flag"
"fmt"
)
func main() {
f := flag.NewFlagSet("flag", flag.ExitOnError)
f.Int("int", 0, "int flag with value")
f.Int("int2", 0, "second int flag with value")
visitor := func(a *flag.Flag) {
fmt.Println(">", a.Name, "value=", a.Value)
}
fmt.Println("First visit")
f.Visit(visitor) // no value assigned
f.Parse([]string{"-int", "108"}) // visit flag set earlier and assign value
fmt.Println("Second visit")
f.Visit(visitor)
fmt.Println("Visit All")
f.VisitAll(visitor) // this will display the int2 flag
}
Output :
First visit
Second visit
> int value= 108
Visit All
int value= 108
int2 value= 0
Reference :
Advertisement
Something interesting
Tutorials
+8.3k Golang : Emulate NumPy way of creating matrix example
+13.1k Golang : List objects in AWS S3 bucket
+18.1k Golang : Convert IPv4 address to decimal number(base 10) or integer
+6.2k Golang & Javascript : How to save cropped image to file on server
+15.2k Golang : How to add color to string?
+6.9k Mac OSX : Find large files by size
+7.5k Gogland : Single File versus Go Application Run Configurations
+9.8k Golang : Resumable upload to Google Drive(RESTful) example
+5.8k Golang : Launching your executable inside a console under Linux
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+46.4k Golang : Encode image to base64 example