Eliminate needless level of closure indirection (#1085)

This was CR feedback from @swgillespie.
This commit is contained in:
Joe Duffy 2018-03-29 08:57:25 -07:00 committed by GitHub
parent 91c550f1e0
commit be26db3ffa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 41 deletions

View file

@ -23,14 +23,13 @@ func Destroy(u UpdateInfo, events chan<- Event, opts UpdateOptions) (ResourceCha
emitter := makeEventEmitter(events, u)
return update(ctx, planOptions{
UpdateOptions: opts,
SourceFunc: newDestroySourceFunc(),
SourceFunc: newDestroySource,
Events: emitter,
Diag: newEventSink(emitter),
})
}
func newDestroySourceFunc() planSourceFunc {
return func(opts planOptions, proj *workspace.Project, pwd, main string,
func newDestroySource(opts planOptions, proj *workspace.Project, pwd, main string,
target *deploy.Target, plugctx *plugin.Context) (deploy.Source, error) {
// For destroy, we consult the manifest for the plugin versions/ required to destroy it.
if target != nil && target.Snapshot != nil {
@ -42,5 +41,4 @@ func newDestroySourceFunc() planSourceFunc {
// Create a nil source. This simply returns "nothing" as the new state, which will cause the
// engine to destroy the entire existing state.
return deploy.NullSource, nil
}
}

View file

@ -29,7 +29,7 @@ func Preview(u UpdateInfo, events chan<- Event, opts UpdateOptions) error {
emitter := makeEventEmitter(events, u)
return preview(ctx, planOptions{
UpdateOptions: opts,
SourceFunc: newUpdateSourceFunc(),
SourceFunc: newUpdateSource,
Events: emitter,
Diag: newEventSink(emitter),
})

View file

@ -41,14 +41,13 @@ func Update(u UpdateInfo, events chan<- Event, opts UpdateOptions) (ResourceChan
emitter := makeEventEmitter(events, u)
return update(ctx, planOptions{
UpdateOptions: opts,
SourceFunc: newUpdateSourceFunc(),
SourceFunc: newUpdateSource,
Events: emitter,
Diag: newEventSink(emitter),
})
}
func newUpdateSourceFunc() planSourceFunc {
return func(opts planOptions, proj *workspace.Project, pwd, main string,
func newUpdateSource(opts planOptions, proj *workspace.Project, pwd, main string,
target *deploy.Target, plugctx *plugin.Context) (deploy.Source, error) {
// Figure out which plugins to load by inspecting the program contents.
plugins, err := plugctx.Host.GetRequiredPlugins(plugin.ProgInfo{
@ -73,7 +72,6 @@ func newUpdateSourceFunc() planSourceFunc {
Program: main,
Target: target,
}, opts.DryRun), nil
}
}
func update(info *planContext, opts planOptions) (ResourceChanges, error) {