-
Notifications
You must be signed in to change notification settings - Fork 46
/
restart.go
42 lines (33 loc) · 1.23 KB
/
restart.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
package commands
import (
"github.com/spf13/cobra"
)
// KoolRestartFlags holds the flags for the kool restart command
type KoolRestartFlags struct {
Purge bool
Rebuild bool
}
// NewRestartCommand initializes new kool start command
func NewRestartCommand(stop KoolService, start KoolService) (restartCmd *cobra.Command) {
var flags *KoolRestartFlags = &KoolRestartFlags{false, false}
restartCmd = &cobra.Command{
Use: "restart",
Short: "Restart running service containers (the same as 'kool stop' followed by 'kool start')",
RunE: func(cmd *cobra.Command, args []string) error {
if _, ok := stop.(*KoolStop); ok && flags.Purge {
stop.(*KoolStop).Flags.Purge = true
}
if _, ok := start.(*KoolStart); ok && flags.Rebuild {
start.(*KoolStart).Flags.Rebuild = true
}
return DefaultCommandRunFunction(stop, start)(cmd, args)
},
DisableFlagsInUseLine: true,
}
restartCmd.Flags().BoolVarP(&flags.Purge, "purge", "", false, "Remove all persistent data from volume mounts on containers")
restartCmd.Flags().BoolVarP(&flags.Rebuild, "rebuild", "", false, "Updates and builds service's images")
return
}
func AddKoolRestart(root *cobra.Command) {
root.AddCommand(NewRestartCommand(NewKoolStop(), NewKoolStart()))
}