Support the legacy client flag for better backward compatibility

Signed-off-by: Ryan SIU <ryan.siu@cloverhealth.com>
pull/6368/head
Ryan SIU 6 years ago
parent 5cb923eecb
commit 243fc9352a

@ -0,0 +1 @@
Client: version.BuildInfo{Version:"v3.0+unreleased", GitCommit:"", GitTreeState:"", GoVersion:""}

@ -0,0 +1 @@
Client: v3.0+unreleased

@ -43,6 +43,7 @@ version.BuildInfo{Version:"v2.0.0", GitCommit:"ff52399e51bb880526e9cd0ed8386f643
type versionOptions struct {
short bool
client bool
template string
}
@ -60,6 +61,7 @@ func newVersionCmd(out io.Writer) *cobra.Command {
}
f := cmd.Flags()
f.BoolVar(&o.short, "short", false, "print the version number")
f.BoolVarP(&o.client, "client", "c", false, "print the version number")
f.StringVar(&o.template, "template", "", "template for version string format")
return cmd
@ -73,17 +75,21 @@ func (o *versionOptions) run(out io.Writer) error {
}
return tt.Execute(out, version.Get())
}
fmt.Fprintln(out, formatVersion(o.short))
fmt.Fprintln(out, formatVersion(o.short, o.client))
return nil
}
func formatVersion(short bool) string {
func formatVersion(short bool, client bool) string {
v := version.Get()
pre := ""
if client {
pre = "Client: "
}
if short {
if len(v.GitCommit) >= 7 {
return fmt.Sprintf("%s+g%s", v.Version, v.GitCommit[:7])
return fmt.Sprintf("%s%s+g%s", pre, v.Version, v.GitCommit[:7])
}
return version.GetVersion()
return fmt.Sprintf("%s%s", pre, version.GetVersion())
}
return fmt.Sprintf("%#v", v)
return fmt.Sprintf("%s%#v", pre, v)
}

@ -32,6 +32,14 @@ func TestVersion(t *testing.T) {
name: "template",
cmd: "version --template='Version: {{.Version}}'",
golden: "output/version-template.txt",
}, {
name: "short with client",
cmd: "version --short -c",
golden: "output/version-short-client.txt",
}, {
name: "client",
cmd: "version -c",
golden: "output/version-client.txt",
}}
runTestCmd(t, tests)
}

Loading…
Cancel
Save