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 ¶
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 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.