command: push command

This commit is contained in:
Mitchell Hashimoto 2014-10-28 15:09:22 -07:00
parent 835cadeee2
commit 6fb375c89e
3 changed files with 89 additions and 0 deletions

13
command/command_test.go Normal file
View File

@ -0,0 +1,13 @@
package command
import (
"testing"
"github.com/mitchellh/cli"
)
func testMeta(t *testing.T) Meta {
return Meta{
Ui: new(cli.MockUi),
}
}

55
command/push.go Normal file
View File

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

21
command/push_test.go Normal file
View File

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