CloseBackend is a wrapper for a RunE function that will close the Backend properly if it has been opened. This wrapper style is necessary because a Cobra PostE function does not run if RunE return an error.
(env *Env, runE func(cmd *cobra.Command, args []string) error)
| 113 | // if it has been opened. |
| 114 | // This wrapper style is necessary because a Cobra PostE function does not run if RunE return an error. |
| 115 | func CloseBackend(env *Env, runE func(cmd *cobra.Command, args []string) error) func(*cobra.Command, []string) error { |
| 116 | return func(cmd *cobra.Command, args []string) error { |
| 117 | errRun := runE(cmd, args) |
| 118 | |
| 119 | if env.Backend == nil { |
| 120 | return nil |
| 121 | } |
| 122 | err := env.Backend.Close() |
| 123 | env.Backend = nil |
| 124 | |
| 125 | // prioritize the RunE error |
| 126 | if errRun != nil { |
| 127 | return errRun |
| 128 | } |
| 129 | return err |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | func CacheBuildProgressBar(env *Env, events chan cache.BuildEvent) error { |
| 134 | var progress *mpb.Progress |
no test coverage detected