Merge pull request #2720 from darkowlzz/formatversion-json

feat(helm): add --template flag to `helm version`
pull/3499/head
Matthew Fisher 7 years ago committed by GitHub
commit 4506b393ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -55,6 +55,7 @@ type versionCmd struct {
showClient bool
showServer bool
short bool
template string
}
func newVersionCmd(c helm.Interface, out io.Writer) *cobra.Command {
@ -85,18 +86,26 @@ func newVersionCmd(c helm.Interface, out io.Writer) *cobra.Command {
f.BoolVarP(&version.showClient, "client", "c", false, "client version only")
f.BoolVarP(&version.showServer, "server", "s", false, "server version only")
f.BoolVar(&version.short, "short", false, "print the version number")
f.StringVar(&version.template, "template", "", "template for version string format")
return cmd
}
func (v *versionCmd) run() error {
// Store map data for template rendering
data := map[string]interface{}{}
if v.showClient {
cv := version.GetVersionProto()
if v.template != "" {
data["Client"] = cv
} else {
fmt.Fprintf(v.out, "Client: %s\n", formatVersion(cv, v.short))
}
}
if !v.showServer {
return nil
return tpl(v.template, data, v.out)
}
if settings.Debug {
@ -115,8 +124,13 @@ func (v *versionCmd) run() error {
debug("%s", err)
return errors.New("cannot connect to Tiller")
}
if v.template != "" {
data["Server"] = resp.Version
} else {
fmt.Fprintf(v.out, "Server: %s\n", formatVersion(resp.Version, v.short))
return nil
}
return tpl(v.template, data, v.out)
}
func getK8sVersion() (*apiVersion.Info, error) {

@ -38,6 +38,7 @@ func TestVersion(t *testing.T) {
{"default", true, true, []string{}, false},
{"client", true, false, []string{"-c"}, false},
{"server", false, true, []string{"-s"}, false},
{"template", true, true, []string{"--template='{{ .Client.SemVer }} {{ .Server.SemVer }}'"}, false},
}
settings.TillerHost = "fake-localhost"

@ -33,6 +33,7 @@ helm version
-c, --client client version only
-s, --server server version only
--short print the version number
--template string template for version string format
--tls enable TLS for request
--tls-ca-cert string path to TLS CA certificate file (default "$HELM_HOME/ca.pem")
--tls-cert string path to TLS certificate file (default "$HELM_HOME/cert.pem")
@ -53,4 +54,4 @@ helm version
### SEE ALSO
* [helm](helm.md) - The Helm package manager for Kubernetes.
###### Auto generated by spf13/cobra on 25-Jan-2018
###### Auto generated by spf13/cobra on 11-Feb-2018

Loading…
Cancel
Save