packer-cn/packer.go

49 lines
1.1 KiB
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"
"io/ioutil"
"log"
2013-03-25 19:29:26 -04:00
"os"
)
2013-03-23 21:40:26 -04:00
2013-03-23 02:00:23 -04:00
func main() {
if os.Getenv("PACKER_LOG") == "" {
// If we don't have logging explicitly enabled, then disable it
log.SetOutput(ioutil.Discard)
} else {
// Logging is enabled, make sure it goes to stderr
log.SetOutput(os.Stderr)
}
defer plugin.CleanupClients()
2013-05-08 21:13:15 -04:00
config, err := parseConfig(defaultConfig)
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading global Packer configuration: \n\n%s\n", err)
os.Exit(1)
}
envConfig := packer.DefaultEnvironmentConfig()
2013-05-08 21:13:15 -04:00
envConfig.Commands = config.CommandNames()
envConfig.CommandFunc = config.LoadCommand
env, err := packer.NewEnvironment(envConfig)
if err != nil {
fmt.Fprintf(os.Stderr, "Packer initialization error: \n\n%s\n", err)
os.Exit(1)
}
exitCode, err := env.Cli(os.Args[1:])
if err != nil {
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
os.Exit(1)
}
plugin.CleanupClients()
2013-05-08 02:09:34 -04:00
os.Exit(exitCode)
2013-03-23 02:00:23 -04:00
}