Separate commands into other directories

This commit is contained in:
Mitchell Hashimoto 2013-04-21 19:04:35 -07:00
parent f49c0cb313
commit fefd2ae208
4 changed files with 28 additions and 1 deletions

15
command/build/command.go Normal file
View File

@ -0,0 +1,15 @@
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"
}

View File

@ -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)

View File

@ -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
}

View File

@ -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)