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

cmd.NewVersionCommand   A

Complexity

Conditions 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nop 1
dl 0
loc 17
rs 9.8
c 0
b 0
f 0
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