NewVersionCommand creates and returns the cobra command for displaying version information.
()
| 16 | |
| 17 | // NewVersionCommand creates and returns the cobra command for displaying version information. |
| 18 | func NewVersionCommand() *cobra.Command { |
| 19 | cmd := &cobra.Command{ |
| 20 | Use: "version", |
| 21 | Short: "Print the client version information for the current context", |
| 22 | Long: "Print the client version information for the current context", |
| 23 | Run: func(_ *cobra.Command, _ []string) { |
| 24 | var versionContent string |
| 25 | if Version != "" { |
| 26 | versionContent += fmt.Sprintf("Version: %s\n", Version) |
| 27 | } |
| 28 | if BuildGoVersion != "" { |
| 29 | versionContent += fmt.Sprintf("GoVersion: %s\n", BuildGoVersion) |
| 30 | } |
| 31 | if BuildTime != "" { |
| 32 | versionContent += fmt.Sprintf("BuildTime: %s\n", BuildTime) |
| 33 | } |
| 34 | if versionContent == "" { |
| 35 | versionContent = "Version: (dev)\n" |
| 36 | } |
| 37 | fmt.Printf("%s", versionContent) |
| 38 | }, |
| 39 | } |
| 40 | return cmd |
| 41 | } |
no outgoing calls