浏览代码

fix usage for completly deprecated flag

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
Victor Vieux 11 年之前
父节点
当前提交
089bf5e11e
共有 2 个文件被更改,包括 4 次插入1 次删除
  1. 1 0
      pkg/mflag/example/example.go
  2. 3 1
      pkg/mflag/flag.go

+ 1 - 0
pkg/mflag/example/example.go

@@ -12,6 +12,7 @@ var (
 )
 
 func init() {
+	flag.Bool([]string{"#hp", "#-halp"}, false, "display the halp")
 	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")

+ 3 - 1
pkg/mflag/flag.go

@@ -404,7 +404,9 @@ func (f *FlagSet) PrintDefaults() {
 				names = append(names, name)
 			}
 		}
-		fmt.Fprintf(f.out(), format, strings.Join(names, ", -"), flag.DefValue, flag.Usage)
+		if len(names) > 0 {
+			fmt.Fprintf(f.out(), format, strings.Join(names, ", -"), flag.DefValue, flag.Usage)
+		}
 	})
 }