2014-09-22 19:56:50 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
2014-09-22 20:15:27 +02:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/config/module"
|
2014-09-22 19:56:50 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetCommand is a Command implementation that takes a Terraform
|
|
|
|
// configuration and downloads all the modules.
|
|
|
|
type GetCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *GetCommand) Run(args []string) int {
|
2014-09-22 20:18:49 +02:00
|
|
|
var update bool
|
|
|
|
|
2014-09-22 19:56:50 +02:00
|
|
|
args = c.Meta.process(args, false)
|
|
|
|
|
|
|
|
cmdFlags := flag.NewFlagSet("get", flag.ContinueOnError)
|
2014-09-22 20:18:49 +02:00
|
|
|
cmdFlags.BoolVar(&update, "update", false, "update")
|
2014-09-22 19:56:50 +02:00
|
|
|
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
|
|
|
if err := cmdFlags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
var path string
|
|
|
|
args = cmdFlags.Args()
|
|
|
|
if len(args) > 1 {
|
2015-09-13 23:40:36 +02:00
|
|
|
c.Ui.Error("The get command expects one argument.\n")
|
2014-09-22 19:56:50 +02:00
|
|
|
cmdFlags.Usage()
|
|
|
|
return 1
|
|
|
|
} else if len(args) == 1 {
|
|
|
|
path = args[0]
|
|
|
|
} else {
|
|
|
|
var err error
|
|
|
|
path, err = os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error getting pwd: %s", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-22 20:18:49 +02:00
|
|
|
mode := module.GetModeGet
|
|
|
|
if update {
|
|
|
|
mode = module.GetModeUpdate
|
|
|
|
}
|
|
|
|
|
2014-09-22 19:56:50 +02:00
|
|
|
_, _, err := c.Context(contextOpts{
|
2014-09-22 20:15:27 +02:00
|
|
|
Path: path,
|
2014-09-22 20:18:49 +02:00
|
|
|
GetMode: mode,
|
2014-09-22 19:56:50 +02:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error loading Terraform: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *GetCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: terraform get [options] PATH
|
|
|
|
|
|
|
|
Downloads and installs modules needed for the configuration given by
|
|
|
|
PATH.
|
|
|
|
|
|
|
|
This recursively downloads all modules needed, such as modules
|
|
|
|
imported by modules imported by the root and so on. If a module is
|
|
|
|
already downloaded, it will not be redownloaded or checked for updates
|
|
|
|
unless the -update flag is specified.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
|
|
|
-update=false If true, modules already downloaded will be checked
|
|
|
|
for updates and updated if necessary.
|
|
|
|
|
2015-06-22 14:14:01 +02:00
|
|
|
-no-color If specified, output won't contain any color.
|
|
|
|
|
2014-09-22 19:56:50 +02:00
|
|
|
`
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *GetCommand) Synopsis() string {
|
|
|
|
return "Download and install modules for the configuration"
|
|
|
|
}
|