cliutil

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 14 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 cliutil holds the plumbing shared by every goforge subcommand: connecting to the configured database, building the migration.Engine and rendering output in both human and --json form.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accent

func Accent(text string) string

Accent marks a neutral interface pointer (a plan bullet). It is never a status color — success/failure always go through Success/Danger.

func Bold

func Bold(text string) string

Bold adds structural emphasis (headers) without implying a color meaning.

func Danger

func Danger(text string) string

Danger marks a negative per-item outcome (a failed check, a dirty migration).

func DangerBadge

func DangerBadge(text string) string

DangerBadge is the failing counterpart of SuccessBadge, for a run's headline verdict.

func DangerBold

func DangerBold(text string) string

DangerBold marks an irreversible destructive action — reserved for the warning banners and last-chance confirmations of reset/fresh/rollback.

func IsColorEnabled

func IsColorEnabled() bool

IsColorEnabled returns whether color output is currently enabled.

func IsTerminal

func IsTerminal(r io.Reader) bool

IsTerminal checks if the given reader is a character device (interactive terminal).

func LoadMigrations

func LoadMigrations(cfg *config.Config) ([]migration.Entry, error)

LoadMigrations discovers SQL migrations under cfg.Migrations.Path. Go migrations are not loaded here: the standalone CLI never interprets .go files, they are used by importing the migration engine as a library together with the registry `goforge generate` produces.

func Muted

func Muted(text string) string

Muted marks inactive or secondary text: skipped checks, pending migrations.

func PrepareConsole added in v0.1.1

func PrepareConsole()

PrepareConsole is a no-op outside Windows, where terminals handle UTF-8 and ANSI escape sequences without any per-process setup.

func PrintDoctorHuman

func PrintDoctorHuman(w io.Writer, report DoctorReport)

PrintDoctorHuman renders a DoctorReport as a checklist for humans, in the active language. Name and Detail stay in English inside the struct so the --json report remains a stable machine contract; only the fixed boilerplate and the known check names are translated here, at print time.

func PrintExecutedHuman

func PrintExecutedHuman(w io.Writer, executed []ExecutedMigration)

PrintExecutedHuman prints the "✓ 000001_create_users" lines shown after a successful migrate/rollback run. The line carries no words, so it is identical in every language.

func PrintJSON

func PrintJSON(w io.Writer, v any) error

PrintJSON writes v to w as indented JSON, followed by a newline.

func PrintStatusHuman

func PrintStatusHuman(w io.Writer, rows []StatusRow)

PrintStatusHuman renders a status table for humans, translated into the active language. The --json path (FromStatusEntries) is never translated.

func PromptConfirmation

func PromptConfirmation(in io.Reader, out io.Writer, prompts []string, expectedWord string) (bool, error)

PromptConfirmation runs one or more consecutive confirmation prompts against in/out. Every step must be answered with the exact expectedWord (strictly case-sensitive, e.g. "si" or "yes" in lowercase, no spaces).

Returns: - (true, nil): User successfully confirmed all steps. - (false, nil): User entered something else (cancellation). - (false, err): I/O or scanner error (e.g. unexpected EOF).

func SetColorEnabled

func SetColorEnabled(enabled bool)

SetColorEnabled explicitly enables or disables ANSI color escape sequences.

func Success

func Success(text string) string

Success marks a positive per-item outcome (a passed check, an applied migration).

func SuccessBadge

func SuccessBadge(text string) string

SuccessBadge renders text as a solid-background pill. Reserved for the single headline verdict of a run (e.g. "All checks passed") — individual items use Success instead, so a listing never turns into a wall of pills.

func SuccessBadgeLine

func SuccessBadgeLine(text string) string

SuccessBadgeLine wraps a message that carries its own surrounding blank lines (as the migrate/rollback/reset "done" strings do) in a success badge, without the badge's background bleeding onto those blank lines.

func Warning

func Warning(text string) string

Warning marks interactive caution: confirmation hints and cancellations.

Types

type ConfigError

type ConfigError struct {
	Err error
}

ConfigError wraps errors from loading configuration or connecting to the database, so main can distinguish "your setup is wrong" (exit 2) from "the migration run failed" (exit 1).

func (*ConfigError) Error

func (e *ConfigError) Error() string

func (*ConfigError) Unwrap

func (e *ConfigError) Unwrap() error

type Connection

type Connection struct {
	Provider migration.Provider
	DB       migration.DB
	// contains filtered or unexported fields
}

Connection bundles a Provider with the DB the engine should use against it, and a way to close both.

func BuildEngine

func BuildEngine(ctx context.Context, cfg *config.Config) (*migration.Engine, *Connection, error)

BuildEngine connects to the database and constructs the engine in one step. The caller is responsible for closing the returned Connection.

func Connect

func Connect(ctx context.Context, cfg *config.Config) (*Connection, error)

Connect opens a database connection for cfg.Database.Driver. See internal/providers for the supported drivers; config.Load already canonicalizes cfg.Database.Driver, this Resolve call is defense in depth for callers that build a Config by hand.

func (*Connection) Close

func (c *Connection) Close() error

type DoctorCheck

type DoctorCheck struct {
	Name    string `json:"name"`
	OK      bool   `json:"ok"`
	Skipped bool   `json:"skipped,omitempty"`
	Detail  string `json:"detail,omitempty"`
}

DoctorCheck is one diagnostic check `goforge doctor` ran.

type DoctorReport

type DoctorReport struct {
	Healthy bool          `json:"healthy"`
	Checks  []DoctorCheck `json:"checks"`
}

DoctorReport is the full result of `goforge doctor`.

type ExecutedMigration

type ExecutedMigration struct {
	Version     uint64 `json:"version"`
	Name        string `json:"name"`
	ExecutionMS int64  `json:"execution_time_ms"`
	AppliedAt   string `json:"applied_at,omitempty"`
}

ExecutedMigration is the JSON/human view of one migration.Record produced by a migrate/rollback run.

func FromRecords

func FromRecords(records []migration.Record) []ExecutedMigration

FromRecords converts a slice of migration.Record for JSON/human output.

type PromptStep

type PromptStep struct {
	Message string
}

PromptStep represents a prompt question to display to the user.

type StatusRow

type StatusRow struct {
	Version   uint64 `json:"version"`
	Name      string `json:"name"`
	Applied   bool   `json:"applied"`
	Batch     int    `json:"batch,omitempty"`
	AppliedAt string `json:"applied_at,omitempty"`
	Dirty     bool   `json:"dirty,omitempty"`
}

StatusRow is the JSON/human view of one migration.StatusEntry.

func FromStatusEntries

func FromStatusEntries(entries []migration.StatusEntry) []StatusRow

Jump to

Keyboard shortcuts

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