command: get supports -update
This commit is contained in:
parent
1b8426f7ff
commit
6f7c3caab3
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue