Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

any flags doesn't work with commands up down etc #38

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading