LoadBackend is a pre-run function that load the repository and the Backend for use in a command When using this function you also need to use CloseBackend as a post-run
(env *Env)
| 59 | // LoadBackend is a pre-run function that load the repository and the Backend for use in a command |
| 60 | // When using this function you also need to use CloseBackend as a post-run |
| 61 | func LoadBackend(env *Env) func(*cobra.Command, []string) error { |
| 62 | return func(cmd *cobra.Command, args []string) error { |
| 63 | err := LoadRepo(env)(cmd, args) |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | var events chan cache.BuildEvent |
| 69 | env.Backend, events = cache.NewRepoCache(env.Repo) |
| 70 | |
| 71 | err = CacheBuildProgressBar(env, events) |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 | |
| 76 | cleaner := func(env *Env) interrupt.CleanerFunc { |
| 77 | return func() error { |
| 78 | if env.Backend != nil { |
| 79 | err := env.Backend.Close() |
| 80 | env.Backend = nil |
| 81 | return err |
| 82 | } |
| 83 | return nil |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // Cleanup properly on interrupt |
| 88 | interrupt.RegisterCleaner(cleaner(env)) |
| 89 | return nil |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // LoadBackendEnsureUser is the same as LoadBackend, but also ensure that the user has configured |
| 94 | // an identity. Use this pre-run function when an error after using the configured user won't |
no test coverage detected