computed

package
v1.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2024 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package computed contains types that represent the computed diffs for OpenTofu blocks, attributes, and outputs.

Each Diff struct is made up of a renderer, an action, and a boolean describing the diff. The renderer internally holds child diffs or concrete values that allow it to know how to render the diff appropriately.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	// Renderer captures the uncommon functionality across the different kinds
	// of changes. Each type of change (lists, blocks, sets, etc.) will have a
	// unique renderer.
	Renderer DiffRenderer

	// Action is the action described by this change (such as create, delete,
	// update, etc.).
	Action plans.Action

	// Replace tells the Change that it should add the `# forces replacement`
	// suffix.
	//
	// Every single change could potentially add this suffix, so we embed it in
	// the change as common functionality instead of in the specific renderers.
	Replace bool
}

Diff captures the computed diff for a single block, element or attribute.

It essentially merges common functionality across all types of changes, namely the replace logic and the action / change type. Any remaining behaviour can be offloaded to the renderer which will be unique for the various change types (eg. maps, objects, lists, blocks, primitives, etc.).

func NewDiff

func NewDiff(renderer DiffRenderer, action plans.Action, replace bool) Diff

NewDiff creates a new Diff object with the provided renderer, action and replace context.

func (Diff) RenderHuman

func (diff Diff) RenderHuman(indent int, opts RenderHumanOpts) string

RenderHuman prints the Change into a human-readable string referencing the specified RenderOpts.

If the returned string is a single line, then indent should be ignored.

If the return string is multiple lines, then indent should be used to offset the beginning of all lines but the first by the specified amount.

func (Diff) WarningsHuman

func (diff Diff) WarningsHuman(indent int, opts RenderHumanOpts) []string

WarningsHuman returns a list of strings that should be rendered as warnings before a given change is rendered.

As with the RenderHuman function, the indent should only be applied on multiline warnings and on the second and following lines.

type DiffRenderer

type DiffRenderer interface {
	RenderHuman(diff Diff, indent int, opts RenderHumanOpts) string
	WarningsHuman(diff Diff, indent int, opts RenderHumanOpts) []string
}

type RenderHumanOpts

type RenderHumanOpts struct {
	Colorize *colorstring.Colorize

	// OverrideNullSuffix tells the Renderer not to display the `-> null` suffix
	// that is normally displayed when an element, attribute, or block is
	// deleted.
	OverrideNullSuffix bool

	// OverrideForcesReplacement tells the Renderer to display the
	// `# forces replacement` suffix, even if a diff doesn't have the Replace
	// field set.
	//
	// Some renderers (like the Set renderer) don't display the suffix
	// themselves but force their child diffs to display it instead.
	OverrideForcesReplacement bool

	// ShowUnchangedChildren instructs the Renderer to render all children of a
	// given complex change, instead of hiding unchanged items and compressing
	// them into a single line.
	ShowUnchangedChildren bool

	// HideDiffActionSymbols tells the renderer not to show the '+'/'-' symbols
	// and to skip the places where the symbols would result in an offset.
	HideDiffActionSymbols bool
}

RenderHumanOpts contains options that can control how the human render function of the DiffRenderer will function.

func NewRenderHumanOpts

func NewRenderHumanOpts(colorize *colorstring.Colorize) RenderHumanOpts

NewRenderHumanOpts creates a new RenderHumanOpts struct with the required fields set.

func (RenderHumanOpts) Clone

func (opts RenderHumanOpts) Clone() RenderHumanOpts

Clone returns a new RenderOpts object, that matches the original but can be edited without changing the original.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL