Commit bd843cfc authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

command/build: -debug flag enables debug mode

parent 6c718bc3
...@@ -20,11 +20,13 @@ func (Command) Help() string { ...@@ -20,11 +20,13 @@ func (Command) Help() string {
} }
func (c Command) Run(env packer.Environment, args []string) int { func (c Command) Run(env packer.Environment, args []string) int {
var cfgDebug bool
var cfgExcept []string var cfgExcept []string
var cfgOnly []string var cfgOnly []string
cmdFlags := flag.NewFlagSet("build", flag.ContinueOnError) cmdFlags := flag.NewFlagSet("build", flag.ContinueOnError)
cmdFlags.Usage = func() { env.Ui().Say(c.Help()) } 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)(&cfgExcept), "except", "build all builds except these")
cmdFlags.Var((*stringSliceValue)(&cfgOnly), "only", "only build the given builds by name") cmdFlags.Var((*stringSliceValue)(&cfgOnly), "only", "only build the given builds by name")
if err := cmdFlags.Parse(args); err != nil { if err := cmdFlags.Parse(args); err != nil {
...@@ -141,9 +143,12 @@ func (c Command) Run(env packer.Environment, args []string) int { ...@@ -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 // Add a newline between the color output and the actual output
env.Ui().Say("") 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 { for _, b := range builds {
log.Printf("Preparing build: %s", b.Name()) log.Printf("Preparing build: %s", b.Name())
b.SetDebug(cfgDebug)
err := b.Prepare() err := b.Prepare()
if err != nil { if err != nil {
env.Ui().Error(err.Error()) env.Ui().Error(err.Error())
...@@ -173,6 +178,11 @@ func (c Command) Run(env packer.Environment, args []string) int { ...@@ -173,6 +178,11 @@ func (c Command) Run(env packer.Environment, args []string) int {
ui.Say("Build finished.") ui.Say("Build finished.")
} }
}(b) }(b)
if cfgDebug {
log.Printf("Debug enabled, so waiting for build to finish: %s", b.Name())
wg.Wait()
}
} }
// Handle signals // Handle signals
......
...@@ -8,6 +8,7 @@ Usage: packer build TEMPLATE ...@@ -8,6 +8,7 @@ Usage: packer build TEMPLATE
Options: Options:
-debug Debug mode enabled for builds
-except=foo,bar,baz Build all builds other than these -except=foo,bar,baz Build all builds other than these
-only=foo,bar,baz Only build the given builds by name -only=foo,bar,baz Only build the given builds by name
` `
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment