From 46e3499a47feac0bf05d0583a5d699421af7fe37 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Thu, 8 Feb 2024 15:24:40 +0100 Subject: [PATCH] enhancement: allow skipping service listing --- .../enhancement-skip-version-service-listing | 7 +++++ ocis/pkg/command/version.go | 30 ++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 changelog/unreleased/enhancement-skip-version-service-listing diff --git a/changelog/unreleased/enhancement-skip-version-service-listing b/changelog/unreleased/enhancement-skip-version-service-listing new file mode 100644 index 000000000..b1e774105 --- /dev/null +++ b/changelog/unreleased/enhancement-skip-version-service-listing @@ -0,0 +1,7 @@ +Enhancement: allow to skip service listing + +The ocis version cmd listed all services by default. This is not always intended, +so we allow to skip the listing of the services by using the --skip-services flag. + +https://github.com/owncloud/ocis/pull/8408 +https://github.com/owncloud/ocis/issues/8070 diff --git a/ocis/pkg/command/version.go b/ocis/pkg/command/version.go index 3e251f953..e4c351b2f 100644 --- a/ocis/pkg/command/version.go +++ b/ocis/pkg/command/version.go @@ -5,29 +5,45 @@ import ( "os" tw "github.com/olekukonko/tablewriter" + "github.com/urfave/cli/v2" + mreg "go-micro.dev/v4/registry" + "github.com/owncloud/ocis/v2/ocis-pkg/config" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/ocis/pkg/register" - "github.com/urfave/cli/v2" - mreg "go-micro.dev/v4/registry" +) + +const ( + _skipServiceListingFlagName = "skip-services" ) // VersionCommand is the entrypoint for the version command. func VersionCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "version", - Usage: "print the version of this binary and all running service instances", + Name: "version", + Usage: "print the version of this binary and all running service instances", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: _skipServiceListingFlagName, + Usage: "skip service listing", + }, + }, Category: "info", Action: func(c *cli.Context) error { fmt.Println("Version: " + version.GetString()) fmt.Printf("Compiled: %s\n", version.Compiled()) - fmt.Println("") + + if c.Bool(_skipServiceListingFlagName) { + return nil + } + + fmt.Print("\n") reg := registry.GetRegistry() serviceList, err := reg.ListServices() if err != nil { - fmt.Println(fmt.Errorf("could not list services: %v", err)) + fmt.Printf("could not list services: %v\n", err) return err } @@ -35,7 +51,7 @@ func VersionCommand(cfg *config.Config) *cli.Command { for _, s := range serviceList { s, err := reg.GetService(s.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get service: %v", err)) + fmt.Printf("could not get service: %v\n", err) return err } services = append(services, s...)