command/build: -debug flag enables debug mode

This commit is contained in:
Mitchell Hashimoto 2013-06-14 13:14:17 -07:00
parent 6c718bc3be
commit bd843cfc16
2 changed files with 12 additions and 1 deletions

View File

@ -20,11 +20,13 @@ func (Command) Help() string {
}
func (c Command) Run(env packer.Environment, args []string) int {
var cfgDebug bool
var cfgExcept []string
var cfgOnly []string
cmdFlags := flag.NewFlagSet("build", flag.ContinueOnError)
cmdFlags.Usage = func() { env.Ui().Say(c.Help()) }
cmdFlags.BoolVar(&cfgDebug, "debug", false, "debug mode for builds")
cmdFlags.Var((*stringSliceValue)(&cfgExcept), "except", "build all builds except these")
cmdFlags.Var((*stringSliceValue)(&cfgOnly), "only", "only build the given builds by name")
if err := cmdFlags.Parse(args); err != nil {
@ -141,9 +143,12 @@ func (c Command) Run(env packer.Environment, args []string) int {
// Add a newline between the color output and the actual output
env.Ui().Say("")
// Prepare all the builds
log.Printf("Build debug mode: %v", cfgDebug)
// Set the debug mode and prepare all the builds
for _, b := range builds {
log.Printf("Preparing build: %s", b.Name())
b.SetDebug(cfgDebug)
err := b.Prepare()
if err != nil {
env.Ui().Error(err.Error())
@ -173,6 +178,11 @@ func (c Command) Run(env packer.Environment, args []string) int {
ui.Say("Build finished.")
}
}(b)
if cfgDebug {
log.Printf("Debug enabled, so waiting for build to finish: %s", b.Name())
wg.Wait()
}
}
// Handle signals

View File

@ -8,6 +8,7 @@ Usage: packer build TEMPLATE
Options:
-debug Debug mode enabled for builds
-except=foo,bar,baz Build all builds other than these
-only=foo,bar,baz Only build the given builds by name
`