From f4526d4bc878e3c4efe6b3eb9d96a36de1c24516 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 2 Dec 2025 13:20:57 +0100 Subject: [PATCH] migrate clientlog from urfave/cli to spf13/cobra Signed-off-by: Christian Richter --- services/clientlog/pkg/command/health.go | 13 ++++++------ services/clientlog/pkg/command/root.go | 18 ++++++++-------- services/clientlog/pkg/command/server.go | 25 +++++++++++------------ services/clientlog/pkg/command/version.go | 14 ++++++------- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/services/clientlog/pkg/command/health.go b/services/clientlog/pkg/command/health.go index a120eaf505..379b3416ed 100644 --- a/services/clientlog/pkg/command/health.go +++ b/services/clientlog/pkg/command/health.go @@ -2,15 +2,16 @@ package command import ( "github.com/opencloud-eu/opencloud/services/clientlog/pkg/config" - "github.com/urfave/cli/v2" + + "github.com/spf13/cobra" ) // Health is the entrypoint for the health command. -func Health(cfg *config.Config) *cli.Command { - return &cli.Command{ - Name: "health", - Usage: "Check health status", - Action: func(c *cli.Context) error { +func Health(cfg *config.Config) *cobra.Command { + return &cobra.Command{ + Use: "health", + Short: "Check health status", + RunE: func(cmd *cobra.Command, args []string) error { // Not implemented return nil }, diff --git a/services/clientlog/pkg/command/root.go b/services/clientlog/pkg/command/root.go index 8cfc0d1e57..38d8ea9e10 100644 --- a/services/clientlog/pkg/command/root.go +++ b/services/clientlog/pkg/command/root.go @@ -5,12 +5,13 @@ import ( "github.com/opencloud-eu/opencloud/pkg/clihelper" "github.com/opencloud-eu/opencloud/services/clientlog/pkg/config" - "github.com/urfave/cli/v2" + + "github.com/spf13/cobra" ) // GetCommands provides all commands for this service -func GetCommands(cfg *config.Config) cli.Commands { - return []*cli.Command{ +func GetCommands(cfg *config.Config) []*cobra.Command { + return []*cobra.Command{ // start this service Server(cfg), @@ -24,11 +25,12 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the clientlog command. func Execute(cfg *config.Config) error { - app := clihelper.DefaultApp(&cli.App{ - Name: "clientlog", - Usage: "starts clientlog service", - Commands: GetCommands(cfg), + app := clihelper.DefaultAppCobra(&cobra.Command{ + Use: "clientlog", + Short: "starts clientlog service", }) + app.AddCommand(GetCommands(cfg)...) + app.SetArgs(os.Args[1:]) - return app.RunContext(cfg.Context, os.Args) + return app.ExecuteContext(cfg.Context) } diff --git a/services/clientlog/pkg/command/server.go b/services/clientlog/pkg/command/server.go index 41bc8b24da..6156255837 100644 --- a/services/clientlog/pkg/command/server.go +++ b/services/clientlog/pkg/command/server.go @@ -5,11 +5,6 @@ import ( "fmt" "os/signal" - "github.com/opencloud-eu/reva/v2/pkg/events" - "github.com/opencloud-eu/reva/v2/pkg/events/stream" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - "github.com/urfave/cli/v2" - "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/generators" "github.com/opencloud-eu/opencloud/pkg/registry" @@ -22,6 +17,11 @@ import ( "github.com/opencloud-eu/opencloud/services/clientlog/pkg/metrics" "github.com/opencloud-eu/opencloud/services/clientlog/pkg/server/debug" "github.com/opencloud-eu/opencloud/services/clientlog/pkg/service" + "github.com/opencloud-eu/reva/v2/pkg/events" + "github.com/opencloud-eu/reva/v2/pkg/events/stream" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" + + "github.com/spf13/cobra" ) // all events we care about @@ -47,17 +47,16 @@ var _registeredEvents = []events.Unmarshaller{ } // Server is the entrypoint for the server command. -func Server(cfg *config.Config) *cli.Command { - return &cli.Command{ - Name: "server", - Usage: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name), - Category: "server", - Before: func(c *cli.Context) error { +func Server(cfg *config.Config) *cobra.Command { + return &cobra.Command{ + Use: "server", + Short: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name), + PreRunE: func(cmd *cobra.Command, args []string) error { return configlog.ReturnFatal(parser.ParseConfig(cfg)) }, - Action: func(c *cli.Context) error { + RunE: func(cmd *cobra.Command, args []string) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) - tracerProvider, err := tracing.GetTraceProvider(c.Context, cfg.Commons.TracesExporter, cfg.Service.Name) + tracerProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name) if err != nil { return err } diff --git a/services/clientlog/pkg/command/version.go b/services/clientlog/pkg/command/version.go index 284b5fa181..bdeec714d1 100644 --- a/services/clientlog/pkg/command/version.go +++ b/services/clientlog/pkg/command/version.go @@ -2,16 +2,16 @@ package command import ( "github.com/opencloud-eu/opencloud/services/clientlog/pkg/config" - "github.com/urfave/cli/v2" + + "github.com/spf13/cobra" ) // 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 { +func Version(cfg *config.Config) *cobra.Command { + return &cobra.Command{ + Use: "version", + Short: "print the version of this binary and the running service instances", + RunE: func(cmd *cobra.Command, args []string) error { // not implemented return nil },