Version prints the service versions of all running instances.
(cfg *config.Config)
| 15 | |
| 16 | // Version prints the service versions of all running instances. |
| 17 | func Version(cfg *config.Config) *cobra.Command { |
| 18 | return &cobra.Command{ |
| 19 | Use: "version", |
| 20 | Short: "print the version of this binary and the running service instances", |
| 21 | RunE: func(cmd *cobra.Command, args []string) error { |
| 22 | fmt.Println("Version: " + version.GetString()) |
| 23 | fmt.Printf("Compiled: %s\n", version.Compiled()) |
| 24 | fmt.Println("") |
| 25 | |
| 26 | reg := registry.GetRegistry() |
| 27 | services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) |
| 28 | if err != nil { |
| 29 | fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) |
| 30 | return err |
| 31 | } |
| 32 | |
| 33 | if len(services) == 0 { |
| 34 | fmt.Println("No running " + cfg.Service.Name + " service found.") |
| 35 | return nil |
| 36 | } |
| 37 | |
| 38 | table := tablewriter.NewTable(os.Stdout, tablewriter.WithHeaderAutoFormat(tw.Off)) |
| 39 | table.Header([]string{"Version", "Address", "Id"}) |
| 40 | for _, s := range services { |
| 41 | for _, n := range s.Nodes { |
| 42 | table.Append([]string{s.Version, n.Address, n.Id}) |
| 43 | } |
| 44 | } |
| 45 | table.Render() |
| 46 | return nil |
| 47 | }, |
| 48 | } |
| 49 | } |
no test coverage detected