cli

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package cli provides the command-line interface for go-migration.

Package cli provides the command-line interface for go-migration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App is the top-level CLI application. It holds the Router and the CLIContext that provides dependencies to command handlers.

func NewApp

func NewApp(ctx *CLIContext) *App

NewApp creates a new CLI App with a Router. The CLIContext may be nil during initial setup — it is wired after config loading in the entry point.

func (*App) Context

func (a *App) Context() *CLIContext

Context returns the CLIContext.

func (*App) Router

func (a *App) Router() *Router

Router returns the underlying Router, allowing callers to register commands or set pre-run hooks.

func (*App) Run

func (a *App) Run(args []string) error

Run executes the router with the given arguments. Pass nil to use os.Args[1:].

func (*App) SetContext

func (a *App) SetContext(ctx *CLIContext)

SetContext sets the CLIContext. This is used when the context is built after config loading but before command execution.

type CLIContext

type CLIContext struct {
	Config    *config.Config
	DB        *sql.DB
	Migrator  commands.MigratorRunner
	Seeder    *seeder.Runner
	Generator *generator.Generator
	Logger    logger.Logger
}

CLIContext bundles the dependencies needed by CLI command handlers. It is constructed during app initialization and passed to each command.

func NewCLIContext

NewCLIContext creates a CLIContext with the given dependencies.

type CommandHandler

type CommandHandler func(args []string, flags *flag.FlagSet) error

CommandHandler handles a single CLI command. It receives the remaining args after the command name and a FlagSet for parsing per-command flags.

type PreRunFunc

type PreRunFunc func(cmdName string, configPath string, flags *flag.FlagSet) error

PreRunFunc is called before each command handler. It receives the command name, the parsed global config path, and the per-command FlagSet (already parsed).

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router matches os.Args to the correct CommandHandler.

func NewRouter

func NewRouter(out, errOut io.Writer, stdin io.Reader) *Router

NewRouter creates a Router that writes to the given writers. If out or errOut is nil, os.Stdout / os.Stderr is used.

func (*Router) ErrOut

func (r *Router) ErrOut() io.Writer

ErrOut returns the stderr writer.

func (*Router) Out

func (r *Router) Out() io.Writer

Out returns the stdout writer.

func (*Router) Register

func (r *Router) Register(name, description string, handler CommandHandler, setupFlags func(fs *flag.FlagSet))

Register adds a command to the router.

func (*Router) Run

func (r *Router) Run(args []string) error

Run parses os.Args (or the provided args) and dispatches to the matching handler. If args is nil, os.Args[1:] is used.

func (*Router) SetPreRun

func (r *Router) SetPreRun(fn PreRunFunc)

SetPreRun sets a function that runs before every command handler.

func (*Router) Stdin

func (r *Router) Stdin() io.Reader

Stdin returns the stdin reader.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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