Skip to content
Myr

Merge pull request #134 from apriendeau/master

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

#67 creates RunE functions to allow for errors to populate to the top

authored by Eric Paris · committed by Eric Paris · parents 99d2c51, 9174039 · Browse files · 1 file+39 added−6 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+39 added−6 removed

  • other:+39 added−6 removed

1 file+39 added−6 removed

modified:command.go+39 added-6 removed
64 unmodified lines
65 // * PersistentPostRun()66 // All functions get the same args, the arguments after the command name67 // PersistentPreRun: children of this command will inherit and execute68 PersistentPreRun func(cmd *Command, args []string)69 // PersistentPreRunE: PersistentPreRun but returns an error70 PersistentPreRunE func(cmd *Command, args []string) error71 // PreRun: children of this command will not inherit.72 PreRun func(cmd *Command, args []string)73 // PreRunE: PreRun but returns an error74 PreRunE func(cmd *Command, args []string) error75 // Run: Typically the actual work function. Most commands will only implement this76 Run func(cmd *Command, args []string)77 // RunE: Run but returns an error78 RunE func(cmd *Command, args []string) error79 // PostRun: run after the Run command.80 PostRun func(cmd *Command, args []string)81 // PostRunE: PostRun but returns an error82 PostRunE func(cmd *Command, args []string) error83 // PersistentPostRun: children of this command will inherit and execute after PostRun84 PersistentPostRun func(cmd *Command, args []string)85 // PersistentPostRunE: PersistentPostRun but returns an error86 PersistentPostRunE func(cmd *Command, args []string) error87 // Commands is the list of commands supported by this program.88 commands []*Command89 // Parent Command for this command90 parent *Command
392 unmodified lines
483 c.preRun()484 argWoFlags := c.Flags().Args()485486 for p := c; p != nil; p = p.Parent() {477 if p.PersistentPreRun != nil {487 if p.PersistentPreRunE != nil {488 if err := p.PersistentPostRunE(c, argWoFlags); err != nil {489 return err490 }491 break492 } else if p.PersistentPreRun != nil {493 p.PersistentPreRun(c, argWoFlags)494 break495 }496 }482 if c.PreRun != nil {497 if c.PreRunE != nil {498 if err := c.PreRunE(c, argWoFlags); err != nil {499 return err500 }501 } else if c.PreRun != nil {502 c.PreRun(c, argWoFlags)503 }504505 if c.RunE != nil {506 if err := c.RunE(c, argWoFlags); err != nil {507 return err508 }509 } else {486 c.Run(c, argWoFlags)487488 if c.PostRun != nil {510 c.Run(c, argWoFlags)511 }512 if c.PostRunE != nil {513 if err := c.PostRunE(c, argWoFlags); err != nil {514 return err515 }516 } else if c.PostRun != nil {517 c.PostRun(c, argWoFlags)518 }519 for p := c; p != nil; p = p.Parent() {492 if p.PersistentPostRun != nil {520 if p.PersistentPostRunE != nil {521 if err := p.PersistentPostRunE(c, argWoFlags); err != nil {522 return err523 }524 break525 } else if p.PersistentPostRun != nil {526 p.PersistentPostRun(c, argWoFlags)527 break528 }529 }
550 unmodified lines