cli: use DepFn system instead of direct module lists
This commit is contained in:
51
cli/cli.go
51
cli/cli.go
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.auvem.com/go-toolkit/app"
|
|
||||||
"gitea.auvem.com/go-toolkit/appcli"
|
"gitea.auvem.com/go-toolkit/appcli"
|
||||||
"gitea.auvem.com/go-toolkit/dbx"
|
"gitea.auvem.com/go-toolkit/dbx"
|
||||||
"gitea.auvem.com/go-toolkit/migrate"
|
"gitea.auvem.com/go-toolkit/migrate"
|
||||||
@@ -13,29 +12,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// MigrateCmd returns the main migrate command.
|
// MigrateCmd returns the main migrate command.
|
||||||
func MigrateCmd(sqlo dbx.SQLOFunc, directDeps []*app.Module, childDeps []*app.Module) *cli.Command {
|
func MigrateCmd(sqlo dbx.SQLOFunc, directDeps appcli.DepFn, childDeps appcli.DepFn) *cli.Command {
|
||||||
return appcli.NewCommand(&cli.Command{
|
return appcli.NewCommand(&cli.Command{
|
||||||
Name: "migrate",
|
Name: "migrate",
|
||||||
Usage: "Migrate the database",
|
Usage: "Migrate the database",
|
||||||
Commands: AllSubcommands(sqlo, childDeps...),
|
Commands: AllSubcommands(sqlo, childDeps),
|
||||||
}, directDeps...)
|
}, directDeps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllSubcommands returns all subcommands of the migrate command.
|
// AllSubcommands returns all subcommands of the migrate command.
|
||||||
func AllSubcommands(sqlo dbx.SQLOFunc, deps ...*app.Module) []*cli.Command {
|
func AllSubcommands(sqlo dbx.SQLOFunc, deps appcli.DepFn) []*cli.Command {
|
||||||
return []*cli.Command{
|
return []*cli.Command{
|
||||||
MigrateStatusCmd(sqlo, deps...),
|
MigrateStatusCmd(sqlo, deps),
|
||||||
MigrateCreateCmd(sqlo, deps...),
|
MigrateCreateCmd(sqlo, deps),
|
||||||
MigrateUpCmd(sqlo, deps...),
|
MigrateUpCmd(sqlo, deps),
|
||||||
MigrateUpToCmd(sqlo, deps...),
|
MigrateUpToCmd(sqlo, deps),
|
||||||
MigrateDownCmd(sqlo, deps...),
|
MigrateDownCmd(sqlo, deps),
|
||||||
MigrateDownToCmd(sqlo, deps...),
|
MigrateDownToCmd(sqlo, deps),
|
||||||
MigrateRedoCmd(sqlo, deps...),
|
MigrateRedoCmd(sqlo, deps),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateStatusCmd returns a command to get database migration status.
|
// MigrateStatusCmd returns a command to get database migration status.
|
||||||
func MigrateStatusCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
func MigrateStatusCmd(sqlo dbx.SQLOFunc, deps appcli.DepFn) *cli.Command {
|
||||||
return appcli.NewCommand(&cli.Command{
|
return appcli.NewCommand(&cli.Command{
|
||||||
Name: "status",
|
Name: "status",
|
||||||
Usage: "Get database migration status",
|
Usage: "Get database migration status",
|
||||||
@@ -46,11 +45,11 @@ func MigrateStatusCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}, deps...)
|
}, deps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateCreateCmd returns a command to create a new migration.
|
// MigrateCreateCmd returns a command to create a new migration.
|
||||||
func MigrateCreateCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
func MigrateCreateCmd(sqlo dbx.SQLOFunc, deps appcli.DepFn) *cli.Command {
|
||||||
return appcli.NewCommand(&cli.Command{
|
return appcli.NewCommand(&cli.Command{
|
||||||
Name: "create",
|
Name: "create",
|
||||||
Usage: "Create a new migration",
|
Usage: "Create a new migration",
|
||||||
@@ -76,11 +75,11 @@ func MigrateCreateCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}, deps...)
|
}, deps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateUpCmd returns a command to apply all available database migrations.
|
// MigrateUpCmd returns a command to apply all available database migrations.
|
||||||
func MigrateUpCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
func MigrateUpCmd(sqlo dbx.SQLOFunc, deps appcli.DepFn) *cli.Command {
|
||||||
return appcli.NewCommand(&cli.Command{
|
return appcli.NewCommand(&cli.Command{
|
||||||
Name: "up",
|
Name: "up",
|
||||||
Usage: "Apply all available database migrations",
|
Usage: "Apply all available database migrations",
|
||||||
@@ -90,11 +89,11 @@ func MigrateUpCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}, deps...)
|
}, deps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateUpToCmd returns a command to apply all available database migrations up to a specific version.
|
// MigrateUpToCmd returns a command to apply all available database migrations up to a specific version.
|
||||||
func MigrateUpToCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
func MigrateUpToCmd(sqlo dbx.SQLOFunc, deps appcli.DepFn) *cli.Command {
|
||||||
return appcli.NewCommand(&cli.Command{
|
return appcli.NewCommand(&cli.Command{
|
||||||
Name: "up-to",
|
Name: "up-to",
|
||||||
Usage: "Apply all available database migrations up to a specific version",
|
Usage: "Apply all available database migrations up to a specific version",
|
||||||
@@ -111,11 +110,11 @@ func MigrateUpToCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}, deps...)
|
}, deps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateDownCmd returns a command to rollback the most recent database migration.
|
// MigrateDownCmd returns a command to rollback the most recent database migration.
|
||||||
func MigrateDownCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
func MigrateDownCmd(sqlo dbx.SQLOFunc, deps appcli.DepFn) *cli.Command {
|
||||||
return appcli.NewCommand(&cli.Command{
|
return appcli.NewCommand(&cli.Command{
|
||||||
Name: "down",
|
Name: "down",
|
||||||
Usage: "Rollback the most recent database migration",
|
Usage: "Rollback the most recent database migration",
|
||||||
@@ -125,11 +124,11 @@ func MigrateDownCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}, deps...)
|
}, deps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateDownToCmd returns a command to rollback all database migrations down to a specific version.
|
// MigrateDownToCmd returns a command to rollback all database migrations down to a specific version.
|
||||||
func MigrateDownToCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
func MigrateDownToCmd(sqlo dbx.SQLOFunc, deps appcli.DepFn) *cli.Command {
|
||||||
return appcli.NewCommand(&cli.Command{
|
return appcli.NewCommand(&cli.Command{
|
||||||
Name: "down-to",
|
Name: "down-to",
|
||||||
Usage: "Rollback all database migrations down to a specific version",
|
Usage: "Rollback all database migrations down to a specific version",
|
||||||
@@ -146,11 +145,11 @@ func MigrateDownToCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}, deps...)
|
}, deps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateRedoCmd returns a command to rollback the most recent database migration and reapply it.
|
// MigrateRedoCmd returns a command to rollback the most recent database migration and reapply it.
|
||||||
func MigrateRedoCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
func MigrateRedoCmd(sqlo dbx.SQLOFunc, deps appcli.DepFn) *cli.Command {
|
||||||
return appcli.NewCommand(&cli.Command{
|
return appcli.NewCommand(&cli.Command{
|
||||||
Name: "redo",
|
Name: "redo",
|
||||||
Usage: "Rollback the most recent database migration and reapply it",
|
Usage: "Rollback the most recent database migration and reapply it",
|
||||||
@@ -160,5 +159,5 @@ func MigrateRedoCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}, deps...)
|
}, deps)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user