import "launchpad.net/gnuflag" func main() { var verbose bool flag := gnuflag.FlagSet{} flag.BoolVar(&verbose, "v", false, "Verbose output") flag.Parse(true, os.Args) if verbose { fmt.Println("Verbose output enabled") } }
import "launchpad.net/gnuflag" func main() { var name string flag := gnuflag.FlagSet{} flag.StringVar(&name, "n", "world", "Name to greet") flag.Parse(true, os.Args) fmt.Printf("Hello, %s!\n", name) }
import "launchpad.net/gnuflag" func main() { var count int flag := gnuflag.FlagSet{} flag.IntVar(&count, "c", 10, "Number of items") flag.Parse(true, os.Args) fmt.Printf("There are %d items.\n", count) }In this example, `gnufalag.FlagSet` is used to define an integer flag called `count`, with a default value of 10. The `IntVar` method is used to associate an integer variable `count` with the flag, and set its usage message (`Number of items`). The `Parse` method is once again used to parse the command-line arguments, with `true` specifying that the program name should be excluded from the arguments. In conclusion, the package library used in the examples above is launchpad.net.gnuflag.