-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (82 loc) · 1.88 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"github.com/mg98/scriptup/pkg/scriptup"
"github.com/urfave/cli/v2"
"log"
"os"
)
func main() {
app := NewApp()
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
// NewApp creates a new command line app
func NewApp() *cli.App {
app := cli.NewApp()
app.Name = "scriptup"
app.Usage = "A lightweight and agnostic script migration tool."
app.Version = "0.1.0"
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "env",
Aliases: []string{"e"},
Value: "dev",
Usage: "specify which configuration to use",
},
}
app.Commands = []*cli.Command{
{
Name: "new",
Aliases: []string{"n"},
Usage: "Generate a new migration file",
Action: func(c *cli.Context) error {
cfg := scriptup.GetConfig(c.String("env"))
return scriptup.NewMigrationFile(cfg, c.Args().Get(0))
},
},
{
Name: "up",
Aliases: []string{"u"},
Flags: []cli.Flag{
&cli.IntFlag{
Name: "steps",
Value: -1,
Usage: "Limit the number of migrations to run",
},
},
Usage: "Execute recent scripts that have not been migrated yet",
Action: func(c *cli.Context) error {
cfg := scriptup.GetConfig(c.String("env"))
return scriptup.MigrateUp(cfg, c.Int("steps"))
},
},
{
Name: "down",
Aliases: []string{"d"},
Flags: []cli.Flag{
&cli.IntFlag{
Name: "steps",
Value: -1,
Usage: "Limit the number of migrations to run",
},
},
Usage: "Undo recently performed migrations",
Action: func(c *cli.Context) error {
cfg := scriptup.GetConfig(c.String("env"))
return scriptup.MigrateDown(cfg, c.Int("steps"))
},
},
{
Name: "status",
Aliases: []string{"s"},
Usage: "Get status about open migrations and which was run last",
Action: func(c *cli.Context) error {
cfg := scriptup.GetConfig(c.String("env"))
return scriptup.Status(cfg)
},
},
}
return app
}