Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |