command/fix: run the iso-md5 fixer

This commit is contained in:
Mitchell Hashimoto 2013-07-14 17:05:26 +09:00
parent ab2af979fd
commit 7fc30436d5
2 changed files with 30 additions and 2 deletions

View File

@ -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
}

View File

@ -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
`