/
activationTree.go
66 lines (58 loc) · 2 KB
/
activationTree.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
package commands
import (
"github.com/jlentink/aem/internal/aem"
"github.com/jlentink/aem/internal/aem/replication"
"github.com/jlentink/aem/internal/output"
"github.com/spf13/cobra"
"os"
)
type commandActivateTree struct {
verbose bool
instanceName string
instanceGroup string
path string
ignoreDeactivate bool
onlyModified bool
}
func (c *commandActivateTree) setup() *cobra.Command {
cmd := &cobra.Command{
Use: "tree",
Short: "Activate Tree",
PreRun: c.preRun,
Run: c.run,
}
cmd.Flags().StringVarP(&c.instanceName, "name", "n", aem.GetDefaultInstanceName(), "Instance to (de)activate page on")
cmd.Flags().StringVarP(&c.instanceGroup, "group", "g", ``, "Instance group to (de)activate page on")
cmd.Flags().StringVarP(&c.path, "path", "p", ``, "Path to (de)activate")
cmd.Flags().BoolVarP(&c.ignoreDeactivate, "ignore-deactivated", "d", false, "Ignore Deactivated")
cmd.Flags().BoolVarP(&c.onlyModified, "only-modified", "o", false, "Only Modified")
cmd.MarkFlagRequired("path") // nolint: errcheck
return cmd
}
func (c *commandActivateTree) preRun(cmd *cobra.Command, args []string) {
c.verbose, _ = cmd.Flags().GetBool("verbose")
output.SetVerbose(c.verbose)
ConfigCheckListProjects()
RegisterProject()
}
func (c *commandActivateTree) run(cmd *cobra.Command, args []string) {
_, is, errorString, err := getConfigAndInstanceOrGroupWithRoles(c.instanceName, c.instanceGroup, []string{aem.RoleAuthor})
if err != nil {
output.Printf(output.NORMAL, errorString, err.Error())
os.Exit(ExitError)
}
if len(c.path) == 0 {
output.Printf(output.NORMAL, "no path provided")
os.Exit(ExitError)
}
for _, i := range is {
i := i
body, err := replication.ActivateTree(&i, c.path, c.ignoreDeactivate, c.onlyModified)
if err != nil {
output.Printf(output.NORMAL, "Could not activate tree: %s", err.Error())
os.Exit(ExitError)
}
output.Printf(output.NORMAL, "\U00002705 tree activated: %s\n", c.path)
output.Printf(output.VERBOSE, "%s", body)
}
}