-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from kubefirst/go-cli-v0.0.2
Add check tools and update outputs
- Loading branch information
Showing
15 changed files
with
515 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.