From c21042edb8b2d635fcc21e642519295d2e78ad1c Mon Sep 17 00:00:00 2001 From: Elijah Duffy Date: Thu, 5 Jun 2025 14:59:05 -0700 Subject: [PATCH] cli: use DepFn system instead of direct module lists --- cli/cli.go | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 31729b6..f962d84 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -4,7 +4,6 @@ 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" @@ -13,29 +12,29 @@ import ( ) // 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{ Name: "migrate", Usage: "Migrate the database", - Commands: AllSubcommands(sqlo, childDeps...), - }, directDeps...) + Commands: AllSubcommands(sqlo, childDeps), + }, directDeps) } // 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{ - MigrateStatusCmd(sqlo, deps...), - MigrateCreateCmd(sqlo, deps...), - MigrateUpCmd(sqlo, deps...), - MigrateUpToCmd(sqlo, deps...), - MigrateDownCmd(sqlo, deps...), - MigrateDownToCmd(sqlo, deps...), - MigrateRedoCmd(sqlo, deps...), + MigrateStatusCmd(sqlo, deps), + MigrateCreateCmd(sqlo, deps), + MigrateUpCmd(sqlo, deps), + MigrateUpToCmd(sqlo, deps), + MigrateDownCmd(sqlo, deps), + MigrateDownToCmd(sqlo, deps), + MigrateRedoCmd(sqlo, deps), } } // 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{ Name: "status", Usage: "Get database migration status", @@ -46,11 +45,11 @@ func MigrateStatusCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command { return nil }, - }, deps...) + }, deps) } // 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{ Name: "create", Usage: "Create a new migration", @@ -76,11 +75,11 @@ func MigrateCreateCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command { return nil }, - }, deps...) + }, deps) } // 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{ Name: "up", Usage: "Apply all available database migrations", @@ -90,11 +89,11 @@ func MigrateUpCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command { } return nil }, - }, deps...) + }, deps) } // 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{ Name: "up-to", 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 }, - }, deps...) + }, deps) } // 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{ Name: "down", Usage: "Rollback the most recent database migration", @@ -125,11 +124,11 @@ func MigrateDownCmd(sqlo dbx.SQLOFunc, deps ...*app.Module) *cli.Command { } return nil }, - }, deps...) + }, deps) } // 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{ Name: "down-to", 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 }, - }, deps...) + }, deps) } // 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{ Name: "redo", 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 }, - }, deps...) + }, deps) }