Skip to content

Commit

Permalink
Instance init => validate
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Nov 15, 2024
1 parent 15b0e1b commit 2a59862
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
16 changes: 8 additions & 8 deletions cmd/aem/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (c *CLI) instanceCmd() *cobra.Command {
cmd.AddCommand(c.instanceListCmd())
cmd.AddCommand(c.instanceAwaitCmd())
cmd.AddCommand(c.instanceBackupCmd())
cmd.AddCommand(c.instanceInitCmd())
cmd.AddCommand(c.instanceValidateCmd())
cmd.AddCommand(c.instanceImportCmd())
return cmd
}
Expand Down Expand Up @@ -335,19 +335,19 @@ func (c *CLI) instanceListCmd() *cobra.Command {
}
}

func (c *CLI) instanceInitCmd() *cobra.Command {
func (c *CLI) instanceValidateCmd() *cobra.Command {
return &cobra.Command{
Use: "init",
Aliases: []string{"initialize"},
Short: "Init prerequisites for AEM instance(s)",
Use: "validate",
Aliases: []string{"verify"},
Short: "Validate prerequisites for AEM instance(s)",
Run: func(cmd *cobra.Command, args []string) {
if err := c.aem.InstanceManager().LocalOpts.Initialize(); err != nil {
if err := c.aem.InstanceManager().LocalOpts.Validate(); err != nil {
c.Error(err)
return
}

c.SetOutput("initialized", true)
c.Changed("initialized prerequisites for instance(s)")
c.SetOutput("validated", true)
c.Changed("Validated prerequisites for instance(s)")
},
}
}
19 changes: 13 additions & 6 deletions cmd/aem/vendor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -19,20 +20,22 @@ func (c *CLI) vendorCmd() *cobra.Command {
func (c *CLI) vendorListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List all prepared vendors",
Short: "List vendor tools available",
Aliases: []string{"ls"},
Run: func(cmd *cobra.Command, args []string) {
errored := false

javaHome, err := c.aem.VendorManager().JavaManager().FindHomeDir()
if err != nil {
c.Error(err)
return
errored = true
log.Warnf("java home not available: %s", err)
}
c.SetOutput("javaHome", javaHome)

javaExecutable, err := c.aem.VendorManager().JavaManager().Executable()
if err != nil {
c.Error(err)
return
errored = true
log.Warnf("java executable not available: %s", err)
}
c.SetOutput("javaExecutable", javaExecutable)

Expand All @@ -42,7 +45,11 @@ func (c *CLI) vendorListCmd() *cobra.Command {
oakRunJar := c.aem.VendorManager().OakRun().JarFile()
c.setOutput("oakRunJar", oakRunJar)

c.Ok("vendors listed")
if errored {
c.Fail("vendor tool listed with errors")
} else {
c.Ok("vendor tools listed")
}
},
}
return cmd
Expand Down
6 changes: 3 additions & 3 deletions pkg/local_instance_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewLocalOpts(manager *InstanceManager) *LocalOpts {
return result
}

func (o *LocalOpts) Initialize() error {
func (o *LocalOpts) Validate() error {
// validate phase (fast feedback)
if err := o.validateUnpackDir(); err != nil {
return err
Expand Down Expand Up @@ -127,7 +127,7 @@ func (im *InstanceManager) CreateAll() ([]Instance, error) {

func (im *InstanceManager) Create(instances []Instance) ([]Instance, error) {
created := []Instance{}
if err := im.LocalOpts.Initialize(); err != nil {
if err := im.LocalOpts.Validate(); err != nil {
return created, err
}
log.Info(InstancesMsg(instances, "creating"))
Expand Down Expand Up @@ -202,7 +202,7 @@ func (im *InstanceManager) Start(instances []Instance) ([]Instance, error) {
log.Debugf("no instances to start")
return []Instance{}, nil
}
if err := im.LocalOpts.Initialize(); err != nil {
if err := im.LocalOpts.Validate(); err != nil {
return []Instance{}, err
}

Expand Down

0 comments on commit 2a59862

Please sign in to comment.