cli

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package cli implements the peng command-line interface. The same dispatcher is used by both the upstream `peng` binary and the user-built cmd/peng/main.go in each project — the latter brings the registered seeds along via a blank import.

Index

Constants

View Source
const EnvVar = "PENG_ENV"

EnvVar is the env variable peng reads to select which .env.<name> file (if any) to load. Set by --env=<name> on the CLI when present.

Variables

View Source
var Version = "0.1.0-dev"

Version is the peng release version.

Priority for the resolved value:

  1. goreleaser-baked value via `-ldflags -X .../cli.Version=...` (set for release binaries built by .github/workflows/release.yml)
  2. Module version from runtime/debug.ReadBuildInfo (set for users who installed via `go install github.com/2kims/peng/cmd/peng@vX.Y.Z`)
  3. The default "0.1.0-dev" fallback (local builds from source)

var rather than const because Go's -X ldflag only overrides variables.

Functions

func Dispatch

func Dispatch(ctx context.Context, args []string) error

Dispatch parses subcommand args and routes to the matching handler. Exported so tests can drive it without going through os.Args / os.Exit.

func Run

func Run()

Run is the entrypoint for the peng CLI. The upstream `peng` binary and each project's cmd/peng/main.go both call it. On error, the message is written to stderr and the process exits 1.

Before dispatching, Run extracts a global --env / PENG_ENV value and loads .env files in priority order (.env.local > .env.<env> > .env), without overwriting any variables already in the process environment. The subcommand dispatcher never sees --env.

Types

type Provider

type Provider interface {
	Up(ctx context.Context) ([]peng.Migration, error)
	Down(ctx context.Context) (*peng.Migration, error)
	Status(ctx context.Context) ([]peng.MigrationStatus, error)
	ApplySeed(ctx context.Context, name string, opts ...peng.ApplySeedOption) (*peng.SeedRunResult, error)
	ApplyAllSeeds(ctx context.Context, opts ...peng.ApplySeedOption) ([]peng.SeedRunResult, error)
	SeedStatus(ctx context.Context) ([]peng.SeedStatus, error)
	Close()
}

Provider is the operations the CLI needs from any dialect-specific provider. The pg package's *pg.Provider satisfies it; sqlite (or future dialects) will satisfy it the same way.

This interface lives in the cli package — not peng root — because the CLI is the only place that benefits from polymorphism over dialects. Direct library users import the dialect package and use the concrete *Provider directly.

Jump to

Keyboard shortcuts

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