mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-02-16 07:01:11 -05:00
* Rename module name from "github.com/hashicorp/terraform" to "github.com/placeholderplaceholderplaceholder/opentf". Signed-off-by: Jakub Martin <kubam@spacelift.io> * Gofmt. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Regenerate protobuf. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Fix comments. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Undo issue and pull request link changes. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Undo comment changes. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Fix comment. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Undo some link changes. Signed-off-by: Jakub Martin <kubam@spacelift.io> * make generate && make protobuf Signed-off-by: Jakub Martin <kubam@spacelift.io> --------- Signed-off-by: Jakub Martin <kubam@spacelift.io>
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package renderers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/placeholderplaceholderplaceholder/opentf/internal/command/jsonformat/computed"
|
|
)
|
|
|
|
type evaluatedString struct {
|
|
String string
|
|
Json interface{}
|
|
|
|
IsMultiline bool
|
|
IsNull bool
|
|
}
|
|
|
|
func evaluatePrimitiveString(value interface{}, opts computed.RenderHumanOpts) evaluatedString {
|
|
if value == nil {
|
|
return evaluatedString{
|
|
String: opts.Colorize.Color("[dark_gray]null[reset]"),
|
|
IsNull: true,
|
|
}
|
|
}
|
|
|
|
str := value.(string)
|
|
|
|
if strings.HasPrefix(str, "{") || strings.HasPrefix(str, "[") {
|
|
var jv interface{}
|
|
if err := json.Unmarshal([]byte(str), &jv); err == nil {
|
|
return evaluatedString{
|
|
String: str,
|
|
Json: jv,
|
|
}
|
|
}
|
|
}
|
|
|
|
if strings.Contains(str, "\n") {
|
|
return evaluatedString{
|
|
String: strings.TrimSpace(str),
|
|
IsMultiline: true,
|
|
}
|
|
}
|
|
|
|
return evaluatedString{
|
|
String: str,
|
|
}
|
|
}
|
|
|
|
func (e evaluatedString) RenderSimple() string {
|
|
if e.IsNull {
|
|
return e.String
|
|
}
|
|
return fmt.Sprintf("%q", e.String)
|
|
}
|