Skip to content

Commit

Permalink
Merge pull request #68 from kubefirst/go-cli-v0.0.2
Browse files Browse the repository at this point in the history
Add check tools and update outputs
  • Loading branch information
6za authored Jul 4, 2022
2 parents 643070f + 97b5e70 commit a98418a
Show file tree
Hide file tree
Showing 15 changed files with 515 additions and 330 deletions.
12 changes: 12 additions & 0 deletions cmd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ General overview of the code, to help shuffling parts around.
|cfgFile|String| .flare config file|
|NebolousVersion|String|CLI version|


# Commands Available

| Command | Short Description | Long Description|
|:---|:---|:---|
|checktools|Present, needs review.|Present, needs review.|
|clean|Missing Text|Missing Text|
|create|Missing Text|Missing Text|
|destroy|Missing Text|Missing Text|
|info|Present, needs review.|Present, needs review.|
|init|Missing Text|Missing Text|
|version|Present, needs review.|Present, needs review.|
56 changes: 56 additions & 0 deletions cmd/checktools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"
"log"
"bytes"
"os/exec"
"github.com/spf13/cobra"
)

// checktoolsCmd represents the checktools command
var checktoolsCmd = &cobra.Command{
Use: "checktools",
Short: "use to check compatibility of .kubefirst/tools",
Long: `Execute a compatibility check of the tools downloaded by the installer.
Execute After callint "init". If executed before init, tools will not be available.
`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Checking the tools installed used by installer:")

kubectlVersion, kubectlStdErr,errKubectl := execShellReturnStrings(kubectlClientPath, "version", "--client", "--short")
fmt.Printf("-> kubectl version:\n\t%s\n\t%s\n",kubectlVersion,kubectlStdErr)
terraformVersion, terraformStdErr,errTerraform := execShellReturnStrings(terraformPath, "version")
fmt.Printf("-> terraform version:\n\t%s\n\t%s\n",terraformVersion,terraformStdErr)
helmVersion, helmStdErr,errHelm := execShellReturnStrings(helmClientPath, "version", "--client", "--short")
fmt.Printf("-> helm version:\n\t%s\n\t%s\n",helmVersion,helmStdErr)

if errKubectl != nil {
fmt.Println("failed to call kubectlVersionCmd.Run(): %v", errKubectl)
}
if errHelm != nil {
fmt.Println("failed to call helmVersionCmd.Run(): %v", errHelm)
}
if errTerraform != nil {
fmt.Println("failed to call terraformVersionCmd.Run(): %v", errTerraform)
}

},
}

func init() {
rootCmd.AddCommand(checktoolsCmd)
}
func execShellReturnStrings(command string, args ...string) (string, string, error) {
var outb, errb bytes.Buffer
k := exec.Command(command, args...)
k.Stdout = &outb
k.Stderr = &errb
err := k.Run()
log.Println("Error executing command: %v", err)
return outb.String(), errb.String(), err
}
Loading

0 comments on commit a98418a

Please sign in to comment.