Commit 1ee2b014 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: remove Ui/Cache from CoreConfig

parent 1d3a4d6a
......@@ -149,7 +149,7 @@ func (c BuildCommand) Run(args []string) int {
name := b.Name()
log.Printf("Starting build run: %s", name)
ui := buildUis[name]
runArtifacts, err := b.Run(ui, c.CoreConfig.Cache)
runArtifacts, err := b.Run(ui, c.Cache)
if err != nil {
ui.Error(fmt.Sprintf("Build '%s' errored: %s", name, err))
......
......@@ -26,6 +26,7 @@ const (
// Packer command inherits.
type Meta struct {
CoreConfig *packer.CoreConfig
Cache packer.Cache
Ui packer.Ui
// These are set by command-line flags
......
......@@ -6,62 +6,53 @@ import (
"github.com/mitchellh/cli"
"github.com/mitchellh/packer/command"
"github.com/mitchellh/packer/packer"
)
// Commands is the mapping of all the available Terraform commands.
var Commands map[string]cli.CommandFactory
// Ui is the cli.Ui used for communicating to the outside world.
var Ui cli.Ui
// CommandMeta is the Meta to use for the commands. This must be written
// before the CLI is started.
var CommandMeta *command.Meta
const ErrorPrefix = "e:"
const OutputPrefix = "o:"
func init() {
meta := command.Meta{
CoreConfig: &CoreConfig,
Ui: &packer.BasicUi{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stdout,
},
}
Commands = map[string]cli.CommandFactory{
"build": func() (cli.Command, error) {
return &command.BuildCommand{
Meta: meta,
Meta: *CommandMeta,
}, nil
},
"fix": func() (cli.Command, error) {
return &command.FixCommand{
Meta: meta,
Meta: *CommandMeta,
}, nil
},
"inspect": func() (cli.Command, error) {
return &command.InspectCommand{
Meta: meta,
Meta: *CommandMeta,
}, nil
},
"push": func() (cli.Command, error) {
return &command.PushCommand{
Meta: meta,
Meta: *CommandMeta,
}, nil
},
"validate": func() (cli.Command, error) {
return &command.ValidateCommand{
Meta: meta,
Meta: *CommandMeta,
}, nil
},
"version": func() (cli.Command, error) {
return &command.VersionCommand{
Meta: meta,
Meta: *CommandMeta,
Revision: GitCommit,
Version: Version,
VersionPrerelease: VersionPrerelease,
......
......@@ -13,9 +13,6 @@ import (
"github.com/mitchellh/packer/packer/plugin"
)
// CoreConfig is the global CoreConfig we use to initialize the CLI.
var CoreConfig packer.CoreConfig
type config struct {
DisableCheckpoint bool `json:"disable_checkpoint"`
DisableCheckpointSignature bool `json:"disable_checkpoint_signature"`
......
......@@ -12,6 +12,7 @@ import (
"sync"
"github.com/mitchellh/cli"
"github.com/mitchellh/packer/command"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer/plugin"
"github.com/mitchellh/panicwrap"
......@@ -139,14 +140,14 @@ func wrappedMain() int {
defer plugin.CleanupClients()
// Create the environment configuration
CoreConfig.Cache = cache
CoreConfig.Components.Builder = config.LoadBuilder
CoreConfig.Components.Hook = config.LoadHook
CoreConfig.Components.PostProcessor = config.LoadPostProcessor
CoreConfig.Components.Provisioner = config.LoadProvisioner
// Setup the UI if we're being machine-readable
var ui packer.Ui = &packer.BasicUi{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stdout,
}
if machineReadable {
CoreConfig.Ui = &packer.MachineReadableUi{
ui = &packer.MachineReadableUi{
Writer: os.Stdout,
}
......@@ -158,6 +159,20 @@ func wrappedMain() int {
}
}
// Create the CLI meta
CommandMeta = &command.Meta{
CoreConfig: &packer.CoreConfig{
Components: packer.ComponentFinder{
Builder: config.LoadBuilder,
Hook: config.LoadHook,
PostProcessor: config.LoadPostProcessor,
Provisioner: config.LoadProvisioner,
},
},
Cache: cache,
Ui: ui,
}
//setupSignalHandlers(env)
cli := &cli.CLI{
......
......@@ -2,7 +2,6 @@ package packer
import (
"fmt"
"os"
"sort"
"github.com/hashicorp/go-multierror"
......@@ -13,9 +12,7 @@ import (
// Core is the main executor of Packer. If Packer is being used as a
// library, this is the struct you'll want to instantiate to get anything done.
type Core struct {
cache Cache
components ComponentFinder
ui Ui
template *template.Template
variables map[string]string
builds map[string]*template.Builder
......@@ -24,9 +21,7 @@ type Core struct {
// CoreConfig is the structure for initializing a new Core. Once a CoreConfig
// is used to initialize a Core, it shouldn't be re-used or modified again.
type CoreConfig struct {
Cache Cache
Components ComponentFinder
Ui Ui
Template *template.Template
Variables map[string]string
}
......@@ -55,14 +50,6 @@ type ComponentFinder struct {
// NewCore creates a new Core.
func NewCore(c *CoreConfig) (*Core, error) {
if c.Ui == nil {
c.Ui = &BasicUi{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stdout,
}
}
// Go through and interpolate all the build names. We shuld be able
// to do this at this point with the variables.
builds := make(map[string]*template.Builder)
......@@ -80,9 +67,7 @@ func NewCore(c *CoreConfig) (*Core, error) {
}
return &Core{
cache: c.Cache,
components: c.Components,
ui: c.Ui,
template: c.Template,
variables: c.Variables,
builds: builds,
......
......@@ -3,7 +3,6 @@ package packer
import (
"bytes"
"io/ioutil"
"os"
"testing"
)
......@@ -20,9 +19,7 @@ func TestCoreConfig(t *testing.T) *CoreConfig {
}
return &CoreConfig{
Cache: &FileCache{CacheDir: os.TempDir()},
Components: components,
Ui: TestUi(t),
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment