findChildCmd returns the subcommand with matching name or alias.
(name string)
| 102 | |
| 103 | // findChildCmd returns the subcommand with matching name or alias. |
| 104 | func (c *Cmd) findChildCmd(name string) *Cmd { |
| 105 | // find perfect matches first |
| 106 | if cmd, ok := c.children[name]; ok { |
| 107 | return cmd |
| 108 | } |
| 109 | |
| 110 | // find alias matching the name |
| 111 | for _, cmd := range c.children { |
| 112 | for _, alias := range cmd.Aliases { |
| 113 | if alias == name { |
| 114 | return cmd |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | return nil |
| 120 | } |
| 121 | |
| 122 | // FindCmd finds the matching Cmd for args. |
| 123 | // It returns the Cmd and the remaining args. |