-
Notifications
You must be signed in to change notification settings - Fork 1
/
down_cmd.go
47 lines (37 loc) · 897 Bytes
/
down_cmd.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
package cobracmd
import (
"errors"
"fmt"
"strconv"
"github.com/iamsalnikov/mymigrate"
"github.com/spf13/cobra"
)
// DownCmd is a cobra command that applies new migrations
var DownCmd = &cobra.Command{
Use: "down",
Short: "down number of migrations",
RunE: DownRunE,
}
// DownRunE is a cobra run function for DownCmd command
func DownRunE(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("please pass count of migrations to down")
}
number, err := strconv.Atoi(args[0])
if err != nil {
return err
}
list, err := mymigrate.Down(number)
if err != nil {
return err
}
if len(list) == 0 {
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "There is nothing to down")
return nil
}
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "List of downed migrations:")
for _, mig := range list {
_, _ = fmt.Fprintln(cmd.OutOrStdout(), mig)
}
return nil
}