From a9fce84efc3bee147464c6ccd789691cf7b60229 Mon Sep 17 00:00:00 2001 From: raoptimus Date: Mon, 2 Dec 2024 23:11:23 +0300 Subject: [PATCH] any flags doesn't work with commands up down etc --- Makefile | 1 - cmd/db-migrator/main.go | 20 ++++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 96ea5d0..4b3967d 100644 --- a/Makefile +++ b/Makefile @@ -74,7 +74,6 @@ test-unit: ## Run only Unit tests test-integration: ## Run Integration Tests only @go test $$(go list ./... | grep -v mock) \ -buildvcs=false \ - -failfast \ -run Integration \ -tags=integration \ -v diff --git a/cmd/db-migrator/main.go b/cmd/db-migrator/main.go index 468bad3..2106664 100644 --- a/cmd/db-migrator/main.go +++ b/cmd/db-migrator/main.go @@ -11,6 +11,7 @@ package main import ( "fmt" "os" + "slices" _ "github.com/lib/pq" "github.com/raoptimus/db-migrator.go/internal/migrator" @@ -31,7 +32,6 @@ func main() { app.Name = "DB Service" app.Usage = "up/down/redo command for migrates the different db" app.Version = fmt.Sprintf("%s.rev[%s]", Version, GitCommit) - app.Flags = flags(&options) app.Commands = commands(&options) app.Before = func(context *cli.Context) error { dbService = migrator.New(&options) @@ -44,10 +44,13 @@ func main() { } func commands(options *migrator.Options) []*cli.Command { + defaultFlags := flags(options) + allFlags := slices.Concat(defaultFlags, addsFlags(options)) + return []*cli.Command{ { Name: "up", - Flags: addsFlags(options), + Flags: allFlags, Action: func(ctx *cli.Context) error { if a, err := dbService.Upgrade(); err != nil { return err @@ -58,7 +61,7 @@ func commands(options *migrator.Options) []*cli.Command { }, { Name: "down", - Flags: addsFlags(options), + Flags: allFlags, Action: func(ctx *cli.Context) error { if a, err := dbService.Downgrade(); err != nil { return err @@ -69,7 +72,7 @@ func commands(options *migrator.Options) []*cli.Command { }, { Name: "redo", - Flags: addsFlags(options), + Flags: allFlags, Action: func(ctx *cli.Context) error { if a, err := dbService.Redo(); err != nil { return err @@ -79,14 +82,15 @@ func commands(options *migrator.Options) []*cli.Command { }, }, { - Name: "create", + Name: "create", + Flags: defaultFlags, Action: func(ctx *cli.Context) error { return dbService.Create().Run(ctx) }, }, { Name: "history", - Flags: addsFlags(options), + Flags: allFlags, Action: func(ctx *cli.Context) error { if a, err := dbService.History(); err != nil { return err @@ -97,7 +101,7 @@ func commands(options *migrator.Options) []*cli.Command { }, { Name: "new", - Flags: addsFlags(options), + Flags: allFlags, Action: func(ctx *cli.Context) error { if a, err := dbService.HistoryNew(); err != nil { return err @@ -108,7 +112,7 @@ func commands(options *migrator.Options) []*cli.Command { }, { Name: "to", - Flags: addsFlags(options), + Flags: allFlags, Action: func(ctx *cli.Context) error { if a, err := dbService.To(); err != nil { return err