Skip to content
Myr

added pre and post run hooks.

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 9cf0f37 · Browse files · 1 file+17 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+17 added−1 removed

  • other:+17 added−1 removed

1 file+17 added−1 removed

modified:command.go+17 added-1 removed
57 unmodified lines
58 lflags *flag.FlagSet59 // Run runs the command.60 // The args are the arguments after the command name.61 Run func(cmd *Command, args []string)62 // PreRun runs the command after the flags are parsed and before run.63 // The args are the arguments after the command name.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 // Commands is the list of commands supported by this program.69 commands []*Command70 // Parent Command for this command71 parent *Command
381 unmodified lines
453 }454455 c.preRun()456 argWoFlags := c.Flags().Args()457458 if c.PreRun != nil {459 c.PreRun(c, argWoFlags)460 }461462 c.Run(c, argWoFlags)463464 if c.PostRun != nil {465 c.PostRun(c, argWoFlags)466 }467468 return nil469}470471func (c *Command) preRun() {
485 unmodified lines
957 c.Flags().VisitAll(addtolocal)958 c.PersistentFlags().VisitAll(addtolocal)959 }960 rmerge = func(x *Command) {945 if ! x.HasParent() {961 if !x.HasParent() {962 flag.CommandLine.VisitAll(func(f *flag.Flag) {963 if x.PersistentFlags().Lookup(f.Name) == nil {964 x.PersistentFlags().AddFlag(f)965 }
16 unmodified lines