2023-05-02 11:33:06 -04:00
|
|
|
// Copyright IBM Corp. 2014, 2026
|
2023-08-10 18:43:27 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-05-02 11:33:06 -04:00
|
|
|
|
2018-02-28 20:09:48 -05:00
|
|
|
package command
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2023-12-20 06:04:10 -05:00
|
|
|
"github.com/hashicorp/cli"
|
2018-02-28 20:09:48 -05:00
|
|
|
version "github.com/hashicorp/go-version"
|
2019-01-08 21:39:14 -05:00
|
|
|
"github.com/hashicorp/terraform/internal/initwd"
|
2018-02-28 20:09:48 -05:00
|
|
|
)
|
|
|
|
|
|
2024-04-05 01:30:55 -04:00
|
|
|
type view interface {
|
|
|
|
|
Log(message string, params ...any)
|
|
|
|
|
}
|
2018-02-28 20:09:48 -05:00
|
|
|
type uiModuleInstallHooks struct {
|
2019-01-08 21:39:14 -05:00
|
|
|
initwd.ModuleInstallHooksImpl
|
2018-02-28 20:09:48 -05:00
|
|
|
Ui cli.Ui
|
|
|
|
|
ShowLocalPaths bool
|
2024-04-05 01:30:55 -04:00
|
|
|
View view
|
2018-02-28 20:09:48 -05:00
|
|
|
}
|
|
|
|
|
|
2019-01-08 21:39:14 -05:00
|
|
|
var _ initwd.ModuleInstallHooks = uiModuleInstallHooks{}
|
2018-02-28 20:09:48 -05:00
|
|
|
|
|
|
|
|
func (h uiModuleInstallHooks) Download(modulePath, packageAddr string, v *version.Version) {
|
|
|
|
|
if v != nil {
|
2024-04-05 01:30:55 -04:00
|
|
|
h.log(fmt.Sprintf("Downloading %s %s for %s...", packageAddr, v, modulePath))
|
2018-02-28 20:09:48 -05:00
|
|
|
} else {
|
2024-04-05 01:30:55 -04:00
|
|
|
h.log(fmt.Sprintf("Downloading %s for %s...", packageAddr, modulePath))
|
2018-02-28 20:09:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h uiModuleInstallHooks) Install(modulePath string, v *version.Version, localDir string) {
|
|
|
|
|
if h.ShowLocalPaths {
|
2024-04-05 01:30:55 -04:00
|
|
|
h.log(fmt.Sprintf("- %s in %s", modulePath, localDir))
|
2018-02-28 20:09:48 -05:00
|
|
|
} else {
|
2024-04-05 01:30:55 -04:00
|
|
|
h.log(fmt.Sprintf("- %s", modulePath))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h uiModuleInstallHooks) log(message string) {
|
|
|
|
|
switch h.View.(type) {
|
|
|
|
|
case view:
|
2024-08-09 13:54:13 -04:00
|
|
|
// there is no unformatted option for the View interface, so we need to
|
|
|
|
|
// pass message as a parameter to avoid double escaping % characters
|
|
|
|
|
h.View.Log("%s", message)
|
2024-04-05 01:30:55 -04:00
|
|
|
default:
|
|
|
|
|
h.Ui.Info(message)
|
2018-02-28 20:09:48 -05:00
|
|
|
}
|
|
|
|
|
}
|