From fa36cf82ee8c63252a210eca2920685e24907b4f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 27 Oct 2014 20:34:49 -0700 Subject: [PATCH] command: move all remaining commands --- command/{fix/command.go => fix.go} | 49 +++++++++++++++---- command/fix/command_test.go | 14 ------ command/fix/help.go | 22 --------- commands.go | 6 +++ {command/fix => fix}/fixer.go | 0 {command/fix => fix}/fixer_createtime.go | 0 {command/fix => fix}/fixer_createtime_test.go | 0 {command/fix => fix}/fixer_iso_md5.go | 0 {command/fix => fix}/fixer_iso_md5_test.go | 0 .../fix => fix}/fixer_pp_vagrant_override.go | 0 .../fixer_pp_vagrant_override_test.go | 0 .../fix => fix}/fixer_virtualbox_gaattach.go | 0 .../fixer_virtualbox_gaattach_test.go | 0 .../fix => fix}/fixer_virtualbox_rename.go | 0 .../fixer_virtualbox_rename_test.go | 0 {command/fix => fix}/fixer_vmware_rename.go | 0 .../fix => fix}/fixer_vmware_rename_test.go | 0 plugin/command-fix/main.go | 15 ------ plugin/command-fix/main_test.go | 1 - 19 files changed, 45 insertions(+), 62 deletions(-) rename command/{fix/command.go => fix.go} (55%) delete mode 100644 command/fix/command_test.go delete mode 100644 command/fix/help.go rename {command/fix => fix}/fixer.go (100%) rename {command/fix => fix}/fixer_createtime.go (100%) rename {command/fix => fix}/fixer_createtime_test.go (100%) rename {command/fix => fix}/fixer_iso_md5.go (100%) rename {command/fix => fix}/fixer_iso_md5_test.go (100%) rename {command/fix => fix}/fixer_pp_vagrant_override.go (100%) rename {command/fix => fix}/fixer_pp_vagrant_override_test.go (100%) rename {command/fix => fix}/fixer_virtualbox_gaattach.go (100%) rename {command/fix => fix}/fixer_virtualbox_gaattach_test.go (100%) rename {command/fix => fix}/fixer_virtualbox_rename.go (100%) rename {command/fix => fix}/fixer_virtualbox_rename_test.go (100%) rename {command/fix => fix}/fixer_vmware_rename.go (100%) rename {command/fix => fix}/fixer_vmware_rename_test.go (100%) delete mode 100644 plugin/command-fix/main.go delete mode 100644 plugin/command-fix/main_test.go diff --git a/command/fix/command.go b/command/fix.go similarity index 55% rename from command/fix/command.go rename to command/fix.go index c62d3676b..aac0b3916 100644 --- a/command/fix/command.go +++ b/command/fix.go @@ -1,23 +1,28 @@ -package fix +package command import ( "bytes" "encoding/json" "flag" "fmt" - "github.com/mitchellh/packer/packer" "log" "os" "strings" + + "github.com/mitchellh/packer/fix" ) -type Command byte - -func (Command) Help() string { - return strings.TrimSpace(helpString) +type FixCommand struct { + 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.Usage = func() { env.Ui().Say(c.Help()) } if err := cmdFlags.Parse(args); err != nil { @@ -50,9 +55,9 @@ func (c Command) Run(env packer.Environment, args []string) int { tplF.Close() input := templateData - for _, name := range FixerOrder { + for _, name := range fix.FixerOrder { var err error - fixer, ok := Fixers[name] + fixer, ok := fix.Fixers[name] if !ok { panic("fixer not found: " + name) } @@ -85,6 +90,30 @@ func (c Command) Run(env packer.Environment, args []string) int { 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" } diff --git a/command/fix/command_test.go b/command/fix/command_test.go deleted file mode 100644 index e6c0c59e4..000000000 --- a/command/fix/command_test.go +++ /dev/null @@ -1,14 +0,0 @@ -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") - } -} diff --git a/command/fix/help.go b/command/fix/help.go deleted file mode 100644 index 95c5f3e16..000000000 --- a/command/fix/help.go +++ /dev/null @@ -1,22 +0,0 @@ -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" - -` diff --git a/commands.go b/commands.go index 2b5179edd..8aa6314aa 100644 --- a/commands.go +++ b/commands.go @@ -38,6 +38,12 @@ func init() { }, nil }, + "fix": func() (cli.Command, error) { + return &command.FixCommand{ + Meta: meta, + }, nil + }, + "inspect": func() (cli.Command, error) { return &command.InspectCommand{ Meta: meta, diff --git a/command/fix/fixer.go b/fix/fixer.go similarity index 100% rename from command/fix/fixer.go rename to fix/fixer.go diff --git a/command/fix/fixer_createtime.go b/fix/fixer_createtime.go similarity index 100% rename from command/fix/fixer_createtime.go rename to fix/fixer_createtime.go diff --git a/command/fix/fixer_createtime_test.go b/fix/fixer_createtime_test.go similarity index 100% rename from command/fix/fixer_createtime_test.go rename to fix/fixer_createtime_test.go diff --git a/command/fix/fixer_iso_md5.go b/fix/fixer_iso_md5.go similarity index 100% rename from command/fix/fixer_iso_md5.go rename to fix/fixer_iso_md5.go diff --git a/command/fix/fixer_iso_md5_test.go b/fix/fixer_iso_md5_test.go similarity index 100% rename from command/fix/fixer_iso_md5_test.go rename to fix/fixer_iso_md5_test.go diff --git a/command/fix/fixer_pp_vagrant_override.go b/fix/fixer_pp_vagrant_override.go similarity index 100% rename from command/fix/fixer_pp_vagrant_override.go rename to fix/fixer_pp_vagrant_override.go diff --git a/command/fix/fixer_pp_vagrant_override_test.go b/fix/fixer_pp_vagrant_override_test.go similarity index 100% rename from command/fix/fixer_pp_vagrant_override_test.go rename to fix/fixer_pp_vagrant_override_test.go diff --git a/command/fix/fixer_virtualbox_gaattach.go b/fix/fixer_virtualbox_gaattach.go similarity index 100% rename from command/fix/fixer_virtualbox_gaattach.go rename to fix/fixer_virtualbox_gaattach.go diff --git a/command/fix/fixer_virtualbox_gaattach_test.go b/fix/fixer_virtualbox_gaattach_test.go similarity index 100% rename from command/fix/fixer_virtualbox_gaattach_test.go rename to fix/fixer_virtualbox_gaattach_test.go diff --git a/command/fix/fixer_virtualbox_rename.go b/fix/fixer_virtualbox_rename.go similarity index 100% rename from command/fix/fixer_virtualbox_rename.go rename to fix/fixer_virtualbox_rename.go diff --git a/command/fix/fixer_virtualbox_rename_test.go b/fix/fixer_virtualbox_rename_test.go similarity index 100% rename from command/fix/fixer_virtualbox_rename_test.go rename to fix/fixer_virtualbox_rename_test.go diff --git a/command/fix/fixer_vmware_rename.go b/fix/fixer_vmware_rename.go similarity index 100% rename from command/fix/fixer_vmware_rename.go rename to fix/fixer_vmware_rename.go diff --git a/command/fix/fixer_vmware_rename_test.go b/fix/fixer_vmware_rename_test.go similarity index 100% rename from command/fix/fixer_vmware_rename_test.go rename to fix/fixer_vmware_rename_test.go diff --git a/plugin/command-fix/main.go b/plugin/command-fix/main.go deleted file mode 100644 index 03677674d..000000000 --- a/plugin/command-fix/main.go +++ /dev/null @@ -1,15 +0,0 @@ -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() -} diff --git a/plugin/command-fix/main_test.go b/plugin/command-fix/main_test.go deleted file mode 100644 index 06ab7d0f9..000000000 --- a/plugin/command-fix/main_test.go +++ /dev/null @@ -1 +0,0 @@ -package main