pkg/cmd/version.go   A
last analyzed

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 25
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A cmd.NewVersionCommand 0 20 2
A cmd.init 0 7 3
1
package cmd
2
3
import (
4
	"fmt"
5
	"io"
6
7
	"github.com/spf13/cobra"
8
)
9
10
var (
11
	Version   string
12
	BuildTime string
13
)
14
15
//nolint:gochecknoinits
16
func init() {
17
	if Version == "" {
18
		Version = "dev"
19
	}
20
21
	if BuildTime == "" {
22
		BuildTime = "now"
23
	}
24
}
25
26
func NewVersionCommand(out io.Writer) *cobra.Command {
27
	cmd := &cobra.Command{
28
		Use:   "version",
29
		Short: "Print the current version",
30
		RunE: func(cmd *cobra.Command, args []string) error {
31
			_, _ = fmt.Fprintln(
32
				out,
33
				fmt.Sprintf("Version: %s", Version),
34
			)
35
36
			_, _ = fmt.Fprintln(
37
				out,
38
				fmt.Sprintf("Built at: %s", BuildTime),
39
			)
40
41
			return nil
42
		},
43
	}
44
45
	return cmd
46
}
47