From bd843cfc1653c30481adc79b1f3e55c883be5a8d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 14 Jun 2013 13:14:17 -0700 Subject: [PATCH] command/build: -debug flag enables debug mode --- command/build/command.go | 12 +++++++++++- command/build/help.go | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/command/build/command.go b/command/build/command.go index 84e14fc0d..adc1fc42c 100644 --- a/command/build/command.go +++ b/command/build/command.go @@ -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 diff --git a/command/build/help.go b/command/build/help.go index 559422d98..0b7a55809 100644 --- a/command/build/help.go +++ b/command/build/help.go @@ -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 `