example.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package main
  2. import (
  3. "fmt"
  4. flag "github.com/dotcloud/docker/pkg/mflag"
  5. )
  6. var (
  7. i int
  8. str string
  9. b, b2, h bool
  10. )
  11. func init() {
  12. flag.Bool([]string{"#hp", "#-halp"}, false, "display the halp")
  13. flag.BoolVar(&b, []string{"b", "#bal", "#bol", "-bal"}, false, "a simple bool")
  14. flag.BoolVar(&b, []string{"g", "#gil"}, false, "a simple bool")
  15. flag.BoolVar(&b2, []string{"#-bool"}, false, "a simple bool")
  16. flag.IntVar(&i, []string{"-integer", "-number"}, -1, "a simple integer")
  17. flag.StringVar(&str, []string{"s", "#hidden", "-string"}, "", "a simple string") //-s -hidden and --string will work, but -hidden won't be in the usage
  18. flag.BoolVar(&h, []string{"h", "#help", "-help"}, false, "display the help")
  19. flag.StringVar(&str, []string{"mode"}, "mode1", "set the mode\nmode1: use the mode1\nmode2: use the mode2\nmode3: use the mode3")
  20. flag.Parse()
  21. }
  22. func main() {
  23. if h {
  24. flag.PrintDefaults()
  25. } else {
  26. fmt.Printf("s/#hidden/-string: %s\n", str)
  27. fmt.Printf("b: %t\n", b)
  28. fmt.Printf("-bool: %t\n", b2)
  29. fmt.Printf("s/#hidden/-string(via lookup): %s\n", flag.Lookup("s").Value.String())
  30. fmt.Printf("ARGS: %v\n", flag.Args())
  31. }
  32. }