Repository: helm/helm (go)

Issue:
Feature request: a `helm version` option that works consistently across v2 and v3
I am consuming Helm programmatically and sometimes need to issue slightly different command syntax according to whether the user has Helm 2 or Helm 3.  I can try to detect this using `helm version` _but_...

* On Helm 2, `helm version` attempts to reach Tiller, which is potentially slow.  I can avoid this with `helm version -c` but...
* On Helm 3, `helm version -c` is an error.
* On Helm 2, `helm version --short` returns a string of the form `Client: v2.14.3+g0e7f3b6` (plus server info which can be suppress with `-c`)
* On Helm 3, `helm version --short` returns a string of the form `v3.0.0-beta.2+g26c7338` (no `Client: ` prefix)

All this makes detecting v2 vs v3 a bit fiddly.  I could issue `helm version -c` and assume v3 if I get an error, but perhaps it would be nice to continue to support `-c` as a hidden flag and have it force the output to the same format as v2?




Pull request:
fix(version): implement `helm version -c`, mark as hidden
This has been requested by multiple users, and incurs no additional maintenance on our end, so I'm re-opening this for further discussion/debate.

Users are struggling to find a solution to this problem. No alternative solutions have been reached. This is the best solution as discussed at this time. IMO I'd rather have a half-baked solution that works for community members than no solution. Having this in for Helm 3 will reduce friction for adopting Helm 3 in third party tools like the [VSCode Kubernetes Extension](https://github.com/Azure/vscode-kubernetes-tools) and in [helmfile](https://github.com/roboll/helmfile).

this is identical to #6670, just re-opened against `master` after the big branch switch.
closes #6322

Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>

Patch:
diff --git a/cmd/helm/version.go b/cmd/helm/version.go
index 8c0c11484..3067f7289 100644
--- a/cmd/helm/version.go
+++ b/cmd/helm/version.go
@@ -61,6 +61,8 @@ func newVersionCmd(out io.Writer) *cobra.Command {
 	f := cmd.Flags()
 	f.BoolVar(&o.short, "short", false, "print the version number")
 	f.StringVar(&o.template, "template", "", "template for version string format")
+	f.BoolP("client", "c", true, "display client version information")
+	f.MarkHidden("client")
 
 	return cmd
 }


Test patch:
diff --git a/cmd/helm/testdata/output/version-client-shorthand.txt b/cmd/helm/testdata/output/version-client-shorthand.txt
new file mode 100644
index 000000000..0d9b536e6
--- /dev/null
+++ b/cmd/helm/testdata/output/version-client-shorthand.txt
@@ -0,0 +1,1 @@
+version.BuildInfo{Version:"v3.0+unreleased", GitCommit:"", GitTreeState:"", GoVersion:""}
diff --git a/cmd/helm/testdata/output/version-client.txt b/cmd/helm/testdata/output/version-client.txt
new file mode 100644
index 000000000..0d9b536e6
--- /dev/null
+++ b/cmd/helm/testdata/output/version-client.txt
@@ -0,0 +1,1 @@
+version.BuildInfo{Version:"v3.0+unreleased", GitCommit:"", GitTreeState:"", GoVersion:""}
diff --git a/cmd/helm/version_test.go b/cmd/helm/version_test.go
index 89b89093e..134401948 100644
--- a/cmd/helm/version_test.go
+++ b/cmd/helm/version_test.go
@@ -32,6 +32,14 @@ func TestVersion(t *testing.T) {
 		name:   "template",
 		cmd:    "version --template='Version: {{.Version}}'",
 		golden: "output/version-template.txt",
+	}, {
+		name:   "client",
+		cmd:    "version --client",
+		golden: "output/version-client.txt",
+	}, {
+		name:   "client shorthand",
+		cmd:    "version -c",
+		golden: "output/version-client-shorthand.txt",
 	}}
 	runTestCmd(t, tests)
 }