Golang flag.VisitAll() function example
package flag
VisitAll visits the command-line flags in lexicographical order, calling fn for each. It visits all flags, even those not set.
Golang flag.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
See https://www.socketloop.com/references/golang-flag-visit-function-example for comparison
Reference :
See also : Golang flag.Visit() function example
Advertisement
Something interesting
Tutorials
+18.1k Golang : Check if a directory exist or not
+17.9k Golang : How to make a file read only and set it to writable again?
+17.6k Golang : Upload/Receive file progress indicator
+10.8k Android Studio : Checkbox for user to select options example
+15.4k Golang : Find location by IP address and display with Google Map
+5.8k Unix/Linux : How to test user agents blocked successfully ?
+8.6k Android Studio : Import third-party library or package into Gradle Scripts
+6.5k Golang : Map within a map example
+10.5k Golang : Create matrix with Gonum Matrix package example
+18.4k Golang : How to get hour, minute, second from time?
+6.8k Get Facebook friends working in same company
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example