github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/command/hook_module_install.go (about)

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