cli: add dependencies to builders

This commit is contained in:
Elijah Duffy
2025-06-04 17:47:09 -07:00
parent 6331eaf093
commit b201306152
3 changed files with 44 additions and 36 deletions

View File

@@ -4,6 +4,8 @@ import (
"context"
"fmt"
"gitea.auvem.com/go-toolkit/app"
"gitea.auvem.com/go-toolkit/appcli"
"gitea.auvem.com/go-toolkit/dbx"
"gitea.auvem.com/go-toolkit/migrate"
"github.com/pressly/goose/v3"
@@ -11,30 +13,30 @@ import (
)
// MigrateCmd returns the main migrate command.
func MigrateCmd() *cli.Command {
return &cli.Command{
func MigrateCmd(directDeps []*app.Module, childDeps []*app.Module) *cli.Command {
return appcli.NewCommand(&cli.Command{
Name: "migrate",
Usage: "Migrate the database",
Commands: AllSubcommands(),
}
Commands: AllSubcommands(childDeps...),
}, directDeps...)
}
// AllSubcommands returns all subcommands of the migrate command.
func AllSubcommands() []*cli.Command {
func AllSubcommands(deps ...*app.Module) []*cli.Command {
return []*cli.Command{
MigrateStatusCmd(),
MigrateCreateCmd(),
MigrateUpCmd(),
MigrateUpToCmd(),
MigrateDownCmd(),
MigrateDownToCmd(),
MigrateRedoCmd(),
MigrateStatusCmd(deps...),
MigrateCreateCmd(deps...),
MigrateUpCmd(deps...),
MigrateUpToCmd(deps...),
MigrateDownCmd(deps...),
MigrateDownToCmd(deps...),
MigrateRedoCmd(deps...),
}
}
// MigrateStatusCmd returns a command to get database migration status.
func MigrateStatusCmd() *cli.Command {
return &cli.Command{
func MigrateStatusCmd(deps ...*app.Module) *cli.Command {
return appcli.NewCommand(&cli.Command{
Name: "status",
Usage: "Get database migration status",
Action: func(ctx context.Context, cmd *cli.Command) error {
@@ -44,12 +46,12 @@ func MigrateStatusCmd() *cli.Command {
return nil
},
}
}, deps...)
}
// MigrateCreateCmd returns a command to create a new migration.
func MigrateCreateCmd() *cli.Command {
return &cli.Command{
func MigrateCreateCmd(deps ...*app.Module) *cli.Command {
return appcli.NewCommand(&cli.Command{
Name: "create",
Usage: "Create a new migration",
Arguments: []cli.Argument{
@@ -74,12 +76,12 @@ func MigrateCreateCmd() *cli.Command {
return nil
},
}
}, deps...)
}
// MigrateUpCmd returns a command to apply all available database migrations.
func MigrateUpCmd() *cli.Command {
return &cli.Command{
func MigrateUpCmd(deps ...*app.Module) *cli.Command {
return appcli.NewCommand(&cli.Command{
Name: "up",
Usage: "Apply all available database migrations",
Action: func(ctx context.Context, cmd *cli.Command) error {
@@ -88,12 +90,12 @@ func MigrateUpCmd() *cli.Command {
}
return nil
},
}
}, deps...)
}
// MigrateUpToCmd returns a command to apply all available database migrations up to a specific version.
func MigrateUpToCmd() *cli.Command {
return &cli.Command{
func MigrateUpToCmd(deps ...*app.Module) *cli.Command {
return appcli.NewCommand(&cli.Command{
Name: "up-to",
Usage: "Apply all available database migrations up to a specific version",
Arguments: []cli.Argument{
@@ -109,12 +111,12 @@ func MigrateUpToCmd() *cli.Command {
}
return nil
},
}
}, deps...)
}
// MigrateDownCmd returns a command to rollback the most recent database migration.
func MigrateDownCmd() *cli.Command {
return &cli.Command{
func MigrateDownCmd(deps ...*app.Module) *cli.Command {
return appcli.NewCommand(&cli.Command{
Name: "down",
Usage: "Rollback the most recent database migration",
Action: func(ctx context.Context, cmd *cli.Command) error {
@@ -123,12 +125,12 @@ func MigrateDownCmd() *cli.Command {
}
return nil
},
}
}, deps...)
}
// MigrateDownToCmd returns a command to rollback all database migrations down to a specific version.
func MigrateDownToCmd() *cli.Command {
return &cli.Command{
func MigrateDownToCmd(deps ...*app.Module) *cli.Command {
return appcli.NewCommand(&cli.Command{
Name: "down-to",
Usage: "Rollback all database migrations down to a specific version",
Arguments: []cli.Argument{
@@ -144,12 +146,12 @@ func MigrateDownToCmd() *cli.Command {
}
return nil
},
}
}, deps...)
}
// MigrateRedoCmd returns a command to rollback the most recent database migration and reapply it.
func MigrateRedoCmd() *cli.Command {
return &cli.Command{
func MigrateRedoCmd(deps ...*app.Module) *cli.Command {
return appcli.NewCommand(&cli.Command{
Name: "redo",
Usage: "Rollback the most recent database migration and reapply it",
Action: func(ctx context.Context, cmd *cli.Command) error {
@@ -158,5 +160,5 @@ func MigrateRedoCmd() *cli.Command {
}
return nil
},
}
}, deps...)
}