mirror of
https://github.com/rwxrob/bonzai
synced 2024-11-12 07:10:26 +00:00
Fix and close #64, broken aliases
This commit is contained in:
parent
b0983d80a7
commit
fa90cf0850
15
z/cmd.go
15
z/cmd.go
@ -45,7 +45,7 @@ type Cmd struct {
|
||||
MaxParm int `json:"-"` // maximum number of params required
|
||||
ReqConf bool `json:"-"` // requires Z.Conf be assigned
|
||||
|
||||
_aliases map[string]*Cmd // see cacheAliases called from Run
|
||||
_aliases map[string]*Cmd // see cacheAliases called from Run->Seek->Resolve
|
||||
_sections map[string]string // see cacheSections called from Run
|
||||
}
|
||||
|
||||
@ -167,7 +167,6 @@ func (x *Cmd) cacheSections() {
|
||||
func (x *Cmd) Run() {
|
||||
defer TrapPanic()
|
||||
|
||||
x.cacheAliases()
|
||||
x.cacheSections()
|
||||
|
||||
// resolve Z.Aliases (if completion didn't replace them)
|
||||
@ -183,6 +182,7 @@ func (x *Cmd) Run() {
|
||||
|
||||
// bash completion context
|
||||
line := os.Getenv("COMP_LINE")
|
||||
|
||||
if line != "" {
|
||||
var list []string
|
||||
lineargs := ArgsFrom(line)
|
||||
@ -207,6 +207,7 @@ func (x *Cmd) Run() {
|
||||
|
||||
// seek should never fail to return something, but ...
|
||||
cmd, args := x.Seek(os.Args[1:])
|
||||
|
||||
if cmd == nil {
|
||||
ExitError(x.UsageError())
|
||||
}
|
||||
@ -290,16 +291,24 @@ func (x *Cmd) Add(name string, aliases ...string) *Cmd {
|
||||
return c
|
||||
}
|
||||
|
||||
// Resolve looks up a given Command by name or name from Aliases.
|
||||
// Resolve looks up a given Command by name or alias from Aliases
|
||||
// (caching a lookup map of aliases in the process).
|
||||
func (x *Cmd) Resolve(name string) *Cmd {
|
||||
|
||||
if x.Commands == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, c := range x.Commands {
|
||||
if name == c.Name {
|
||||
return c
|
||||
}
|
||||
}
|
||||
|
||||
if x._aliases == nil {
|
||||
x.cacheAliases()
|
||||
}
|
||||
|
||||
if c, has := x._aliases[name]; has {
|
||||
return c
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user