Skip to content

Commit

Permalink
any flags doesn't work with commands up down etc
Browse files Browse the repository at this point in the history
  • Loading branch information
raoptimus committed Dec 2, 2024
1 parent 7af44d3 commit a9fce84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions cmd/db-migrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package main
import (
"fmt"
"os"
"slices"

_ "github.com/lib/pq"
"github.com/raoptimus/db-migrator.go/internal/migrator"
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a9fce84

Please sign in to comment.