diff --git a/app.go b/app.go index 0a54cb3..3d9bf06 100644 --- a/app.go +++ b/app.go @@ -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) diff --git a/command.go b/command.go index 992608f..8fa6ce2 100644 --- a/command.go +++ b/command.go @@ -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) diff --git a/context.go b/context.go index f207bd1..b9fe259 100644 --- a/context.go +++ b/context.go @@ -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 } diff --git a/flag.go b/flag.go index 414a9dd..a5f396d 100644 --- a/flag.go +++ b/flag.go @@ -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 = "-"