opentofu/internal/command/views/hook_module_install.go
Andrei Ciobanu 5603b8a27c
Some checks are pending
build / Build for freebsd_386 (push) Waiting to run
build / Build for linux_386 (push) Waiting to run
build / Build for openbsd_386 (push) Waiting to run
build / Build for windows_386 (push) Waiting to run
build / Build for freebsd_amd64 (push) Waiting to run
build / Build for linux_amd64 (push) Waiting to run
build / Build for openbsd_amd64 (push) Waiting to run
build / Build for solaris_amd64 (push) Waiting to run
build / Build for windows_amd64 (push) Waiting to run
build / Build for freebsd_arm (push) Waiting to run
build / Build for linux_arm (push) Waiting to run
build / Build for linux_arm64 (push) Waiting to run
build / Build for darwin_amd64 (push) Waiting to run
build / Build for darwin_arm64 (push) Waiting to run
build / End-to-end Tests for linux_386 (push) Waiting to run
build / End-to-end Tests for windows_386 (push) Waiting to run
build / End-to-end Tests for darwin_amd64 (push) Waiting to run
build / End-to-end Tests for linux_amd64 (push) Waiting to run
build / End-to-end Tests for windows_amd64 (push) Waiting to run
Quick Checks / List files changed for pull request (push) Waiting to run
Quick Checks / Unit tests for linux_386 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_amd64 (push) Blocked by required conditions
Quick Checks / Unit tests for windows_amd64 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_arm (push) Blocked by required conditions
Quick Checks / Unit tests for darwin_arm64 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_arm64 (push) Blocked by required conditions
Quick Checks / Race Tests (push) Blocked by required conditions
Quick Checks / End-to-end Tests (push) Blocked by required conditions
Quick Checks / Code Consistency Checks (push) Blocked by required conditions
Quick Checks / License Checks (push) Waiting to run
Website checks / List files changed for pull request (push) Waiting to run
Website checks / Build (push) Blocked by required conditions
Website checks / Test Installation Instructions (push) Blocked by required conditions
Refactor init command to use View instead of Ui (#3749)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-02-11 16:29:31 +02:00

82 lines
2.7 KiB
Go

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package views
import (
"fmt"
"github.com/hashicorp/go-version"
"github.com/opentofu/opentofu/internal/initwd"
)
// moduleInstallationHookHuman is the implementation of [initwd.ModuleInstallHooks] that prints the modules
// installation progress information in human readable format.
type moduleInstallationHookHuman struct {
v *View
showLocalPaths bool
}
var _ initwd.ModuleInstallHooks = moduleInstallationHookHuman{}
func (h moduleInstallationHookHuman) Download(modulePath, packageAddr string, v *version.Version) {
if v != nil {
_, _ = h.v.streams.Println(fmt.Sprintf("Downloading %s %s for %s...", packageAddr, v, modulePath))
} else {
_, _ = h.v.streams.Println(fmt.Sprintf("Downloading %s for %s...", packageAddr, modulePath))
}
}
func (h moduleInstallationHookHuman) Install(modulePath string, v *version.Version, localDir string) {
if h.showLocalPaths {
_, _ = h.v.streams.Println(fmt.Sprintf("- %s in %s", modulePath, localDir))
} else {
_, _ = h.v.streams.Println(fmt.Sprintf("- %s", modulePath))
}
}
// moduleInstallationHookJSON is the implementation of [initwd.ModuleInstallHooks] that prints the modules
// installation progress information in JSON format.
type moduleInstallationHookJSON struct {
v *JSONView
showLocalPaths bool
}
var _ initwd.ModuleInstallHooks = moduleInstallationHookJSON{}
func (h moduleInstallationHookJSON) Download(modulePath, packageAddr string, v *version.Version) {
if v != nil {
h.v.Info(fmt.Sprintf("Downloading %s %s for %s...", packageAddr, v, modulePath))
} else {
h.v.Info(fmt.Sprintf("Downloading %s for %s...", packageAddr, modulePath))
}
}
func (h moduleInstallationHookJSON) Install(modulePath string, _ *version.Version, localDir string) {
if h.showLocalPaths {
h.v.Info(fmt.Sprintf("installing %s in %s", modulePath, localDir))
} else {
h.v.Info(fmt.Sprintf("installing %s", modulePath))
}
}
// moduleInstallationHookMulti is the implementation of [initwd.ModuleInstallHooks] that wraps multiple
// implementation of [initwd.ModuleInstallHooks] and acts as a proxy for all of those.
// This is used for the `-json-into` flag.
type moduleInstallationHookMulti []initwd.ModuleInstallHooks
var _ initwd.ModuleInstallHooks = moduleInstallationHookMulti(nil)
func (m moduleInstallationHookMulti) Download(modulePath, packageAddr string, v *version.Version) {
for _, h := range m {
h.Download(modulePath, packageAddr, v)
}
}
func (m moduleInstallationHookMulti) Install(modulePath string, v *version.Version, localDir string) {
for _, h := range m {
h.Install(modulePath, v, localDir)
}
}