From 344c741642c930da821694a0b0f94b59c08b4275 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Wed, 15 Apr 2015 12:53:57 -0700 Subject: [PATCH] command/push: allow specifying a -name param for push target --- command/push.go | 15 ++++++-- command/push_test.go | 36 +++++++++++++++++++ .../docs/command-line/push.html.markdown | 3 ++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/command/push.go b/command/push.go index 74915de3f..32edfb3ab 100644 --- a/command/push.go +++ b/command/push.go @@ -34,6 +34,7 @@ type pushUploadFn func( func (c *PushCommand) Run(args []string) int { var token string var message string + var name string var create bool f := flag.NewFlagSet("push", flag.ContinueOnError) @@ -41,6 +42,7 @@ func (c *PushCommand) Run(args []string) int { f.StringVar(&token, "token", "", "token") f.StringVar(&message, "m", "", "message") f.StringVar(&message, "message", "", "message") + f.StringVar(&name, "name", "", "name") f.BoolVar(&create, "create", false, "create (deprecated)") if err := f.Parse(args); err != nil { return 1 @@ -65,11 +67,17 @@ func (c *PushCommand) Run(args []string) int { return 1 } + // If we didn't pass name from the CLI, use the template + if name == "" { + name = tpl.Push.Name + } + // Validate some things - if tpl.Push.Name == "" { + if name == "" { c.Ui.Error(fmt.Sprintf( "The 'push' section must be specified in the template with\n" + - "at least the 'name' option set.")) + "at least the 'name' option set. Alternatively, you can pass the\n" + + "name parameter from the CLI.")) return 1 } @@ -245,6 +253,9 @@ Options: -m, -message= A message to identify the purpose or changes in this Packer template much like a VCS commit message + -name= The destination build in Atlas. This is in a format + "username/name". + -token= The access token to use to when uploading ` diff --git a/command/push_test.go b/command/push_test.go index 36e6d11c0..322637049 100644 --- a/command/push_test.go +++ b/command/push_test.go @@ -120,6 +120,42 @@ func TestPush_noName(t *testing.T) { } } +func TestPush_cliName(t *testing.T) { + var actual []string + var actualOpts *uploadOpts + uploadFn := func(r io.Reader, opts *uploadOpts) (<-chan struct{}, <-chan error, error) { + actual = testArchive(t, r) + actualOpts = opts + + doneCh := make(chan struct{}) + close(doneCh) + return doneCh, nil, nil + } + + c := &PushCommand{ + Meta: testMeta(t), + uploadFn: uploadFn, + } + + args := []string{ + "-name=foo/bar", + filepath.Join(testFixture("push-no-name"), "template.json"), + } + + if code := c.Run(args); code != 0 { + fatalCommand(t, c.Meta) + } + + expected := []string{ + archiveTemplateEntry, + "template.json", + } + + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("bad: %#v", actual) + } +} + func TestPush_uploadError(t *testing.T) { uploadFn := func(r io.Reader, opts *uploadOpts) (<-chan struct{}, <-chan error, error) { return nil, nil, fmt.Errorf("bad") diff --git a/website/source/docs/command-line/push.html.markdown b/website/source/docs/command-line/push.html.markdown index be4040527..5833b917f 100644 --- a/website/source/docs/command-line/push.html.markdown +++ b/website/source/docs/command-line/push.html.markdown @@ -33,6 +33,9 @@ must be completed within the template. service such as Atlas. This can also be specified within the push configuration in the template. +* `-name` - The name of the build in the service. This typically + looks like `hashicorp/precise64`. + ## Examples Push a Packer template: