Passed
Pull Request — master (#31)
by Stefano
02:08
created

pkg/cmd/version.go   A

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 24
dl 0
loc 41
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A cmd.NewVersionCommand 0 17 2
1
package cmd
2
3
import (
4
	"fmt"
5
	"io"
6
7
	"github.com/spf13/cobra"
8
)
9
10
var (
11
	Version   string
0 ignored issues
show
introduced by
exported var Version should have comment or be unexported
Loading history...
12
	BuildTime string
13
)
14
15
func init() {
16
	if Version == "" {
17
		Version = "dev"
18
	}
19
20
	if BuildTime == "" {
21
		BuildTime = "now"
22
	}
23
}
24
25
func NewVersionCommand(out io.Writer) *cobra.Command {
0 ignored issues
show
introduced by
exported function NewVersionCommand should have comment or be unexported
Loading history...
26
	cmd := &cobra.Command{
27
		Use:   "version",
28
		Short: "Print the current version",
29
		Run: func(cmd *cobra.Command, args []string) {
30
			fmt.Fprintln(
31
				out,
32
				fmt.Sprintf("Version: %s", Version),
33
			)
34
			fmt.Fprintln(
35
				out,
36
				fmt.Sprintf("Built at: %s", BuildTime),
37
			)
38
		},
39
	}
40
41
	return cmd
42
}
43