add missing commands and unify service / namespace options

This commit is contained in:
Willy Kloucek
2021-11-24 18:30:20 +01:00
parent de87f3160d
commit 6206fe2398
66 changed files with 515 additions and 218 deletions

View File

@@ -0,0 +1,47 @@
package command
import (
"fmt"
"os"
"github.com/owncloud/ocis/ocis-pkg/registry"
tw "github.com/olekukonko/tablewriter"
"github.com/owncloud/ocis/web/pkg/config"
"github.com/urfave/cli/v2"
)
// PrintVersion prints the service versions of all running instances.
func PrintVersion(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "version",
Usage: "Print the versions of the running instances",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
},
Action: func(c *cli.Context) error {
reg := registry.GetRegistry()
services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name)
if err != nil {
fmt.Println(fmt.Errorf("could not get web services from the registry: %v", err))
return err
}
if len(services) == 0 {
fmt.Println("No running web service found.")
return nil
}
table := tw.NewWriter(os.Stdout)
table.SetHeader([]string{"Version", "Address", "Id"})
table.SetAutoFormatHeaders(false)
for _, s := range services {
for _, n := range s.Nodes {
table.Append([]string{s.Version, n.Address, n.Id})
}
}
table.Render()
return nil
},
}
}