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) {
|
func (a *App) Run(arguments []string) {
|
||||||
// parse flags
|
// parse flags
|
||||||
set := flagSet(a.Flags)
|
set := flagSet(a.Name, a.Flags)
|
||||||
set.Parse(arguments[1:])
|
set.Parse(arguments[1:])
|
||||||
|
|
||||||
// append help to commands
|
// append help to commands
|
||||||
|
12
command.go
12
command.go
@ -9,12 +9,12 @@ type Command struct {
|
|||||||
Flags []Flag
|
Flags []Flag
|
||||||
}
|
}
|
||||||
|
|
||||||
func (command Command) Run(c *Context) {
|
func (c Command) Run(ctx *Context) {
|
||||||
set := flagSet(command.Flags)
|
set := flagSet(c.Name, c.Flags)
|
||||||
set.Parse(c.Args()[1:])
|
set.Parse(ctx.Args()[1:])
|
||||||
command.Action(NewContext(c.App, set, c.globalSet))
|
c.Action(NewContext(ctx.App, set, ctx.globalSet))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (command Command) HasName(name string) bool {
|
func (c Command) HasName(name string) bool {
|
||||||
return command.Name == name || command.ShortName == name
|
return c.Name == name || c.ShortName == name
|
||||||
}
|
}
|
||||||
|
4
flag.go
4
flag.go
@ -8,8 +8,8 @@ type Flag interface {
|
|||||||
Apply(*flag.FlagSet)
|
Apply(*flag.FlagSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
func flagSet(flags []Flag) *flag.FlagSet {
|
func flagSet(name string, flags []Flag) *flag.FlagSet {
|
||||||
set := flag.NewFlagSet("cli", flag.ExitOnError)
|
set := flag.NewFlagSet(name, flag.ExitOnError)
|
||||||
for _, f := range flags {
|
for _, f := range flags {
|
||||||
f.Apply(set)
|
f.Apply(set)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user