Skip to content
Myr

added persistent pre/post commands.

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

authored by Alexander Thaller · committed by Eric Paris · parent 2df6402 · Browse files · 1 file+21 added−1 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+21 added−1 removed

  • other:+21 added−1 removed

1 file+21 added−1 removed

modified:command.go+21 added-1 removed
63 unmodified lines
64 PreRun func(cmd *Command, args []string)65 // PostRun runs the command after run.66 // The args are the arguments after the command name.67 PostRun func(cmd *Command, args []string)68 // PreRun which children of this command will inherit.69 PersistentPreRun func(cmd *Command, args []string)70 // PostRun which children of this command will inherit.71 PersistentPostRun func(cmd *Command, args []string)72 // Commands is the list of commands supported by this program.73 commands []*Command74 // Parent Command for this command75 parent *Command
382 unmodified lines
458459 c.preRun()460 argWoFlags := c.Flags().Args()461462 if c.PersistentPreRun != nil {463 c.PersistentPreRun(c, argWoFlags)464 }465 if c.PreRun != nil {466 c.PreRun(c, argWoFlags)467 }468
1 unmodified line
470471 if c.PostRun != nil {472 c.PostRun(c, argWoFlags)473 }474 if c.PersistentPostRun != nil {475 c.PersistentPostRun(c, argWoFlags)476 }477478 return nil479}480
73 unmodified lines
554 Use: "help [command]",555 Short: "Help about any command",556 Long: `Help provides help for any command in the application.557 Simply type ` + c.Name() + ` help [path to command] for full details.`,548 Run: c.HelpFunc(),558 Run: c.HelpFunc(),559 PersistentPreRun: func(cmd *Command, args []string) {},560 PersistentPostRun: func(cmd *Command, args []string) {},561 }562 }563 c.AddCommand(c.helpCommand)564}
31 unmodified lines
596 if nameLen > c.commandsMaxNameLen {597 c.commandsMaxNameLen = nameLen598 }599 c.commands = append(c.commands, x)600601 // Pass on peristent pre/post functions to children602 if x.PersistentPreRun == nil {603 x.PersistentPreRun = c.PersistentPreRun604 }605 if x.PersistentPostRun == nil {606 x.PersistentPostRun = c.PersistentPostRun607 }608 }609}610611// AddCommand removes one or more commands from a parent command.
390 unmodified lines