From 1024830d1383d9d0836fb148c91ae76a99a41448 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 2 Dec 2025 17:08:27 +0100 Subject: [PATCH] migrate sse from urfave/cli to spf13/cobra Signed-off-by: Christian Richter --- services/sse/pkg/command/health.go | 20 +++++++++----------- services/sse/pkg/command/root.go | 19 ++++++++++--------- services/sse/pkg/command/server.go | 23 +++++++++++------------ services/sse/pkg/command/version.go | 16 +++++++--------- 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/services/sse/pkg/command/health.go b/services/sse/pkg/command/health.go index d385f26dbd..0eafc3e406 100644 --- a/services/sse/pkg/command/health.go +++ b/services/sse/pkg/command/health.go @@ -4,25 +4,23 @@ import ( "fmt" "net/http" - "github.com/opencloud-eu/opencloud/pkg/log" - - "github.com/urfave/cli/v2" - "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/sse/pkg/config" "github.com/opencloud-eu/opencloud/services/sse/pkg/config/parser" + + "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", - Category: "info", - Before: func(c *cli.Context) error { +func Health(cfg *config.Config) *cobra.Command { + return &cobra.Command{ + Use: "health", + Short: "check health status", + PreRunE: func(cmd *cobra.Command, args []string) error { return configlog.ReturnError(parser.ParseConfig(cfg)) }, - Action: func(c *cli.Context) error { + RunE: func(cmd *cobra.Command, args []string) error { logger := log.NewLogger( log.Name(cfg.Service.Name), log.Level(cfg.Log.Level), diff --git a/services/sse/pkg/command/root.go b/services/sse/pkg/command/root.go index 85082333e3..82b90791e9 100644 --- a/services/sse/pkg/command/root.go +++ b/services/sse/pkg/command/root.go @@ -3,15 +3,15 @@ package command import ( "os" - "github.com/urfave/cli/v2" - "github.com/opencloud-eu/opencloud/pkg/clihelper" "github.com/opencloud-eu/opencloud/services/sse/pkg/config" + + "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{ Server(cfg), Health(cfg), Version(cfg), @@ -20,11 +20,12 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the sse command. func Execute(cfg *config.Config) error { - app := clihelper.DefaultApp(&cli.App{ - Name: "sse", - Usage: "Serve sse for OpenCloud", - Commands: GetCommands(cfg), + app := clihelper.DefaultAppCobra(&cobra.Command{ + Use: "sse", + Short: "Serve sse for OpenCloud", }) + 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/sse/pkg/command/server.go b/services/sse/pkg/command/server.go index 60708f29dc..feef04961c 100644 --- a/services/sse/pkg/command/server.go +++ b/services/sse/pkg/command/server.go @@ -5,10 +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/urfave/cli/v2" - "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/generators" "github.com/opencloud-eu/opencloud/pkg/log" @@ -18,6 +14,10 @@ import ( "github.com/opencloud-eu/opencloud/services/sse/pkg/config/parser" "github.com/opencloud-eu/opencloud/services/sse/pkg/server/debug" "github.com/opencloud-eu/opencloud/services/sse/pkg/server/http" + "github.com/opencloud-eu/reva/v2/pkg/events" + "github.com/opencloud-eu/reva/v2/pkg/events/stream" + + "github.com/spf13/cobra" ) // all events we care about @@ -26,15 +26,14 @@ 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 { var cancel context.CancelFunc if cfg.Context == nil { cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) @@ -50,7 +49,7 @@ func Server(cfg *config.Config) *cli.Command { log.File(cfg.Log.File), ) - 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/sse/pkg/command/version.go b/services/sse/pkg/command/version.go index c7e0a2d9c8..a144e5029a 100644 --- a/services/sse/pkg/command/version.go +++ b/services/sse/pkg/command/version.go @@ -4,19 +4,17 @@ import ( "fmt" "github.com/opencloud-eu/opencloud/pkg/version" - - "github.com/urfave/cli/v2" - "github.com/opencloud-eu/opencloud/services/sse/pkg/config" + + "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 { fmt.Println("Version: " + version.GetString()) fmt.Printf("Compiled: %s\n", version.Compiled()) fmt.Println("")