-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic integration tests for migrate up
- Loading branch information
Showing
18 changed files
with
384 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package krabcli | ||
|
||
import ( | ||
"fmt" | ||
|
||
mcli "github.com/mitchellh/cli" | ||
"github.com/ohkrab/krab/cli" | ||
"github.com/ohkrab/krab/krab" | ||
) | ||
|
||
type Command mcli.Command | ||
|
||
type App struct { | ||
Ui cli.UI | ||
CLI *mcli.CLI | ||
Config *krab.Config | ||
} | ||
|
||
func New(ui cli.UI, args []string, config *krab.Config) *App { | ||
c := mcli.NewCLI(krab.InfoName, krab.InfoVersion) | ||
c.Args = args | ||
c.Commands = make(map[string]mcli.CommandFactory, 0) | ||
|
||
app := &App{ | ||
Ui: ui, | ||
CLI: c, | ||
Config: config, | ||
} | ||
app.RegisterAll() | ||
|
||
return app | ||
} | ||
|
||
func (a *App) RegisterAll() { | ||
a.RegisterCmd("version", func() Command { | ||
return &krab.ActionVersion{Ui: a.Ui} | ||
}) | ||
|
||
for _, set := range a.Config.MigrationSets { | ||
localSet := set | ||
|
||
a.RegisterCmd(fmt.Sprintln("migrate", "up", set.RefName), func() Command { | ||
return &krab.ActionMigrateUp{Ui: a.Ui, Set: localSet} | ||
}) | ||
|
||
a.RegisterCmd(fmt.Sprintln("migrate", "down", set.RefName), func() Command { | ||
return &krab.ActionMigrateDown{Ui: a.Ui, Set: localSet, Arguments: krab.Arguments{ | ||
Args: []*krab.Argument{ | ||
{ | ||
Name: "version", | ||
Type: "string", | ||
Description: "Migration version to rollback", | ||
}, | ||
}, | ||
}} | ||
}) | ||
} | ||
} | ||
|
||
func (a *App) Run() (int, error) { | ||
return a.CLI.Run() | ||
} | ||
|
||
func (a *App) RegisterCmd(names string, cmd func() Command) { | ||
a.CLI.Commands[names] = func() (mcli.Command, error) { | ||
return cmd(), nil | ||
} | ||
} |
Oops, something went wrong.