29 lines
593 B
Go
29 lines
593 B
Go
package kubectl
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
type toolClientVersion struct {
|
|
GitVersion string `json:"gitVersion"`
|
|
}
|
|
|
|
type toolVersion struct {
|
|
ClientVersion toolClientVersion `json:"clientVersion"`
|
|
}
|
|
|
|
func (this KubectlCommand) GetVersion() (string, error) {
|
|
|
|
cmd := this.Exec(this.Bin, "version", "-o", "json", "--client=true")
|
|
stdout, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
var objmap toolVersion
|
|
|
|
json.Unmarshal(stdout, &objmap)
|
|
res := objmap.ClientVersion.GitVersion
|
|
|
|
return res, nil
|
|
} |