mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 08:51:02 -06:00
ffe056bacb
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
package command
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
|
)
|
|
|
|
// 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 {
|
|
var update bool
|
|
|
|
args = c.Meta.process(args)
|
|
cmdFlags := c.Meta.defaultFlagSet("get")
|
|
cmdFlags.BoolVar(&update, "update", false, "update")
|
|
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
|
if err := cmdFlags.Parse(args); err != nil {
|
|
c.Ui.Error(fmt.Sprintf("Error parsing command-line flags: %s\n", err.Error()))
|
|
return 1
|
|
}
|
|
|
|
path, err := ModulePath(cmdFlags.Args())
|
|
if err != nil {
|
|
c.Ui.Error(err.Error())
|
|
return 1
|
|
}
|
|
|
|
path = c.normalizePath(path)
|
|
|
|
diags := getModules(&c.Meta, path, update)
|
|
c.showDiagnostics(diags)
|
|
if diags.HasErrors() {
|
|
return 1
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
func (c *GetCommand) Help() string {
|
|
helpText := `
|
|
Usage: terraform [global options] 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.
|
|
|
|
Module installation also happens automatically by default as part of
|
|
the "terraform init" command, so you should rarely need to run this
|
|
command separately.
|
|
|
|
Options:
|
|
|
|
-update Check already-downloaded modules for available updates
|
|
and install the newest versions available.
|
|
|
|
-no-color Disable text coloring in the output.
|
|
|
|
`
|
|
return strings.TrimSpace(helpText)
|
|
}
|
|
|
|
func (c *GetCommand) Synopsis() string {
|
|
return "Install or upgrade remote Terraform modules"
|
|
}
|
|
|
|
func getModules(m *Meta, path string, upgrade bool) tfdiags.Diagnostics {
|
|
hooks := uiModuleInstallHooks{
|
|
Ui: m.Ui,
|
|
ShowLocalPaths: true,
|
|
}
|
|
return m.installModules(path, upgrade, hooks)
|
|
}
|