VersionCommand is the entrypoint for the version command.
(cfg *config.Config)
| 22 | |
| 23 | // VersionCommand is the entrypoint for the version command. |
| 24 | func VersionCommand(cfg *config.Config) *cobra.Command { |
| 25 | versionCmd := &cobra.Command{ |
| 26 | Use: "version", |
| 27 | Short: "print the version of this binary and all running service instances", |
| 28 | GroupID: CommandGroupServer, |
| 29 | RunE: func(cmd *cobra.Command, args []string) error { |
| 30 | fmt.Println("Version: " + version.GetString()) |
| 31 | fmt.Printf("Edition: %s\n", version.Edition) |
| 32 | fmt.Printf("Compiled: %s\n", version.Compiled()) |
| 33 | |
| 34 | skipServiceListing, _ := cmd.Flags().GetBool(_skipServiceListingFlagName) |
| 35 | if skipServiceListing { |
| 36 | return nil |
| 37 | } |
| 38 | |
| 39 | fmt.Print("\n") |
| 40 | |
| 41 | reg := registry.GetRegistry() |
| 42 | serviceList, err := reg.ListServices() |
| 43 | if err != nil { |
| 44 | fmt.Printf("could not list services: %v\n", err) |
| 45 | return err |
| 46 | } |
| 47 | |
| 48 | var services []*mreg.Service |
| 49 | for _, s := range serviceList { |
| 50 | s, err := reg.GetService(s.Name) |
| 51 | if err != nil { |
| 52 | fmt.Printf("could not get service: %v\n", err) |
| 53 | return err |
| 54 | } |
| 55 | services = append(services, s...) |
| 56 | } |
| 57 | |
| 58 | if len(services) == 0 { |
| 59 | fmt.Println("No running services found.") |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | table := tablewriter.NewTable(os.Stdout, tablewriter.WithHeaderAutoFormat(tw.Off)) |
| 64 | table.Header([]string{"Version", "Address", "Id"}) |
| 65 | for _, s := range services { |
| 66 | for _, n := range s.Nodes { |
| 67 | table.Append([]string{s.Version, n.Address, n.Id}) |
| 68 | } |
| 69 | } |
| 70 | table.Render() |
| 71 | return nil |
| 72 | }, |
| 73 | } |
| 74 | versionCmd.Flags().Bool(_skipServiceListingFlagName, false, "skip service listing") |
| 75 | return versionCmd |
| 76 | } |
| 77 | |
| 78 | func init() { |
| 79 | register.AddCommand(VersionCommand) |
nothing calls this directly
no test coverage detected