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,24 +23,22 @@ 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,
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 {
if err := plugctx.Host.EnsurePlugins(target.Snapshot.Manifest.Plugins); err != nil {
return nil, err
}
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 {
if err := plugctx.Host.EnsurePlugins(target.Snapshot.Manifest.Plugins); err != nil {
return nil, err
}
// 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
}
// 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,39 +41,37 @@ 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,
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{
Proj: proj,
Pwd: pwd,
Program: main,
})
if err != nil {
return nil, err
}
// Now ensure that we have loaded up any plugins that the program will need in advance.
if err = plugctx.Host.EnsurePlugins(plugins); err != nil {
return nil, err
}
// If that succeeded, create a new source that will perform interpretation of the compiled program.
// TODO[pulumi/pulumi#88]: we are passing `nil` as the arguments map; we need to allow a way to pass these.
return deploy.NewEvalSource(plugctx, &deploy.EvalRunInfo{
Proj: proj,
Pwd: pwd,
Program: main,
Target: target,
}, opts.DryRun), nil
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{
Proj: proj,
Pwd: pwd,
Program: main,
})
if err != nil {
return nil, err
}
// Now ensure that we have loaded up any plugins that the program will need in advance.
if err = plugctx.Host.EnsurePlugins(plugins); err != nil {
return nil, err
}
// If that succeeded, create a new source that will perform interpretation of the compiled program.
// TODO[pulumi/pulumi#88]: we are passing `nil` as the arguments map; we need to allow a way to pass these.
return deploy.NewEvalSource(plugctx, &deploy.EvalRunInfo{
Proj: proj,
Pwd: pwd,
Program: main,
Target: target,
}, opts.DryRun), nil
}
func update(info *planContext, opts planOptions) (ResourceChanges, error) {