packer-cn/packer.go

41 lines
830 B
Go
Raw Normal View History

2013-03-23 02:00:23 -04:00
// This is the main package for the `packer` application.
package main
2013-03-25 19:29:26 -04:00
import (
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer/plugin"
"fmt"
2013-03-25 19:29:26 -04:00
"os"
"os/exec"
2013-03-25 19:29:26 -04:00
)
2013-03-23 21:40:26 -04:00
2013-03-23 02:00:23 -04:00
func main() {
2013-05-07 16:40:49 -04:00
commands := map[string]string {
"build": "packer-build",
}
commandKeys := make([]string, 0, len(commands))
for k, _ := range commands {
commandKeys = append(commandKeys, k)
}
envConfig := packer.DefaultEnvironmentConfig()
2013-05-07 16:40:49 -04:00
envConfig.Commands = commandKeys
envConfig.CommandFunc = func(n string) packer.Command {
2013-05-07 16:40:49 -04:00
commandBin, ok := commands[n]
if !ok {
return nil
}
return plugin.Command(exec.Command(commandBin))
}
env, err := packer.NewEnvironment(envConfig)
if err != nil {
fmt.Fprintf(os.Stderr, "Packer initialization error: \n\n%s\n", err)
os.Exit(1)
}
os.Exit(env.Cli(os.Args[1:]))
2013-03-23 02:00:23 -04:00
}