41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
// Command corestack-goose authors provider-local SQL and Go migrations offline.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
urfavecli "github.com/urfave/cli/v3"
|
|
"go.auvem.com/corestack/cmd/corestack-goose/internal/authoring"
|
|
)
|
|
|
|
func main() {
|
|
if err := command().Run(context.Background(), os.Args); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func command() *urfavecli.Command {
|
|
root := &urfavecli.Command{Name: "corestack-goose", Usage: "Author migrations before deployment"}
|
|
for _, name := range []string{"create", "fix"} {
|
|
root.Commands = append(root.Commands, &urfavecli.Command{Name: name,
|
|
Flags: []urfavecli.Flag{&urfavecli.StringFlag{Name: "dir", Value: ".", Usage: "Migration directory (defaults to the current working directory)"}},
|
|
Action: func(_ context.Context, cmd *urfavecli.Command) error {
|
|
if name == "create" {
|
|
if cmd.NArg() != 2 {
|
|
return fmt.Errorf("usage: create [--dir <dir>] <name> sql|go")
|
|
}
|
|
return authoring.Create(cmd.String("dir"), cmd.Args().Get(0), cmd.Args().Get(1))
|
|
}
|
|
if cmd.NArg() != 0 {
|
|
return fmt.Errorf("usage: fix [--dir <dir>]")
|
|
}
|
|
return authoring.Fix(cmd.String("dir"))
|
|
},
|
|
})
|
|
}
|
|
return root
|
|
}
|