/
bundleStop.go
76 lines (66 loc) · 2.16 KB
/
bundleStop.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
package commands
import (
"github.com/jlentink/aem/internal/aem"
"github.com/jlentink/aem/internal/aem/bundle"
"github.com/jlentink/aem/internal/output"
"github.com/spf13/cobra"
"os"
)
type commandBundelStop struct {
verbose bool
instanceName string
instanceGroup string
bundle string
}
func (c *commandBundelStop) setup() *cobra.Command {
cmd := &cobra.Command{
Use: "stop",
Short: "Stop bundle",
PreRun: c.preRun,
Run: c.run,
}
cmd.Flags().StringVarP(&c.instanceName, "name", "n", aem.GetDefaultInstanceName(), "Instance to install bundle on")
cmd.Flags().StringVarP(&c.instanceGroup, "group", "g", ``, "Instance group to install bundle on")
cmd.Flags().StringVarP(&c.bundle, "bundle", "b", ``, "Instance group to install bundle on")
return cmd
}
func (c *commandBundelStop) preRun(cmd *cobra.Command, args []string) {
c.verbose, _ = cmd.Flags().GetBool("verbose")
output.SetVerbose(c.verbose)
ConfigCheckListProjects()
RegisterProject()
}
func (c *commandBundelStop) run(cmd *cobra.Command, args []string) {
_, is, errorString, err := getConfigAndInstanceOrGroupWithRoles(c.instanceName, c.instanceGroup, []string{aem.RoleAuthor, aem.RolePublisher})
if err != nil {
output.Printf(output.NORMAL, errorString, err.Error())
os.Exit(ExitError)
}
for idx, i := range is {
i := i
if idx == 0 && c.bundle == "" {
bundleObject, err := bundle.Search(&i, "Stopping")
if err != nil {
output.Printf(output.NORMAL, "Could not list bundles: %s", err.Error())
os.Exit(ExitError)
}
c.bundle = bundleObject.SymbolicName
}
bndl, err := bundle.Get(&i, c.bundle)
if err != nil {
output.Printf(output.NORMAL, "Could not find bundle on: %s", i.Name)
os.Exit(ExitError)
}
b, err := bundle.Stop(&i, bndl)
if err != nil {
output.Printf(output.NORMAL, "Could not stop bundle %s", err.Error())
os.Exit(ExitError)
}
if b.StateRaw == 32 {
output.Printf(output.NORMAL, "\U0001F631 Bundle %s - %s\n", b.SymbolicName, bundle.BundleRawState[b.StateRaw])
os.Exit(ExitError)
}
output.Printf(output.NORMAL, "\U00002705 Bundle %s - %s\n", b.SymbolicName, bundle.BundleRawState[b.StateRaw])
os.Exit(ExitNormal)
}
}