From 4bcc4b9ab31b2d8e495a26ec755bbbeef30ed40f Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 2 Dec 2025 12:42:04 +0100 Subject: [PATCH] migrate audit from urfave/cli to spf13/cobra Signed-off-by: Christian Richter --- services/audit/pkg/command/health.go | 12 ++++++------ services/audit/pkg/command/root.go | 17 +++++++++-------- services/audit/pkg/command/server.go | 21 ++++++++++----------- services/audit/pkg/command/version.go | 13 ++++++------- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/services/audit/pkg/command/health.go b/services/audit/pkg/command/health.go index b4e5e23da..59958f782 100644 --- a/services/audit/pkg/command/health.go +++ b/services/audit/pkg/command/health.go @@ -2,15 +2,15 @@ package command import ( "github.com/opencloud-eu/opencloud/services/audit/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/audit/pkg/command/root.go b/services/audit/pkg/command/root.go index db06c145c..447ab9270 100644 --- a/services/audit/pkg/command/root.go +++ b/services/audit/pkg/command/root.go @@ -5,12 +5,12 @@ import ( "github.com/opencloud-eu/opencloud/pkg/clihelper" "github.com/opencloud-eu/opencloud/services/audit/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 +24,12 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the audit command. func Execute(cfg *config.Config) error { - app := clihelper.DefaultApp(&cli.App{ - Name: "audit", - Usage: "starts audit service", - Commands: GetCommands(cfg), + app := clihelper.DefaultAppCobra(&cobra.Command{ + Use: "audit", + Short: "starts audit 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/audit/pkg/command/server.go b/services/audit/pkg/command/server.go index 1a8bce1a5..4ce05241d 100644 --- a/services/audit/pkg/command/server.go +++ b/services/audit/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/runner" @@ -18,18 +14,21 @@ import ( "github.com/opencloud-eu/opencloud/services/audit/pkg/server/debug" svc "github.com/opencloud-eu/opencloud/services/audit/pkg/service" "github.com/opencloud-eu/opencloud/services/audit/pkg/types" + "github.com/opencloud-eu/reva/v2/pkg/events" + "github.com/opencloud-eu/reva/v2/pkg/events/stream" + + "github.com/spf13/cobra" ) // 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...) diff --git a/services/audit/pkg/command/version.go b/services/audit/pkg/command/version.go index 52b33d8e8..fbcfa24aa 100644 --- a/services/audit/pkg/command/version.go +++ b/services/audit/pkg/command/version.go @@ -2,16 +2,15 @@ package command import ( "github.com/opencloud-eu/opencloud/services/audit/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 },