Eliminate needless level of closure indirection (#1085)
This was CR feedback from @swgillespie.
This commit is contained in:
parent
91c550f1e0
commit
be26db3ffa
3 changed files with 37 additions and 41 deletions
|
@ -23,24 +23,22 @@ func Destroy(u UpdateInfo, events chan<- Event, opts UpdateOptions) (ResourceCha
|
||||||
emitter := makeEventEmitter(events, u)
|
emitter := makeEventEmitter(events, u)
|
||||||
return update(ctx, planOptions{
|
return update(ctx, planOptions{
|
||||||
UpdateOptions: opts,
|
UpdateOptions: opts,
|
||||||
SourceFunc: newDestroySourceFunc(),
|
SourceFunc: newDestroySource,
|
||||||
Events: emitter,
|
Events: emitter,
|
||||||
Diag: newEventSink(emitter),
|
Diag: newEventSink(emitter),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDestroySourceFunc() planSourceFunc {
|
func newDestroySource(opts planOptions, proj *workspace.Project, pwd, main string,
|
||||||
return func(opts planOptions, proj *workspace.Project, pwd, main string,
|
target *deploy.Target, plugctx *plugin.Context) (deploy.Source, error) {
|
||||||
target *deploy.Target, plugctx *plugin.Context) (deploy.Source, error) {
|
// For destroy, we consult the manifest for the plugin versions/ required to destroy it.
|
||||||
// For destroy, we consult the manifest for the plugin versions/ required to destroy it.
|
if target != nil && target.Snapshot != nil {
|
||||||
if target != nil && target.Snapshot != nil {
|
if err := plugctx.Host.EnsurePlugins(target.Snapshot.Manifest.Plugins); err != nil {
|
||||||
if err := plugctx.Host.EnsurePlugins(target.Snapshot.Manifest.Plugins); err != nil {
|
return nil, err
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ func Preview(u UpdateInfo, events chan<- Event, opts UpdateOptions) error {
|
||||||
emitter := makeEventEmitter(events, u)
|
emitter := makeEventEmitter(events, u)
|
||||||
return preview(ctx, planOptions{
|
return preview(ctx, planOptions{
|
||||||
UpdateOptions: opts,
|
UpdateOptions: opts,
|
||||||
SourceFunc: newUpdateSourceFunc(),
|
SourceFunc: newUpdateSource,
|
||||||
Events: emitter,
|
Events: emitter,
|
||||||
Diag: newEventSink(emitter),
|
Diag: newEventSink(emitter),
|
||||||
})
|
})
|
||||||
|
|
|
@ -41,39 +41,37 @@ func Update(u UpdateInfo, events chan<- Event, opts UpdateOptions) (ResourceChan
|
||||||
emitter := makeEventEmitter(events, u)
|
emitter := makeEventEmitter(events, u)
|
||||||
return update(ctx, planOptions{
|
return update(ctx, planOptions{
|
||||||
UpdateOptions: opts,
|
UpdateOptions: opts,
|
||||||
SourceFunc: newUpdateSourceFunc(),
|
SourceFunc: newUpdateSource,
|
||||||
Events: emitter,
|
Events: emitter,
|
||||||
Diag: newEventSink(emitter),
|
Diag: newEventSink(emitter),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUpdateSourceFunc() planSourceFunc {
|
func newUpdateSource(opts planOptions, proj *workspace.Project, pwd, main string,
|
||||||
return func(opts planOptions, proj *workspace.Project, pwd, main string,
|
target *deploy.Target, plugctx *plugin.Context) (deploy.Source, error) {
|
||||||
target *deploy.Target, plugctx *plugin.Context) (deploy.Source, error) {
|
// Figure out which plugins to load by inspecting the program contents.
|
||||||
// Figure out which plugins to load by inspecting the program contents.
|
plugins, err := plugctx.Host.GetRequiredPlugins(plugin.ProgInfo{
|
||||||
plugins, err := plugctx.Host.GetRequiredPlugins(plugin.ProgInfo{
|
Proj: proj,
|
||||||
Proj: proj,
|
Pwd: pwd,
|
||||||
Pwd: pwd,
|
Program: main,
|
||||||
Program: main,
|
})
|
||||||
})
|
if err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
func update(info *planContext, opts planOptions) (ResourceChanges, error) {
|
||||||
|
|
Loading…
Reference in a new issue