Minor tweaks and cleanup
This commit is contained in:
parent
2aab39bf49
commit
04490dabec
2
app.go
2
app.go
@ -29,7 +29,7 @@ func NewApp() *App {
|
||||
|
||||
func (a *App) Run(arguments []string) {
|
||||
// parse flags
|
||||
set := flagSet(a.Flags)
|
||||
set := flagSet(a.Name, a.Flags)
|
||||
set.Parse(arguments[1:])
|
||||
|
||||
// append help to commands
|
||||
|
12
command.go
12
command.go
@ -9,12 +9,12 @@ type Command struct {
|
||||
Flags []Flag
|
||||
}
|
||||
|
||||
func (command Command) Run(c *Context) {
|
||||
set := flagSet(command.Flags)
|
||||
set.Parse(c.Args()[1:])
|
||||
command.Action(NewContext(c.App, set, c.globalSet))
|
||||
func (c Command) Run(ctx *Context) {
|
||||
set := flagSet(c.Name, c.Flags)
|
||||
set.Parse(ctx.Args()[1:])
|
||||
c.Action(NewContext(ctx.App, set, ctx.globalSet))
|
||||
}
|
||||
|
||||
func (command Command) HasName(name string) bool {
|
||||
return command.Name == name || command.ShortName == name
|
||||
func (c Command) HasName(name string) bool {
|
||||
return c.Name == name || c.ShortName == name
|
||||
}
|
||||
|
4
flag.go
4
flag.go
@ -8,8 +8,8 @@ type Flag interface {
|
||||
Apply(*flag.FlagSet)
|
||||
}
|
||||
|
||||
func flagSet(flags []Flag) *flag.FlagSet {
|
||||
set := flag.NewFlagSet("cli", flag.ExitOnError)
|
||||
func flagSet(name string, flags []Flag) *flag.FlagSet {
|
||||
set := flag.NewFlagSet(name, flag.ExitOnError)
|
||||
for _, f := range flags {
|
||||
f.Apply(set)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user