diff

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package diff provides the generic diff command shared by every provider.

The scaffolding here owns the flow that is identical across providers: diff argument parsing dispatch, parse-json formatting, the identical-versions check, pager gating, and the JSON/text dispatch. The provider-specific parts — the version-spec grammar, the diff header labels, the JSON shape, and the identical-versions hints — live behind the Presenter so each provider reproduces its own byte-identical output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command[S any](cfg Config[S]) *cli.Command

Command returns the generic diff command wired with the provider Config.

Types

type Config

type Config[S any] struct {
	// Usage is the one-line command usage string.
	Usage string
	// ArgsUsage is the positional-arguments usage string.
	ArgsUsage string
	// Description is the long help text.
	Description string
	// ParseDiffArgs parses the raw positional args into two version specs.
	ParseDiffArgs func(args []string) (S, S, error)
	// NewPresenter builds the provider Presenter bound to the two specs.
	NewPresenter func(ctx context.Context, spec1, spec2 S) (Presenter, error)
}

Config holds the provider-specific configuration for the diff command.

type Options

type Options struct {
	ParseJSON bool
	NoPager   bool
	Output    output.Format
}

Options holds the shared diff options.

type Presenter

type Presenter interface {
	// Fetch resolves both specs and loads their entries via the provider usecase.
	Fetch(ctx context.Context) error
	// OldValue and NewValue return the two raw values to be compared.
	OldValue() string
	NewValue() string
	// Labels returns the unified-diff header labels for the old and new sides.
	Labels() (oldLabel, newLabel string)
	// RenderJSON writes the provider JSON output. diff is the pre-computed raw
	// unified diff (empty when the versions are identical).
	RenderJSON(stdout io.Writer, oldValue, newValue string, identical bool, diff string) error
	// Hints writes the provider-specific hints shown when versions are identical.
	Hints(stderr io.Writer)
}

Presenter renders a diff for a specific provider. Implementations are stateful: Fetch loads both versions, and the subsequent methods render them.

type Runner

type Runner struct {
	Presenter Presenter
	Options   Options
	Stdout    io.Writer
	Stderr    io.Writer
}

Runner executes the diff command over a provider Presenter.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run executes the diff command.

Jump to

Keyboard shortcuts

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