Files

49 lines
1.4 KiB
Go
Raw Permalink Normal View History

2024-03-21 10:13:22 +01:00
package command
import (
"fmt"
"os"
"github.com/olekukonko/tablewriter"
2024-03-21 10:13:22 +01:00
"github.com/owncloud/ocis/v2/ocis-pkg/registry"
"github.com/owncloud/ocis/v2/ocis-pkg/version"
"github.com/owncloud/ocis/v2/services/collaboration/pkg/config"
"github.com/urfave/cli/v2"
)
// Version prints the service versions of all running instances.
func Version(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "version",
Usage: "print the version of this binary and the running service instances",
Category: "info",
Action: func(c *cli.Context) error {
fmt.Println("Version: " + version.GetString())
fmt.Printf("Compiled: %s\n", version.Compiled())
fmt.Println("")
reg := registry.GetRegistry()
services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name + "." + cfg.App.Name)
2024-03-21 10:13:22 +01:00
if err != nil {
fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name+"."+cfg.App.Name, err))
2024-03-21 10:13:22 +01:00
return err
}
if len(services) == 0 {
fmt.Println("No running " + cfg.Service.Name + "." + cfg.App.Name + " service found.")
2024-03-21 10:13:22 +01:00
return nil
}
table := tablewriter.NewTable(os.Stdout)
table.Header("Version", "Address", "Id")
2024-03-21 10:13:22 +01:00
for _, s := range services {
for _, n := range s.Nodes {
table.Append([]string{s.Version, n.Address, n.Id})
}
}
table.Render()
return nil
},
}
}