cli

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 36 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cli defines the pg-sprite command tree (Kong): migrate and status (the optimistic front door), pull, diff, and fmt (the declarative front door), lint and suggest (the offline checker and advisor), capabilities (the embedded support matrix), and reap (the orphan-slot reaper).

Index

Constants

This section is empty.

Variables

View Source
var ErrLintFindings = errors.New("lint found errors")

ErrLintFindings is returned by lint when the script has error-severity findings, so the process exits non-zero; warnings alone pass.

View Source
var ErrPullFailed = errors.New("one or more tables could not be pulled")

ErrPullFailed is returned when at least one table could not be introspected or written. Render refusals use verdict.ErrRefused instead.

Functions

func Interruptible added in v0.4.0

func Interruptible(ctx context.Context) (context.Context, func())

Interruptible derives a context that an operator's SIGINT or SIGTERM cancels, and returns the stop function that releases the signal handler. The first signal cancels the context so the running command unwinds through its own stop path: a copy-and-swap run releases its table lock, writes its checkpoint, and prints the cancelled verdict, so a later run of the same statement resumes. A second signal ends the process immediately with exitCodeInterrupted for an operator who cannot wait.

func Main added in v0.4.0

func Main(args []string, version string, stdout, stderr io.Writer) (code int)

Main parses args, runs the selected command, and returns the process exit code; it never exits the process itself. stdout is the destination for --help and --version output only, and both return 0; commands write their results to the process stdout themselves. A command line that does not parse is reported on stderr — never stdout, which under --json carries only the machine-readable product — and exits exitFailed.

Types

type CLI

type CLI struct {
	Version kong.VersionFlag `help:"Print version and exit."`

	Migrate      MigrateCmd      `cmd:"" help:"Run a schema change safely."`
	Pull         PullCmd         `` /* 194-byte string literal not displayed */
	Diff         DiffCmd         `cmd:"" help:"Diff a desired-state schema file against the live schema."`
	Fmt          FmtCmd          `cmd:"" help:"Canonicalize a schema file."`
	Lint         LintCmd         `cmd:"" help:"Lint DDL for unsafe patterns."`
	Suggest      SuggestCmd      `cmd:"" help:"Recommend safer native forms for risky DDL."`
	Capabilities CapabilitiesCmd `cmd:"" help:"Print the embedded support matrix."`
	Status       StatusCmd       `cmd:"" help:"Report the status of a running schema change."`
	Reap         ReapCmd         `` /* 128-byte string literal not displayed */
}

CLI is the root command tree.

func New

func New(version string) *CLI

New returns a command tree for kong.Parse. The version is the same release-stamped value the binary prints for --version; requiring it here means a caller cannot build the tree and leave the capabilities output reporting a default.

type CapabilitiesCmd added in v0.3.3

type CapabilitiesCmd struct {
	OutputFlags `embed:""`

	JSON bool `help:"Emit the support matrix as JSON."`
	// contains filtered or unexported fields
}

CapabilitiesCmd prints the embedded support matrix without connecting to a database.

func (*CapabilitiesCmd) Run added in v0.3.3

func (c *CapabilitiesCmd) Run() error

Run implements the capabilities subcommand.

type DBFlags

type DBFlags struct {
	URL              string        `help:"PostgreSQL connection URL or key=value DSN." env:"PGSPRITE_URL" required:""`
	CACert           string        `` /* 346-byte string literal not displayed */
	LockTimeout      time.Duration `help:"Session lock_timeout applied to every statement. At least 1ms; 0 uses the default." default:"3s"`
	StatementTimeout time.Duration `help:"Session statement_timeout applied to every statement. At least 1ms; 0 uses the default." default:"30s"`
	Debug            bool          `help:"Log statement-level tracing and lifecycle diagnostics to stderr."`
	// contains filtered or unexported fields
}

DBFlags are the connection flags shared by every command that talks to the database, so every entry point carries the same bounded session defaults.

func (DBFlags) Config

func (f DBFlags) Config() dbconn.Config

