mirror of
https://github.com/opentofu/opentofu.git
synced 2026-06-09 16:40:24 -04:00
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
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
74 lines
2 KiB
Go
74 lines
2 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 (
|
|
"github.com/opentofu/opentofu/internal/addrs"
|
|
"github.com/opentofu/opentofu/internal/command/views/jsonfunction"
|
|
"github.com/opentofu/opentofu/internal/lang"
|
|
"github.com/opentofu/opentofu/internal/tfdiags"
|
|
"github.com/zclconf/go-cty/cty/function"
|
|
)
|
|
|
|
var (
|
|
ignoredFunctions = []addrs.Function{
|
|
addrs.ParseFunction("map").FullyQualified(),
|
|
addrs.ParseFunction("list").FullyQualified(),
|
|
}
|
|
)
|
|
|
|
type MetadataFunctions interface {
|
|
Diagnostics(diags tfdiags.Diagnostics)
|
|
// PrintFunctions returns true if it managed to print the functions and false otherwise.
|
|
PrintFunctions() bool
|
|
}
|
|
|
|
// NewMetadataFunctions returns an initialized MetadataFunctions implementation for the given ViewType.
|
|
// In case of this command, the returned [MetadataFunctions] will always print the diagnostics in human format
|
|
// and the functions in JSON format.
|
|
func NewMetadataFunctions(view *View) MetadataFunctions {
|
|
return &MetadataFunctionsMixed{view: view}
|
|
}
|
|
|
|
type MetadataFunctionsMixed struct {
|
|
view *View
|
|
}
|
|
|
|
var _ MetadataFunctions = (*MetadataFunctionsMixed)(nil)
|
|
|
|
func (v *MetadataFunctionsMixed) Diagnostics(diags tfdiags.Diagnostics) {
|
|
v.view.Diagnostics(diags)
|
|
}
|
|
|
|
func (v *MetadataFunctionsMixed) PrintFunctions() bool {
|
|
scope := &lang.Scope{}
|
|
funcs := scope.Functions()
|
|
filteredFuncs := make(map[string]function.Function)
|
|
for k, f := range funcs {
|
|
if isIgnoredFunction(k) {
|
|
continue
|
|
}
|
|
filteredFuncs[k] = f
|
|
}
|
|
|
|
jsonFunctions, marshalDiags := jsonfunction.Marshal(filteredFuncs)
|
|
if marshalDiags.HasErrors() {
|
|
v.Diagnostics(marshalDiags)
|
|
return false
|
|
}
|
|
_, _ = v.view.streams.Println(string(jsonFunctions))
|
|
return true
|
|
}
|
|
|
|
func isIgnoredFunction(name string) bool {
|
|
funcAddr := addrs.ParseFunction(name).FullyQualified().String()
|
|
for _, i := range ignoredFunctions {
|
|
if funcAddr == i.String() {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|