/
oakCheck.go
60 lines (51 loc) · 1.69 KB
/
oakCheck.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
package commands
import (
"github.com/jlentink/aem/internal/aem"
"github.com/jlentink/aem/internal/cli/oak"
"github.com/jlentink/aem/internal/cli/project"
"github.com/jlentink/aem/internal/output"
"github.com/spf13/cobra"
"os"
)
type commandOakCheck struct {
verbose bool
instanceName string
aemVersion string
oakVersion string
}
func (c *commandOakCheck) setup() *cobra.Command {
cmd := &cobra.Command{
Use: "check",
Aliases: []string{},
Short: "Run oak check",
PreRun: c.preRun,
Run: c.run,
}
cmd.Flags().StringVarP(&c.instanceName, "name", "n", aem.GetDefaultInstanceName(), "Instance to stop")
cmd.Flags().StringVarP(&c.aemVersion, "aem", "a", ``, "Version of AEM to use oak-run on. (use matching AEM version of oak-run)")
cmd.Flags().StringVarP(&c.oakVersion, "oak", "o", ``, "Define version of oak-run to use")
cmd.MarkFlagRequired("name") // nolint: errcheck
return cmd
}
func (c *commandOakCheck) preRun(cmd *cobra.Command, args []string) {
c.verbose, _ = cmd.Flags().GetBool("verbose")
output.SetVerbose(verbose)
ConfigCheckListProjects()
RegisterProject()
}
func (c *commandOakCheck) run(cmd *cobra.Command, args []string) {
_, i, errorString, err := getConfigAndInstance(c.instanceName)
if err != nil {
output.Printf(output.NORMAL, errorString, err.Error())
os.Exit(ExitError)
}
instancePath, err := project.GetRunDirLocation(*i)
if err != nil {
output.Printf(output.NORMAL, errorString, err.Error())
os.Exit(ExitError)
}
oak.SetDefaultVersion(aem.Cnf.OakVersion)
path, _ := oak.Get(i.GetVersion(), aem.Cnf.OakVersion)
oakArgs := []string{"check", instancePath + oak.RepoPath}
oak.Execute(path, aem.Cnf.OakOptions, oakArgs) // nolint: errcheck
}