41 lines
529 B
Go
41 lines
529 B
Go
package cmd
|
|
|
|
type Set []*Command
|
|
|
|
func NewSet() Set {
|
|
return Set{}
|
|
}
|
|
|
|
func (s *Set) Add(c *Command) {
|
|
*s = append(*s, c)
|
|
}
|
|
|
|
func (s Set) Get(name string) (*Command, bool) {
|
|
for _, c := range s {
|
|
if c.name == name {
|
|
return c, true
|
|
}
|
|
|
|
for _, alias := range c.aliases {
|
|
if alias == name {
|
|
return c, true
|
|
}
|
|
}
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
func (s Set) MaxNameWidth() int {
|
|
max := 0
|
|
for _, f := range s {
|
|
if w := len(f.name); w > max {
|
|
max = w
|
|
}
|
|
}
|
|
return max
|
|
}
|
|
|
|
func (s Set) Len() int {
|
|
return len(s)
|
|
}
|