log

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

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

The scaffolding here owns everything identical across providers: flag parsing, the --since/--until RFC3339 parsing, the incompatible-option warnings, pager gating, the empty-history early return, and the per-mode dispatch loop. The 140-line multi-branch Run of the original twins is split into four modes (default, --patch, --oneline, --output=json), each delegating the per-version line formatting to the provider Presenter so output stays byte-identical.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command(cfg Config) *cli.Command

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

func PatchParent added in v1.4.3

func PatchParent(i, n int, reverse bool) (parentIdx int, oldest bool)

PatchParent computes, for version i in a fetched window of n versions, the index of its parent (the immediately-older version) and whether i is the oldest version in the window.

git log -p attaches each version's own creation patch under its own header — the diff from its parent to itself. In newest-first order the parent is the next entry (i+1); in reverse (oldest-first) order it is the previous entry (i-1). The oldest version in the window has no parent in the list; the caller renders it as an all-added creation diff, but only when it is genuinely the initial version (guarding against a --number / date-filter window cut).

Types

type Config

type Config 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
	// UsageError is returned when the resource name argument is missing.
	UsageError string
	// Flags is the provider's flag set (param adds --max-value-length; the
	// --number/--since/--until usage strings differ between providers).
	Flags []cli.Flag
	// NewPresenter builds the provider Presenter bound to the fetch request.
	NewPresenter func(ctx context.Context, req Request) (Presenter, error)
}

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

type Options

type Options struct {
	ShowPatch      bool
	ParseJSON      bool
	Reverse        bool
	NoPager        bool
	Oneline        bool
	Output         output.Format
	MaxValueLength int
}

Options holds the shared render options.

type Presenter

type Presenter interface {
	// Fetch loads the version history via the provider usecase.
	Fetch(ctx context.Context) error
	// Len returns the number of versions loaded.
	Len() int
	// RenderJSON writes the provider-specific JSON array for all versions.
	RenderJSON(stdout io.Writer) error
	// RenderOneline writes the compact one-line form for version i.
	RenderOneline(stdout io.Writer, i, maxValueLength int)
	// RenderHeader writes the "Version ..." line and Date line for version i.
	RenderHeader(stdout io.Writer, i int)
	// RenderValue writes the value preview for version i (default, non-patch mode).
	// Providers without a default value preview (e.g. secrets) make this a no-op.
	RenderValue(stdout io.Writer, i, maxValueLength int)
	// RenderPatch writes the diff between version i and its neighbor (patch mode).
	RenderPatch(stdout, stderr io.Writer, i int, parseJSON, reverse bool)
}

Presenter renders version history for a specific provider. Implementations are stateful: Fetch loads the history, and the render methods format each version.

type Request

type Request struct {
	Name       string
	MaxResults int32
	Since      *time.Time
	Until      *time.Time
	Reverse    bool
}

Request holds the version-history fetch parameters (passed to the usecase).

type Runner

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

Runner executes the log command over a provider Presenter.

func (*Runner) Run

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

Run executes the log command, dispatching to the appropriate per-mode rendering.

Jump to

Keyboard shortcuts

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