cli: add dependencies to builders
This commit is contained in:
68
cli/cli.go
68
cli/cli.go
@@ -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...)
|
||||
}
|
||||
|
||||
4
go.mod
4
go.mod
@@ -3,10 +3,12 @@ module gitea.auvem.com/go-toolkit/migrate
|
||||
go 1.24.0
|
||||
|
||||
require (
|
||||
gitea.auvem.com/go-toolkit/app v0.0.0-20250530224140-b760b035b4d1
|
||||
gitea.auvem.com/go-toolkit/app v0.0.0-20250603235859-6f9e3731acf9
|
||||
gitea.auvem.com/go-toolkit/appcli v0.0.0-20250604221759-6b4196dbda59
|
||||
gitea.auvem.com/go-toolkit/dbx v0.0.0-20250530232843-55cc3ffd8364
|
||||
github.com/pressly/goose/v3 v3.24.3
|
||||
github.com/spf13/cobra v1.9.1
|
||||
github.com/urfave/cli/v3 v3.3.3
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
8
go.sum
8
go.sum
@@ -1,7 +1,9 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
gitea.auvem.com/go-toolkit/app v0.0.0-20250530224140-b760b035b4d1 h1:22A/8PcixfY9B+q+30aTyFUW8W4DtDIELDWP2WUdKk0=
|
||||
gitea.auvem.com/go-toolkit/app v0.0.0-20250530224140-b760b035b4d1/go.mod h1:a7ENpOxndUdONE6oZ9MZAvG1ba2uq01x/LtcnDkpOj8=
|
||||
gitea.auvem.com/go-toolkit/app v0.0.0-20250603235859-6f9e3731acf9 h1:MYOI+bB4IBAqoL1tyIUFnu0S+NSq0OX88J3K/PUR7lI=
|
||||
gitea.auvem.com/go-toolkit/app v0.0.0-20250603235859-6f9e3731acf9/go.mod h1:a7ENpOxndUdONE6oZ9MZAvG1ba2uq01x/LtcnDkpOj8=
|
||||
gitea.auvem.com/go-toolkit/appcli v0.0.0-20250604221759-6b4196dbda59 h1:fKH/G5QUbqUeA20UlxqSOVZvFPjt2JIaGgaLg4QRSEs=
|
||||
gitea.auvem.com/go-toolkit/appcli v0.0.0-20250604221759-6b4196dbda59/go.mod h1:kutQ69eyFMhs7l8siqdZcHRQ9BLc32ftLs0crnm+dys=
|
||||
gitea.auvem.com/go-toolkit/dbx v0.0.0-20250530232843-55cc3ffd8364 h1:xadjfyFYYoyy8d6AtqiNSv8OtMtav53vMpg3mVRM+10=
|
||||
gitea.auvem.com/go-toolkit/dbx v0.0.0-20250530232843-55cc3ffd8364/go.mod h1:3CYeto5wVq0fcABgssDYycXGbR7ibNiN66p1HpxBdds=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
@@ -54,6 +56,8 @@ github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/urfave/cli/v3 v3.3.3 h1:byCBaVdIXuLPIDm5CYZRVG6NvT7tv1ECqdU4YzlEa3I=
|
||||
github.com/urfave/cli/v3 v3.3.3/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 h1:y5zboxd6LQAqYIhHnB48p0ByQ/GnQx2BE33L8BOHQkI=
|
||||
|
||||
Reference in New Issue
Block a user