Commit fefd2ae2 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Separate commands into other directories

parent f49c0cb3
package build
import "fmt"
import "github.com/mitchellh/packer/packer"
type Command byte
func (Command) Run(env *packer.Environment, arg []string) int {
fmt.Println("HI!")
return 0
}
func (Command) Synopsis() string {
return "build image(s) from tempate"
}
......@@ -3,12 +3,16 @@ package main
import (
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/command/build"
"fmt"
"os"
)
func main() {
env, err := packer.NewEnvironment(packer.DefaultEnvironmentConfig())
envConfig := packer.DefaultEnvironmentConfig()
envConfig.Command["build"] = new(build.Command)
env, err := packer.NewEnvironment(envConfig)
if err != nil {
fmt.Fprintf(os.Stderr, "Packer initialization error: \n\n%s\n", err)
os.Exit(1)
......
......@@ -34,6 +34,7 @@ type EnvironmentConfig struct {
func DefaultEnvironmentConfig() *EnvironmentConfig {
config := &EnvironmentConfig{}
config.BuilderFactory = new(NilBuilderFactory)
config.Command = make(map[string]Command)
config.Ui = &ReaderWriterUi{os.Stdin, os.Stdout}
return config
}
......
......@@ -40,6 +40,13 @@ func testEnvironment() *Environment {
return env
}
func TestEnvironment_DefaultConfig_Command(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
config := DefaultEnvironmentConfig()
assert.NotNil(config.Command, "default Command should not be nil")
}
func TestEnvironment_DefaultConfig_Ui(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
......
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