import ( "launchpad.net/gnuflag" "fmt" ) func main() { fs := gnuflag.FlagSet{} var testVal bool fs.BoolVar(&testVal, "test", false, "A test boolean value") fs.Parse(true, []string{"--test"}) fmt.Println(testVal) // true }
import ( "launchpad.net/gnuflag" "fmt" "os" ) func main() { fs := gnuflag.FlagSet{} var testVal bool fs.BoolVar(&testVal, "test", false, "A test boolean value") fs.Parse(true, os.Args[1:]) fmt.Println(testVal) // true or false depending on whether --test was provided }In this example, we create a FlagSet and a boolean variable `testVal` using the BoolVar function. We then parse the command-line arguments passed to the program (excluding the first argument, which is the program name) using the `Parse` method of the FlagSet and print out the value of `testVal`.