Merge pull request #16542 from hashicorp/jbardin/module-ui
update init output
This commit is contained in:
commit
f25d08061d
|
@ -30,7 +30,7 @@ func TestGet(t *testing.T) {
|
|||
}
|
||||
|
||||
output := ui.OutputWriter.String()
|
||||
if !strings.Contains(output, "Get: file://") {
|
||||
if !strings.Contains(output, "module.foo") {
|
||||
t.Fatalf("doesn't look like get: %s", output)
|
||||
}
|
||||
if strings.Contains(output, "(update)") {
|
||||
|
@ -78,7 +78,7 @@ func TestGet_noArgs(t *testing.T) {
|
|||
}
|
||||
|
||||
output := ui.OutputWriter.String()
|
||||
if !strings.Contains(output, "Get: file://") {
|
||||
if !strings.Contains(output, "module.foo") {
|
||||
t.Fatalf("doesn't look like get: %s", output)
|
||||
}
|
||||
if strings.Contains(output, "(update)") {
|
||||
|
@ -108,10 +108,7 @@ func TestGet_update(t *testing.T) {
|
|||
}
|
||||
|
||||
output := ui.OutputWriter.String()
|
||||
if !strings.Contains(output, "Get: file://") {
|
||||
t.Fatalf("doesn't look like get: %s", output)
|
||||
}
|
||||
if !strings.Contains(output, "(update)") {
|
||||
if !strings.Contains(output, `Updating source "./foo"`) {
|
||||
t.Fatalf("doesn't look like get: %s", output)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ func (c *InitCommand) Run(args []string) int {
|
|||
"[reset][bold]Upgrading modules...")))
|
||||
} else {
|
||||
c.Ui.Output(c.Colorize().Color(fmt.Sprintf(
|
||||
"[reset][bold]Downloading modules...")))
|
||||
"[reset][bold]Initializing modules...")))
|
||||
}
|
||||
|
||||
if err := getModules(&c.Meta, path, getMode); err != nil {
|
||||
|
|
|
@ -170,7 +170,7 @@ func TestInit_get(t *testing.T) {
|
|||
|
||||
// Check output
|
||||
output := ui.OutputWriter.String()
|
||||
if !strings.Contains(output, "Get: file://") {
|
||||
if !strings.Contains(output, "Getting source") {
|
||||
t.Fatalf("doesn't look like get: %s", output)
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ func TestInit_getUpgradeModules(t *testing.T) {
|
|||
|
||||
// Check output
|
||||
output := ui.OutputWriter.String()
|
||||
if !strings.Contains(output, "(update)") {
|
||||
if !strings.Contains(output, "Updating source") {
|
||||
t.Fatalf("doesn't look like get upgrade: %s", output)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,12 @@ func (s *Storage) lookupModuleVersions(module *regsrc.Module) (*response.ModuleV
|
|||
return nil, err
|
||||
}
|
||||
|
||||
for _, mod := range versions.Modules {
|
||||
for _, v := range mod.Versions {
|
||||
log.Printf("[DEBUG] found available version %q for %s", v.Version, mod.Source)
|
||||
}
|
||||
}
|
||||
|
||||
return &versions, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -160,6 +160,7 @@ func (s Storage) moduleVersions(source string) ([]moduleRecord, error) {
|
|||
|
||||
for _, m := range manifest.Modules {
|
||||
if m.Source == source && m.Version != "" {
|
||||
log.Printf("[DEBUG] found local version %q for module %s", m.Version, m.Source)
|
||||
matching = append(matching, m)
|
||||
}
|
||||
}
|
||||
|
@ -207,18 +208,19 @@ func (s Storage) recordModuleRoot(dir, root string) error {
|
|||
return s.recordModule(rec)
|
||||
}
|
||||
|
||||
func (s Storage) output(msg string) {
|
||||
if s.Ui == nil || s.Mode == GetModeNone {
|
||||
return
|
||||
}
|
||||
s.Ui.Output(msg)
|
||||
}
|
||||
|
||||
func (s Storage) getStorage(key string, src string) (string, bool, error) {
|
||||
storage := &getter.FolderStorage{
|
||||
StorageDir: s.StorageDir,
|
||||
}
|
||||
|
||||
if s.Ui != nil {
|
||||
update := ""
|
||||
if s.Mode == GetModeUpdate {
|
||||
update = " (update)"
|
||||
}
|
||||
s.Ui.Output(fmt.Sprintf("Get: %s%s", src, update))
|
||||
}
|
||||
log.Printf("[DEBUG] fetching module from %s", src)
|
||||
|
||||
// Get the module with the level specified if we were told to.
|
||||
if s.Mode > GetModeNone {
|
||||
|
@ -307,6 +309,7 @@ func (s Storage) findRegistryModule(mSource, constraint string) (moduleRecord, e
|
|||
if err != nil {
|
||||
log.Printf("[INFO] no matching version for %q<%s>, %s", mod.Module(), constraint, err)
|
||||
}
|
||||
log.Printf("[DEBUG] matched %q version %s for %s", mod, match.Version, constraint)
|
||||
|
||||
rec.Dir = match.Dir
|
||||
rec.Version = match.Version
|
||||
|
@ -339,6 +342,9 @@ func (s Storage) findRegistryModule(mSource, constraint string) (moduleRecord, e
|
|||
if err != nil {
|
||||
return rec, err
|
||||
}
|
||||
|
||||
s.output(fmt.Sprintf(" Found version %s of %s on %s", rec.Version, mod.Module(), mod.RawHost.Display()))
|
||||
|
||||
}
|
||||
return rec, nil
|
||||
}
|
||||
|
|
|
@ -207,12 +207,16 @@ func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) {
|
|||
}
|
||||
|
||||
// Determine the path to this child
|
||||
path := make([]string, len(t.path), len(t.path)+1)
|
||||
copy(path, t.path)
|
||||
path = append(path, m.Name)
|
||||
modPath := make([]string, len(t.path), len(t.path)+1)
|
||||
copy(modPath, t.path)
|
||||
modPath = append(modPath, m.Name)
|
||||
|
||||
log.Printf("[TRACE] module source: %q", m.Source)
|
||||
|
||||
// add the module path to help indicate where modules with relative
|
||||
// paths are being loaded from
|
||||
s.output(fmt.Sprintf("- module.%s", strings.Join(modPath, ".")))
|
||||
|
||||
// Lookup the local location of the module.
|
||||
// dir is the local directory where the module is stored
|
||||
mod, err := s.findRegistryModule(m.Source, m.Version)
|
||||
|
@ -236,7 +240,7 @@ func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if mod.Dir != "" {
|
||||
if mod.Dir != "" && s.Mode != GetModeUpdate {
|
||||
// We found it locally, but in order to load the Tree we need to
|
||||
// find out if there was another subDir stored from detection.
|
||||
subDir, err := s.getModuleRoot(mod.Dir)
|
||||
|
@ -245,20 +249,20 @@ func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) {
|
|||
// recordSubdir method fix it up. Any other filesystem errors
|
||||
// will turn up again below.
|
||||
log.Println("[WARN] error reading subdir record:", err)
|
||||
} else {
|
||||
fullDir := filepath.Join(mod.Dir, subDir)
|
||||
|
||||
child, err := NewTreeModule(m.Name, fullDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("module %s: %s", m.Name, err)
|
||||
}
|
||||
child.path = path
|
||||
child.parent = t
|
||||
child.version = mod.Version
|
||||
child.source = m.Source
|
||||
children[m.Name] = child
|
||||
continue
|
||||
}
|
||||
|
||||
fullDir := filepath.Join(mod.Dir, subDir)
|
||||
|
||||
child, err := NewTreeModule(m.Name, fullDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("module %s: %s", m.Name, err)
|
||||
}
|
||||
child.path = modPath
|
||||
child.parent = t
|
||||
child.version = mod.Version
|
||||
child.source = m.Source
|
||||
children[m.Name] = child
|
||||
continue
|
||||
}
|
||||
|
||||
// Split out the subdir if we have one.
|
||||
|
@ -286,6 +290,15 @@ func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) {
|
|||
subDir = filepath.Join(detectedSubDir, subDir)
|
||||
}
|
||||
|
||||
output := ""
|
||||
switch s.Mode {
|
||||
case GetModeUpdate:
|
||||
output = fmt.Sprintf(" Updating source %q", m.Source)
|
||||
default:
|
||||
output = fmt.Sprintf(" Getting source %q", m.Source)
|
||||
}
|
||||
s.output(output)
|
||||
|
||||
dir, ok, err := s.getStorage(key, source)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -325,7 +338,7 @@ func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("module %s: %s", m.Name, err)
|
||||
}
|
||||
child.path = path
|
||||
child.path = modPath
|
||||
child.parent = t
|
||||
child.version = mod.Version
|
||||
child.source = m.Source
|
||||
|
@ -351,6 +364,10 @@ func (t *Tree) inheritProviderConfigs(stack []*Tree) {
|
|||
c.inheritProviderConfigs(stack)
|
||||
}
|
||||
|
||||
if len(stack) == 1 {
|
||||
return
|
||||
}
|
||||
|
||||
providers := make(map[string]*config.ProviderConfig)
|
||||
missingProviders := make(map[string]bool)
|
||||
|
||||
|
@ -365,11 +382,6 @@ func (t *Tree) inheritProviderConfigs(stack []*Tree) {
|
|||
}
|
||||
}
|
||||
|
||||
// After allowing the empty implicit configs to be created in root, there's nothing left to inherit
|
||||
if len(stack) == 1 {
|
||||
return
|
||||
}
|
||||
|
||||
// get our parent's module config block
|
||||
parent := stack[len(stack)-2]
|
||||
var parentModule *config.Module
|
||||
|
|
Loading…
Reference in New Issue