| Total Lines | 41 |
| 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 | 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 { |
||
| 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 |