-
Notifications
You must be signed in to change notification settings - Fork 1
/
version.go
47 lines (39 loc) · 831 Bytes
/
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
package cmd
import (
"errors"
"fmt"
"github.com/spf13/cobra"
"io"
)
const appLabel = "kubectl server-version"
var version string
// SetVersion set the application version for consumption in the output of the command.
func SetVersion(v string) {
version = v
}
type versionCmd struct {
out io.Writer
}
func newVersionCmd(out io.Writer) *cobra.Command {
version := &versionCmd{
out: out,
}
cmd := &cobra.Command{
Use: "version",
Short: "print the version number and exit",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return errors.New("this command does not accept arguments")
}
return version.run()
},
}
return cmd
}
func (v *versionCmd) run() error {
_, err := fmt.Fprintf(v.out, "%s %s\n", appLabel, version)
if err != nil {
return err
}
return nil
}