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