fix panic in mflag

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
Victor Vieux 2014-01-31 11:33:48 -08:00 committed by Victor Vieux
parent 8520c2e940
commit 84a91cabdd
3 changed files with 29 additions and 5 deletions

View file

@ -6,13 +6,14 @@ import (
)
var (
i int
str string
b, h bool
i int
str string
b, b2, h bool
)
func init() {
flag.BoolVar(&b, []string{"b"}, false, "a simple bool")
flag.BoolVar(&b2, []string{"-bool"}, false, "a simple bool")
flag.IntVar(&i, []string{"#integer", "-integer"}, -1, "a simple integer")
flag.StringVar(&str, []string{"s", "#hidden", "-string"}, "", "a simple string") //-s -hidden and --string will work, but -hidden won't be in the usage
flag.BoolVar(&h, []string{"h", "#help", "-help"}, false, "display the help")
@ -22,6 +23,8 @@ func main() {
if h {
flag.PrintDefaults()
}
fmt.Printf("%s\n", str)
fmt.Printf("%s\n", flag.Lookup("s").Value.String())
fmt.Printf("s/#hidden/-string: %s\n", str)
fmt.Printf("b: %b\n", b)
fmt.Printf("-bool: %b\n", b2)
fmt.Printf("s/#hidden/-string(via lookup): %s\n", flag.Lookup("s").Value.String())
}