|
|
|
|
@ -34,34 +34,30 @@ type Command interface {
|
|
|
|
|
// if you're building a custom Packer binary, you could instantiate multiple
|
|
|
|
|
// environments and run them in parallel.
|
|
|
|
|
type Environment struct {
|
|
|
|
|
builder map[string]Builder
|
|
|
|
|
builderFactory BuilderFactory
|
|
|
|
|
command map[string]Command
|
|
|
|
|
ui Ui
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This struct configures new environments.
|
|
|
|
|
type EnvironmentConfig struct {
|
|
|
|
|
builder map[string]Builder
|
|
|
|
|
command map[string]Command
|
|
|
|
|
ui Ui
|
|
|
|
|
BuilderFactory BuilderFactory
|
|
|
|
|
Command map[string]Command
|
|
|
|
|
Ui Ui
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This creates a new environment
|
|
|
|
|
func NewEnvironment(config *EnvironmentConfig) *Environment {
|
|
|
|
|
env := &Environment{}
|
|
|
|
|
env.builder = make(map[string]Builder)
|
|
|
|
|
env.command = make(map[string]Command)
|
|
|
|
|
|
|
|
|
|
if config != nil {
|
|
|
|
|
for k, v := range config.builder {
|
|
|
|
|
env.builder[k] = v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for k, v := range config.command {
|
|
|
|
|
for k, v := range config.Command {
|
|
|
|
|
env.command[k] = v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
env.ui = config.ui
|
|
|
|
|
env.builderFactory = config.BuilderFactory
|
|
|
|
|
env.ui = config.Ui
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, ok := env.command["build"]; !ok {
|
|
|
|
|
@ -79,12 +75,6 @@ func NewEnvironment(config *EnvironmentConfig) *Environment {
|
|
|
|
|
return env
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Looks up a builder with the given name and returns an interface
|
|
|
|
|
// to access it.
|
|
|
|
|
func (e *Environment) Builder(name string) Builder {
|
|
|
|
|
return e.builder[name]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Executes a command as if it was typed on the command-line interface.
|
|
|
|
|
// The return value is the exit code of the command.
|
|
|
|
|
func (e *Environment) Cli(args []string) int {
|
|
|
|
|
|