Removed help flag. we no longer need it.

This commit is contained in:
Jeremy Saenz 2013-11-20 17:24:37 -08:00
parent 37eef5912e
commit 4120b604ec
4 changed files with 9 additions and 27 deletions

2
app.go
View File

@ -42,7 +42,7 @@ func (a *App) Run(arguments []string) error {
//append version/help flags
a.appendFlag(BoolFlag{"version", "print the version"})
a.appendFlag(helpFlag{"show help"})
a.appendFlag(BoolFlag{"help, h", "show help"})
// parse flags
set := flagSet(a.Name, a.Flags)

View File

@ -27,7 +27,7 @@ func (c Command) Run(ctx *Context) error {
// append help to flags
c.Flags = append(
c.Flags,
helpFlag{"show help"},
BoolFlag{"help, h","show help"},
)
set := flagSet(c.Name, c.Flags)

View File

@ -138,7 +138,7 @@ func normalizeFlags(flags []Flag, set *flag.FlagSet) error {
visited[f.Name] = true
})
for _, f := range flags {
parts := strings.Split(f.GetName(), ",")
parts := strings.Split(f.getName(), ",")
if len(parts) == 1 {
continue
}

30
flag.go
View File

@ -12,7 +12,7 @@ type Flag interface {
fmt.Stringer
// Apply Flag settings to the given flag set
Apply(*flag.FlagSet)
GetName() string
getName() string
}
func flagSet(name string, flags []Flag) *flag.FlagSet {
@ -63,7 +63,7 @@ func (f StringSliceFlag) Apply(set *flag.FlagSet) {
})
}
func (f StringSliceFlag) GetName() string {
func (f StringSliceFlag) getName() string {
return f.Name
}
@ -106,7 +106,7 @@ func (f IntSliceFlag) Apply(set *flag.FlagSet) {
})
}
func (f IntSliceFlag) GetName() string {
func (f IntSliceFlag) getName() string {
return f.Name
}
@ -125,7 +125,7 @@ func (f BoolFlag) Apply(set *flag.FlagSet) {
})
}
func (f BoolFlag) GetName() string {
func (f BoolFlag) getName() string {
return f.Name
}
@ -145,7 +145,7 @@ func (f StringFlag) Apply(set *flag.FlagSet) {
})
}
func (f StringFlag) GetName() string {
func (f StringFlag) getName() string {
return f.Name
}
@ -165,28 +165,10 @@ func (f IntFlag) Apply(set *flag.FlagSet) {
})
}
func (f IntFlag) GetName() string {
func (f IntFlag) getName() string {
return f.Name
}
type helpFlag struct {
Usage string
}
func (f helpFlag) String() string {
return fmt.Sprintf("%s\t%v", prefixedNames("help, h"), f.Usage)
}
func (f helpFlag) Apply(set *flag.FlagSet) {
eachName("help, h", func(name string) {
set.Bool(name, false, f.Usage)
})
}
func (f helpFlag) GetName() string {
return "help"
}
func prefixFor(name string) (prefix string) {
if len(name) == 1 {
prefix = "-"