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