forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
60 lines (50 loc) · 1.33 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cmd
import (
"fmt"
"io"
"github.com/spf13/cobra"
cmdutil "github.com/jenkins-x/jx/pkg/jx/cmd/util"
"github.com/jenkins-x/jx/pkg/version"
)
func NewCmdVersion(f cmdutil.Factory, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Print the version information",
Run: func(cmd *cobra.Command, args []string) {
err := RunVersion(f, out, cmd)
cmdutil.CheckErr(err)
},
}
/*
cmd.Flags().BoolP("client", "c", false, "Client version only (no server required).")
cmd.Flags().BoolP("short", "", false, "Print just the version number.")
*/
cmd.Flags().MarkShorthandDeprecated("client", "please use --client instead.")
return cmd
}
func RunVersion(f cmdutil.Factory, out io.Writer, cmd *cobra.Command) error {
v := fmt.Sprintf("%#v", version.GetVersion())
/*
if cmdutil.GetFlagBool(cmd, "short") {
v = version.Get().GitVersion
}
fmt.Fprintf(out, "Client Version: %s\n", v)
if cmdutil.GetFlagBool(cmd, "client") {
return nil
}
clientset, err := f.ClientSet()
if err != nil {
return err
}
serverVersion, err := clientset.Discovery().ServerVersion()
if err != nil {
return err
}
v = fmt.Sprintf("%#v", *serverVersion)
if cmdutil.GetFlagBool(cmd, "short") {
v = serverVersion.GitVersion
}
*/
fmt.Fprintf(out, "Server Version: %s\n", v)
return nil
}