[gh#carrier-38] [feat] GOOBE work. Check dependencies before any action.
Verify that all required external commands are available before attempting any action.
@@ -4,7 +4,9 @@ import (
"errors"
"fmt"
"os"
+ "os/exec"
+ "github.com/kyokomi/emoji"
"github.com/spf13/cobra"
)
@@ -17,6 +19,8 @@ var kubeconfig string
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
+ ExitfIfError(checkDependencies(), "Cannot operate")
+
rootCmd := &cobra.Command{
Use: "carrier",
Short: "Carrier cli",
@@ -42,3 +46,28 @@ func ensureKubeConfig() error {
return nil
}
+
+func checkDependencies() error {
+ ok := true
+
+ dependencies := []struct {
+ CommandName string
+ }{
+ {CommandName: "kubectl"},
+ {CommandName: "helm"},
+ }
+
+ for _, dependency := range dependencies {
+ _, err := exec.LookPath(dependency.CommandName)
+ if err != nil {
+ fmt.Println(emoji.Sprintf(":fire:Not found: %s", dependency.CommandName))
+ ok = false
+ }
+ }
+
+ if ok {
+ return nil
+ }
+
+ return errors.New("Please check your PATH, some of our dependencies were not found")
+}
