()
| 28 | var VersionCmd *cobra.Command |
| 29 | |
| 30 | func init() { |
| 31 | var json bool |
| 32 | var short bool |
| 33 | |
| 34 | VersionCmd = &cobra.Command{ |
| 35 | Args: cobra.NoArgs, |
| 36 | Use: "version", |
| 37 | Short: "Print version information", |
| 38 | RunE: func(cmd *cobra.Command, args []string) error { |
| 39 | var info *version.VersionInfo |
| 40 | var err error |
| 41 | if info, err = version.ComputeInfo(); err != nil { |
| 42 | return err |
| 43 | } |
| 44 | |
| 45 | out := cmd.OutOrStdout() |
| 46 | switch { |
| 47 | case json: |
| 48 | return j.NewEncoder(out).Encode(info) |
| 49 | case short: |
| 50 | _, err := fmt.Fprint(out, info.Version) |
| 51 | return err |
| 52 | default: |
| 53 | _, err := fmt.Fprint(out, info) |
| 54 | return err |
| 55 | } |
| 56 | }, |
| 57 | } |
| 58 | |
| 59 | VersionCmd.Flags().BoolVarP(&json, "json", "j", false, "JSON output") |
| 60 | VersionCmd.Flags().BoolVarP(&short, "short", "s", false, "Only output the version") |
| 61 | } |
nothing calls this directly
no test coverage detected