Unverified Commit cff4ea41 authored by Sunny's avatar Sunny

feat(helm): add --template flag to `helm version`

`helm version --template` prints the client and server version info in
the provided template format.
parent 460dbe93
......@@ -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()
fmt.Fprintf(v.out, "Client: %s\n", formatVersion(cv, v.short))
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")
}
fmt.Fprintf(v.out, "Server: %s\n", formatVersion(resp.Version, v.short))
return nil
if v.template != "" {
data["Server"] = resp.Version
} else {
fmt.Fprintf(v.out, "Server: %s\n", formatVersion(resp.Version, v.short))
}
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment