Commit fa36cf82 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

command: move all remaining commands

parent 8054e66d
package fix package command
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"github.com/mitchellh/packer/packer"
"log" "log"
"os" "os"
"strings" "strings"
)
type Command byte "github.com/mitchellh/packer/fix"
)
func (Command) Help() string { type FixCommand struct {
return strings.TrimSpace(helpString) Meta
} }
func (c Command) Run(env packer.Environment, args []string) int { func (c *FixCommand) Run(args []string) int {
env, err := c.Meta.Environment()
if err != nil {
c.Ui.Error(fmt.Sprintf("Error initializing environment: %s", err))
return 1
}
cmdFlags := flag.NewFlagSet("fix", flag.ContinueOnError) cmdFlags := flag.NewFlagSet("fix", flag.ContinueOnError)
cmdFlags.Usage = func() { env.Ui().Say(c.Help()) } cmdFlags.Usage = func() { env.Ui().Say(c.Help()) }
if err := cmdFlags.Parse(args); err != nil { if err := cmdFlags.Parse(args); err != nil {
...@@ -50,9 +55,9 @@ func (c Command) Run(env packer.Environment, args []string) int { ...@@ -50,9 +55,9 @@ func (c Command) Run(env packer.Environment, args []string) int {
tplF.Close() tplF.Close()
input := templateData input := templateData
for _, name := range FixerOrder { for _, name := range fix.FixerOrder {
var err error var err error
fixer, ok := Fixers[name] fixer, ok := fix.Fixers[name]
if !ok { if !ok {
panic("fixer not found: " + name) panic("fixer not found: " + name)
} }
...@@ -85,6 +90,30 @@ func (c Command) Run(env packer.Environment, args []string) int { ...@@ -85,6 +90,30 @@ func (c Command) Run(env packer.Environment, args []string) int {
return 0 return 0
} }
func (c Command) Synopsis() string { func (*FixCommand) Help() string {
helpText := `
Usage: packer fix [options] TEMPLATE
Reads the JSON template and attempts to fix known backwards
incompatibilities. The fixed template will be outputted to standard out.
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.
Fixes that are run:
iso-md5 Replaces "iso_md5" in builders with newer "iso_checksum"
createtime Replaces ".CreateTime" in builder configs with "{{timestamp}}"
virtualbox-gaattach Updates VirtualBox builders using "guest_additions_attach"
to use "guest_additions_mode"
pp-vagrant-override Replaces old-style provider overrides for the Vagrant
post-processor to new-style as of Packer 0.5.0.
virtualbox-rename Updates "virtualbox" builders to "virtualbox-iso"
`
return strings.TrimSpace(helpText)
}
func (c *FixCommand) Synopsis() string {
return "fixes templates from old versions of packer" return "fixes templates from old versions of packer"
} }
package fix
import (
"github.com/mitchellh/packer/packer"
"testing"
)
func TestCommand_Impl(t *testing.T) {
var raw interface{}
raw = new(Command)
if _, ok := raw.(packer.Command); !ok {
t.Fatalf("must be a Command")
}
}
package fix
const helpString = `
Usage: packer fix [options] TEMPLATE
Reads the JSON template and attempts to fix known backwards
incompatibilities. The fixed template will be outputted to standard out.
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.
Fixes that are run:
iso-md5 Replaces "iso_md5" in builders with newer "iso_checksum"
createtime Replaces ".CreateTime" in builder configs with "{{timestamp}}"
virtualbox-gaattach Updates VirtualBox builders using "guest_additions_attach"
to use "guest_additions_mode"
pp-vagrant-override Replaces old-style provider overrides for the Vagrant
post-processor to new-style as of Packer 0.5.0.
virtualbox-rename Updates "virtualbox" builders to "virtualbox-iso"
`
...@@ -38,6 +38,12 @@ func init() { ...@@ -38,6 +38,12 @@ func init() {
}, nil }, nil
}, },
"fix": func() (cli.Command, error) {
return &command.FixCommand{
Meta: meta,
}, nil
},
"inspect": func() (cli.Command, error) { "inspect": func() (cli.Command, error) {
return &command.InspectCommand{ return &command.InspectCommand{
Meta: meta, Meta: meta,
......
package main
import (
"github.com/mitchellh/packer/command/fix"
"github.com/mitchellh/packer/packer/plugin"
)
func main() {
server, err := plugin.Server()
if err != nil {
panic(err)
}
server.RegisterCommand(new(fix.Command))
server.Serve()
}
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