diff --git a/command/get.go b/command/get.go index 2d3dec4a5..1ca3b1305 100644 --- a/command/get.go +++ b/command/get.go @@ -16,9 +16,12 @@ type GetCommand struct { } func (c *GetCommand) Run(args []string) int { + var update bool + args = c.Meta.process(args, false) cmdFlags := flag.NewFlagSet("get", flag.ContinueOnError) + cmdFlags.BoolVar(&update, "update", false, "update") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 @@ -40,9 +43,14 @@ func (c *GetCommand) Run(args []string) int { } } + mode := module.GetModeGet + if update { + mode = module.GetModeUpdate + } + _, _, err := c.Context(contextOpts{ Path: path, - GetMode: module.GetModeGet, + GetMode: mode, }) if err != nil { c.Ui.Error(fmt.Sprintf("Error loading Terraform: %s", err)) diff --git a/command/get_test.go b/command/get_test.go index b779222f8..cce03611c 100644 --- a/command/get_test.go +++ b/command/get_test.go @@ -28,6 +28,9 @@ func TestGet(t *testing.T) { if !strings.Contains(output, "Get: file://") { t.Fatalf("doesn't look like get: %s", output) } + if strings.Contains(output, "(update)") { + t.Fatalf("doesn't look like get: %s", output) + } } func TestGet_multipleArgs(t *testing.T) { @@ -75,4 +78,34 @@ func TestGet_noArgs(t *testing.T) { if !strings.Contains(output, "Get: file://") { t.Fatalf("doesn't look like get: %s", output) } + if strings.Contains(output, "(update)") { + t.Fatalf("doesn't look like get: %s", output) + } } + +func TestGet_update(t *testing.T) { + ui := new(cli.MockUi) + c := &GetCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(testProvider()), + Ui: ui, + }, + } + + args := []string{ + "-update", + testFixturePath("get"), + } + if code := c.Run(args); code != 0 { + t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) + } + + output := ui.OutputWriter.String() + if !strings.Contains(output, "Get: file://") { + t.Fatalf("doesn't look like get: %s", output) + } + if !strings.Contains(output, "(update)") { + t.Fatalf("doesn't look like get: %s", output) + } +} + diff --git a/command/module_storage.go b/command/module_storage.go index 0a33abe4a..846942aaa 100644 --- a/command/module_storage.go +++ b/command/module_storage.go @@ -19,6 +19,11 @@ func (s *uiModuleStorage) Dir(source string) (string, bool, error) { } func (s *uiModuleStorage) Get(source string, update bool) error { - s.Ui.Output(fmt.Sprintf("Get: %s", source)) + updateStr := "" + if update { + updateStr = " (update)" + } + + s.Ui.Output(fmt.Sprintf("Get: %s%s", source, updateStr)) return s.Storage.Get(source, update) }