cmd

package
v0.0.0-...-3103211 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package cmd implements the commands: warm, list, debug and version.

Each command takes the injected runtime and its own arguments and returns an exit status. Nothing here reads os.* or flag.CommandLine: main hands everything over.

Index

Constants

View Source
const (
	// ExitOK reports that every listed URL answered 2xx in the last run.
	ExitOK = 0
	// ExitFailed reports a last run where a URL failed, was redirected without
	// --follow or was out of scope without --lax, or an empty enumeration.
	ExitFailed = 1
	// ExitUsage reports a bad command line, or a source that did not answer 200.
	ExitUsage = 2
	// ExitLogin reports a Drupal login the site did not accept.
	ExitLogin = 3
)

Exit statuses. They hold for the binary: go run collapses every non-zero status to 1.

View Source
const (
	EnvBasicAuthPassword = "DRUPAL_WARMUP_BAPASS"
	EnvDrupalPassword    = "DRUPAL_WARMUP_DRPASS"
)

Environment variables standing in for the password flags, which are visible to ps and land in shell history.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, rt *Runtime, args []string) int

Debug fetches the given URLs one at a time with the Xdebug trigger set.

A production warm never carries a debug trigger, which is why this is a command of its own rather than a flag on warm. Redirects are never followed, and stdout shows the status line, the response headers and the drained body length of each answer.

func List

func List(ctx context.Context, rt *Runtime, args []string) int

List enumerates the site and prints one URL per line, fetching none.

An entry the warm command would skip is printed behind a # with its reason, which the list-file source ignores, so the output feeds a later run unchanged.

func NewLogger

func NewLogger(stderr io.Writer, verbosity int) *slog.Logger

NewLogger maps the verbosity to a level: 0 is silent, 1 warnings, 2 progress, 3 requests.

func RealMain

func RealMain(ctx context.Context, args, env []string,
	stdin io.Reader, stdout, stderr io.Writer,
	fsys fs.FS, transport http.RoundTripper,
) int

RealMain is the composition root: it takes every ambient value the program reads.

It parses the global flags, builds the logger and dispatches on the command.

func Version

func Version(rt *Runtime) int

Version prints the version go build stamped into the binary.

func Warm

func Warm(ctx context.Context, rt *Runtime, args []string) int

Warm enumerates the site and fetches every URL, the production path.

Types

type OSFS

type OSFS struct{}

OSFS is the OS filesystem behind an fs.FS.

Not os.DirFS: fs.ValidPath rejects a leading slash and "..", and --list-file has to accept any path the OS does.

func (OSFS) Open

func (OSFS) Open(name string) (fs.File, error)

Open opens a file the way os.Open does.

type Runtime

type Runtime struct {
	// configuration
	Env []string

	// services
	FS        fs.FS
	Log       *slog.Logger
	Stderr    io.Writer
	Stdin     io.Reader
	Stdout    io.Writer
	Transport http.RoundTripper
}

Runtime is every ambient value the commands read, injected by main.

Jump to

Keyboard shortcuts

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