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 ¶
- func Accent(text string) string
- func Bold(text string) string
- func Danger(text string) string
- func DangerBadge(text string) string
- func DangerBold(text string) string
- func IsColorEnabled() bool
- func IsTerminal(r io.Reader) bool
- func LoadMigrations(cfg *config.Config) ([]migration.Entry, error)
- func Muted(text string) string
- func PrintDoctorHuman(w io.Writer, report DoctorReport)
- func PrintExecutedHuman(w io.Writer, executed []ExecutedMigration)
- func PrintJSON(w io.Writer, v any) error
- func PrintStatusHuman(w io.Writer, rows []StatusRow)
- func PromptConfirmation(in io.Reader, out io.Writer, prompts []string, expectedWord string) (bool, error)
- func SetColorEnabled(enabled bool)
- func Success(text string) string
- func SuccessBadge(text string) string
- func SuccessBadgeLine(text string) string
- func Warning(text string) string
- type ConfigError
- type Connection
- type DoctorCheck
- type DoctorReport
- type ExecutedMigration
- type PromptStep
- type StatusRow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accent ¶
Accent marks a neutral interface pointer (a plan bullet). It is never a status color — success/failure always go through Success/Danger.
func DangerBadge ¶
DangerBadge is the failing counterpart of SuccessBadge, for a run's headline verdict.
func DangerBold ¶
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 ¶
IsTerminal checks if the given reader is a character device (interactive terminal).
func LoadMigrations ¶
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 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 PrintStatusHuman ¶
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 SuccessBadge ¶
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 ¶
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.
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 ¶
BuildEngine connects to the database and constructs the engine in one step. The caller is responsible for closing the returned Connection.
func Connect ¶
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