diff --git a/command/fix/command.go b/command/fix/command.go index 4a50e213d..cfb34f626 100644 --- a/command/fix/command.go +++ b/command/fix/command.go @@ -1,6 +1,7 @@ package fix import ( + "bytes" "encoding/json" "flag" "fmt" @@ -47,6 +48,32 @@ func (c Command) Run(env packer.Environment, args []string) int { // Close the file since we're done with that tplF.Close() + // Run the template through the various fixers + fixers := []Fixer{Fixers["iso-md5"]} + input := templateData + for _, fixer := range fixers { + var err error + input, err = fixer.Fix(input) + if err != nil { + env.Ui().Error(fmt.Sprintf("Error fixing: %s", err)) + return 1 + } + } + + var output bytes.Buffer + encoder := json.NewEncoder(&output) + if err := encoder.Encode(input); err != nil { + env.Ui().Error(fmt.Sprintf("Error encoding: %s", err)) + return 1 + } + + var indented bytes.Buffer + if err := json.Indent(&indented, output.Bytes(), "", " "); err != nil { + env.Ui().Error(fmt.Sprintf("Error encoding: %s", err)) + return 1 + } + + env.Ui().Say(indented.String()) return 0 } diff --git a/command/fix/help.go b/command/fix/help.go index aa46218dc..94b5c6a11 100644 --- a/command/fix/help.go +++ b/command/fix/help.go @@ -9,7 +9,8 @@ Usage: packer fix [options] TEMPLATE If the template cannot be fixed due to an error, the command will exit with a non-zero exit status. Error messages will appear on standard error. -Options: +Fixes that are run: + + iso-md5 Replaces "iso_md5" in builders with newer "iso_checksum" - -verbose Output each fix to standard error `