Documentation
¶
Overview ¶
Package renderer contains the logic for formatting and displaying diffs.
Index ¶
- func FormatDiff(diffs []diffmatchpatch.Diff, options DiffOptions) string
- func GenerateDiffWithOptions(_ context.Context, current, desired *un.Unstructured, logger logging.Logger, ...) (*t.ResourceDiff, error)
- func GetLineDiff(oldText, newText string) []diffmatchpatch.Diff
- type ChangeDetail
- type CompactDiffFormatter
- type DefaultDiffRenderer
- type DiffFormatter
- type DiffOptions
- type DiffRenderer
- type FullDiffFormatter
- type OutputFormat
- type StructuredDiffOutput
- type StructuredDiffRenderer
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDiff ¶
func FormatDiff(diffs []diffmatchpatch.Diff, options DiffOptions) string
FormatDiff formats a slice of diffs according to the provided options.
func GenerateDiffWithOptions ¶
func GenerateDiffWithOptions(_ context.Context, current, desired *un.Unstructured, logger logging.Logger, options DiffOptions) (*t.ResourceDiff, error)
GenerateDiffWithOptions produces a structured diff between two unstructured objects.
func GetLineDiff ¶
func GetLineDiff(oldText, newText string) []diffmatchpatch.Diff
GetLineDiff performs a proper line-by-line diff and returns the raw diffs.
Types ¶
type ChangeDetail ¶ added in v0.6.0
type ChangeDetail struct {
Type string `json:"type" yaml:"type"`
APIVersion string `json:"apiVersion" yaml:"apiVersion"`
Kind string `json:"kind" yaml:"kind"`
Name string `json:"name" yaml:"name"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
Diff map[string]any `json:"diff" yaml:"diff"`
}
ChangeDetail represents a single resource change.
type CompactDiffFormatter ¶
type CompactDiffFormatter struct{}
CompactDiffFormatter formats diffs with limited context lines.
func (*CompactDiffFormatter) Format ¶
func (f *CompactDiffFormatter) Format(diffs []diffmatchpatch.Diff, options DiffOptions) string
Format implements the DiffFormatter interface for CompactDiffFormatter.
type DefaultDiffRenderer ¶
type DefaultDiffRenderer struct {
// contains filtered or unexported fields
}
DefaultDiffRenderer implements the DiffRenderer interface.
func (*DefaultDiffRenderer) RenderDiffs ¶
func (r *DefaultDiffRenderer) RenderDiffs(stdout io.Writer, diffs map[string]*dt.ResourceDiff) error
RenderDiffs formats and prints the diffs to the provided writer.
func (*DefaultDiffRenderer) SetDiffOptions ¶
func (r *DefaultDiffRenderer) SetDiffOptions(options DiffOptions)
SetDiffOptions updates the diff options used by the renderer.
type DiffFormatter ¶
type DiffFormatter interface {
Format(diffs []diffmatchpatch.Diff, options DiffOptions) string
}
DiffFormatter is the interface that defines the contract for diff formatters.
func NewFormatter ¶
func NewFormatter(compact bool) DiffFormatter
NewFormatter returns a DiffFormatter based on whether compact mode is desired.
type DiffOptions ¶
type DiffOptions struct {
// UseColors determines whether to colorize the output
UseColors bool
// AddPrefix is the prefix for added lines (default "+")
AddPrefix string
// DeletePrefix is the prefix for deleted lines (default "-")
DeletePrefix string
// ContextPrefix is the prefix for unchanged lines (default " ")
ContextPrefix string
// ContextLines is the number of unchanged lines to show before/after changes in compact mode
ContextLines int
// ChunkSeparator is the string used to separate chunks in compact mode
ChunkSeparator string
// Compact determines whether to show a compact diff
Compact bool
// IgnorePaths is a list of paths to ignore when calculating diffs
// Supports both simple paths (e.g., "metadata.annotations") and
// map key paths (e.g., "metadata.annotations[key.name/value]")
IgnorePaths []string
}
DiffOptions holds configuration options for the diff output.
func DefaultDiffOptions ¶
func DefaultDiffOptions() DiffOptions
DefaultDiffOptions returns the default options with colors enabled.
type DiffRenderer ¶
type DiffRenderer interface {
// RenderDiffs formats and outputs diffs to the provided writer
RenderDiffs(stdout io.Writer, diffs map[string]*dt.ResourceDiff) error
}
DiffRenderer handles rendering diffs to output.
func NewDiffRenderer ¶
func NewDiffRenderer(logger logging.Logger, diffOpts DiffOptions) DiffRenderer
NewDiffRenderer creates a new DefaultDiffRenderer with the given options.
func NewStructuredDiffRenderer ¶ added in v0.6.0
func NewStructuredDiffRenderer(logger logging.Logger, format OutputFormat) DiffRenderer
NewStructuredDiffRenderer creates a new structured renderer with the specified format.
type FullDiffFormatter ¶
type FullDiffFormatter struct{}
FullDiffFormatter formats diffs with all context lines.
func (*FullDiffFormatter) Format ¶
func (f *FullDiffFormatter) Format(diffs []diffmatchpatch.Diff, options DiffOptions) string
Format implements the DiffFormatter interface for FullDiffFormatter.
type OutputFormat ¶ added in v0.6.0
type OutputFormat string
OutputFormat represents the desired output format for diffs.
const ( // OutputFormatDiff is the default human-readable diff format. OutputFormatDiff OutputFormat = "diff" // OutputFormatJSON outputs structured JSON. OutputFormatJSON OutputFormat = "json" // OutputFormatYAML outputs structured YAML. OutputFormatYAML OutputFormat = "yaml" )
type StructuredDiffOutput ¶ added in v0.6.0
type StructuredDiffOutput struct {
Summary Summary `json:"summary" yaml:"summary"`
Changes []ChangeDetail `json:"changes" yaml:"changes"`
}
StructuredDiffOutput represents the structured output format for diffs.
type StructuredDiffRenderer ¶ added in v0.6.0
type StructuredDiffRenderer struct {
// contains filtered or unexported fields
}
StructuredDiffRenderer renders diffs in structured formats (JSON/YAML).
func (*StructuredDiffRenderer) RenderDiffs ¶ added in v0.6.0
func (r *StructuredDiffRenderer) RenderDiffs(stdout io.Writer, diffs map[string]*dt.ResourceDiff) error
RenderDiffs renders the diffs in the configured structured format.