Config translates the flags into the connectivity layer's configuration. The tracer is wired only under --debug: dbconn skips statement tracing entirely for a nil logger. The pool's default size is raised to what a copy-and-swap run with the copier's default workers needs, so a small host's default pool is not refused; a pool_max_conns in the URL is the operator's choice and is kept as given.

type DiffCmd

type DiffCmd struct {
	DBFlags     `embed:""`
	OutputFlags `embed:""`

	Desired         string   `help:"Path to the desired-state CREATE TABLE .sql file." name:"desired" type:"existingfile" required:""`
	Schema          string   `help:"Schema containing the live table." default:"public"`
	ExtensionSchema []string `` /* 368-byte string literal not displayed */
	JSON            bool     `help:"Emit the plan as JSON."`
	SQL             bool     `help:"Print the plan as an executable SQL script instead of the diagnostic report."`
}

DiffCmd derives statements from a desired-state schema (declarative front-end): introspect the live table, materialize the desired state on a rolled-back scratch schema, and print the ordered plan without executing anything.

func (*DiffCmd) Run

func (c *DiffCmd) Run(ctx context.Context) error

Run implements the diff subcommand.

func (*DiffCmd) Validate

func (c *DiffCmd) Validate() error

Validate rejects flag combinations with no coherent meaning: --json and --sql each replace the default report with a different whole-output format, so combining them names no single output.

type FmtCmd

type FmtCmd struct {
	Path string `arg:"" optional:"" help:"Schema file to format; stdin when omitted." type:"existingfile"`
}

FmtCmd canonicalizes a schema file. It is offline — no database flags.

func (*FmtCmd) Run

func (c *FmtCmd) Run() error

Run implements the fmt subcommand.

type LintCmd

type LintCmd struct {
	OutputFlags `embed:""`

	Path    string `arg:"" optional:"" help:"DDL file to lint; stdin when omitted." type:"existingfile"`
	JSON    bool   `help:"Emit the findings report as JSON."`
	Desired bool   `` /* 353-byte string literal not displayed */
}

LintCmd checks a DDL script for patterns the engine would refuse, rewrite, or gate. It is offline — no database flags.

func (*LintCmd) Run

func (c *LintCmd) Run() error

Run implements the lint subcommand.

type MigrateCmd

type MigrateCmd struct {
	DBFlags     `embed:""`
	OutputFlags `embed:""`

	Alter             string        `help:"Imperative ALTER statement to run." name:"alter"`
	Desired           string        `help:"Converge one table from a desired SQL file; mutually exclusive with --alter." type:"existingfile"`
	Schema            string        `help:"Target schema for --desired." default:"public"`
	ExtensionSchema   []string      `` /* 388-byte string literal not displayed */
	MaxTableSize      byteSize      `` /* 310-byte string literal not displayed */
	IndexBuildTimeout time.Duration `` /* 137-byte string literal not displayed */
	ValidateTimeout   time.Duration `` /* 134-byte string literal not displayed */
	Force             string        `` /* 462-byte string literal not displayed */
	AcceptBlocking    string        `` /* 802-byte string literal not displayed */
	AllowDestructive  string        `` /* 1052-byte string literal not displayed */
	ExpectFingerprint string        `` /* 337-byte string literal not displayed */
	LockAttempts      int           `help:"Maximum bounded attempts when native DDL exceeds lock_timeout; 1 disables retry." default:"3"`
	LockBackoff       time.Duration `help:"Initial exponential backoff between lock-timeout attempts." default:"100ms"`
	LockBackoffMax    time.Duration `help:"Maximum exponential backoff between lock-timeout attempts." default:"1s"`
	CopyAndSwap       bool          `` /* 538-byte string literal not displayed */
	FreeDisk          byteSize      `` /* 508-byte string literal not displayed */
	SlotLagCeiling    byteSize      `` /* 1199-byte string literal not displayed */
	KeepOld           bool          `` /* 187-byte string literal not displayed */
	BlockWrites       string        `` /* 471-byte string literal not displayed */
	Restart           string        `` /* 561-byte string literal not displayed */
	DryRun            bool          `help:"Classify and route the statement, print the plan, and execute nothing."`
	JSON              bool          `help:"Emit the verdict (or dry-run plan) as JSON."`
	Progress          string        `` /* 451-byte string literal not displayed */
	// contains filtered or unexported fields
}

