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) Router ¶
Router returns the underlying Router, allowing callers to register commands or set pre-run hooks.
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 ¶
func NewCLIContext(cfg *config.Config, db *sql.DB, m commands.MigratorRunner, s *seeder.Runner, g *generator.Generator, l logger.Logger) *CLIContext
NewCLIContext creates a CLIContext with the given dependencies.
type CommandHandler ¶
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 ¶
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 ¶
NewRouter creates a Router that writes to the given writers. If out or errOut is nil, os.Stdout / os.Stderr is used.
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 ¶
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.