github.com/opentofu/opentofu@v1.7.1/internal/command/hook_module_install.go (about)

     1  // Copyright (c) The OpenTofu Authors
     2  // SPDX-License-Identifier: MPL-2.0
     3  // Copyright (c) 2023 HashiCorp, Inc.
     4  // SPDX-License-Identifier: MPL-2.0
     5  
     6  package command
     7  
     8  import (
     9  	"fmt"
    10  
    11  	version "github.com/hashicorp/go-version"
    12  	"github.com/mitchellh/cli"
    13  	"github.com/opentofu/opentofu/internal/initwd"
    14  )
    15  
    16  type uiModuleInstallHooks struct {
    17  	initwd.ModuleInstallHooksImpl
    18  	Ui             cli.Ui
    19  	ShowLocalPaths bool
    20  }
    21  
    22  var _ initwd.ModuleInstallHooks = uiModuleInstallHooks{}
    23  
    24  func (h uiModuleInstallHooks) Download(modulePath, packageAddr string, v *version.Version) {
    25  	if v != nil {
    26  		h.Ui.Info(fmt.Sprintf("Downloading %s %s for %s...", packageAddr, v, modulePath))
    27  	} else {
    28  		h.Ui.Info(fmt.Sprintf("Downloading %s for %s...", packageAddr, modulePath))
    29  	}
    30  }
    31  
    32  func (h uiModuleInstallHooks) Install(modulePath string, v *version.Version, localDir string) {
    33  	if h.ShowLocalPaths {
    34  		h.Ui.Info(fmt.Sprintf("- %s in %s", modulePath, localDir))
    35  	} else {
    36  		h.Ui.Info(fmt.Sprintf("- %s", modulePath))
    37  	}
    38  }