MigrateCmd runs a schema change (imperative front-end): classify the statement, substitute the planner's safer native sequence by default when the submitted form blocks, and execute every step under bounded budgets. Everything the engine cannot run safely is refused with an explicit verdict.

func (*MigrateCmd) Run

func (c *MigrateCmd) Run(ctx context.Context) error

Run implements the migrate subcommand.

func (*MigrateCmd) Validate

func (c *MigrateCmd) Validate(kctx *kong.Context) error

Validate rejects flag combinations with no coherent meaning. A dry run reports the plan pg-sprite would execute without an override, so neither acknowledgement has anything to acknowledge there; accepting one would let an overridden apply ship with a dry run that reported a refusal it never checked. --force and --accept-blocking each acknowledge a different decision, and a statement reaches one; passing both would leave the audit record ambiguous. --accept-blocking also requires --statement-timeout on the same command line: the shared flag's default would silently become the accepted outage bound, so the operator has to state it. Kong records which flags the command line actually carried, which is the only place "explicitly supplied" is observable — the value alone cannot tell a typed default from an inherited one. The copy-and-swap policy flags govern a run, so they have no meaning on a dry run either. --restart acknowledges discarding a copy-and-swap leftover, so it has no meaning on a dry run or alongside the acknowledgements that steer a statement away from copy-and-swap. --allow-destructive acknowledges data loss, a different risk from the one --force accepts, so the two combine; a dry run with it reports the plan the acknowledged run would take, and a restart re-runs the same statement, so both combine too. It also combines with --accept-blocking, which an accepted DROP INDEX needs both of: one accepts the lock, the other the loss.

type OutputFlags

type OutputFlags struct {
	Color string `` /* 196-byte string literal not displayed */
}

OutputFlags are the presentation flags shared by every command that renders a human-facing diagnostic report. Color never touches the machine contracts: the JSON reports and the --sql script stay plain.

type PullCmd added in v0.3.0

type PullCmd struct {
	DBFlags `embed:""`

	Schema string `help:"Schema containing the tables to export." default:"public"`
	Out    string `` /* 141-byte string literal not displayed */
}

PullCmd exports every table in one schema as a desired-state schema file.

func (*PullCmd) Run added in v0.3.0

func (c *PullCmd) Run(ctx context.Context) error

Run implements the pull subcommand.

type ReapCmd added in v0.5.5

type ReapCmd struct {
	DBFlags `embed:""`

	DryRun bool `` /* 207-byte string literal not displayed */
	JSON   bool `help:"Emit the report as JSON."`
}

ReapCmd drops the engine's orphan replication slots, publications included, in the connected database: pgsprite_ slots of the engine's name shape that no checkpoint row in a non-terminal phase names and no process holds. Slots of other databases are never read.

func (*ReapCmd) Run added in v0.5.5

func (c *ReapCmd) Run(ctx context.Context) error

Run implements the reap subcommand.

type StatusCmd

type StatusCmd struct {
	DBFlags `embed:""`

	JSON bool `help:"Emit the session listing as JSON."`
}

StatusCmd reports schema-change progress.

func (*StatusCmd) Run

func (c *StatusCmd) Run(ctx context.Context) error

Run implements the status subcommand.

type SuggestCmd

type SuggestCmd struct {
	OutputFlags `embed:""`

	Path string `arg:"" optional:"" help:"DDL file to advise on; stdin when omitted." type:"existingfile"`
	JSON bool   `help:"Emit the suggestions report as JSON."`
}

SuggestCmd maps risky-as-written DDL to the safer native form the engine would run instead, with typed caveats. It is offline and advisory — no database flags, nothing executes, and it always exits zero.

func (*SuggestCmd) Run

func (c *SuggestCmd) Run() error

Run implements the suggest subcommand.

Jump to

Keyboard shortcuts

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