Skip to content
Myr

Add ability to cast a command to a commander

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by spf13 · committed by spf13 · parent 88e482c · Browse files · 1 file+23 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+23 added−0 removed

  • other:+23 added−0 removed

1 file+23 added−0 removed

modified:command.go+23 added
50 unmodified lines
51 cmdr *Commander52 flagErrorBuf *bytes.Buffer53}5455// Convert a Command into an (initialized) Commander56func (cmd *Command) ToCommander() (c *Commander) {57 c = NewCommander()58 c.name = cmd.Name()59 c.Use = cmd.Use60 c.Short = cmd.Short61 c.Long = cmd.Long62 c.flags = cmd.flags63 c.pflags = cmd.pflags64 c.Run = cmd.Run65 c.commands = cmd.commands66 c.resetChildrensParents()67 c.flagErrorBuf = cmd.flagErrorBuf68 return69}7071// Really only used when casting a command to a commander72func (c *Command) resetChildrensParents() {73 for _, x := range c.commands {74 x.parent = c75 }76}7778// find the target command given the args and command tree79// Meant to be run on the highest node. Only searches down.80func (c *Command) Find(args []string) (cmd *Command, a []string, err error) {81 if c == nil {
328 unmodified lines