diff --git a/command/command_test.go b/command/command_test.go new file mode 100644 index 000000000..7574d663d --- /dev/null +++ b/command/command_test.go @@ -0,0 +1,13 @@ +package command + +import ( + "testing" + + "github.com/mitchellh/cli" +) + +func testMeta(t *testing.T) Meta { + return Meta{ + Ui: new(cli.MockUi), + } +} diff --git a/command/push.go b/command/push.go new file mode 100644 index 000000000..d50d549d1 --- /dev/null +++ b/command/push.go @@ -0,0 +1,55 @@ +package command + +import ( + "flag" + "fmt" + "strings" + + "github.com/mitchellh/packer/packer" +) + +type PushCommand struct { + Meta +} + +func (c *PushCommand) Run(args []string) int { + f := flag.NewFlagSet("push", flag.ContinueOnError) + f.Usage = func() { c.Ui.Error(c.Help()) } + if err := f.Parse(args); err != nil { + return 1 + } + + args = f.Args() + if len(args) != 1 { + f.Usage() + return 1 + } + + // Read the template + tpl, err := packer.ParseTemplateFile(args[0], nil) + if err != nil { + c.Ui.Error(fmt.Sprintf("Failed to parse template: %s", err)) + return 1 + } + + // TODO: validate the template + println(tpl.Push.Name) + + return 0 +} + +func (*PushCommand) Help() string { + helpText := ` +Usage: packer push [options] TEMPLATE + + Push the template and the files it needs to a Packer build service. + This will not initiate any builds, it will only update the templates + used for builds. +` + + return strings.TrimSpace(helpText) +} + +func (*PushCommand) Synopsis() string { + return "push template files to a Packer build service" +} diff --git a/command/push_test.go b/command/push_test.go new file mode 100644 index 000000000..b7e1f800a --- /dev/null +++ b/command/push_test.go @@ -0,0 +1,21 @@ +package command + +import ( + "testing" +) + +func TestPush_noArgs(t *testing.T) { + c := &PushCommand{Meta: testMeta(t)} + code := c.Run(nil) + if code != 1 { + t.Fatalf("bad: %#v", code) + } +} + +func TestPush_multiArgs(t *testing.T) { + c := &PushCommand{Meta: testMeta(t)} + code := c.Run([]string{"one", "two"}) + if code != 1 { + t.Fatalf("bad: %#v", code) + } +}