From 0372869b8b6e9507feb7844b21710e2901ec5780 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 4 Dec 2025 10:11:06 +0100 Subject: [PATCH] refactor remaining code from urfave/cli Signed-off-by: Christian Richter --- opencloud/pkg/runtime/options.go | 9 --------- pkg/service/http/option.go | 7 ++++--- pkg/service/http/service.go | 3 ++- services/activitylog/pkg/server/http/option.go | 9 +++++---- services/auth-app/pkg/server/http/option.go | 9 +++++---- services/graph/pkg/server/http/option.go | 14 +++++++------- services/idp/pkg/server/http/option.go | 9 +++++---- services/invitations/pkg/server/http/option.go | 9 +++++---- services/ocs/pkg/server/http/option.go | 9 +++++---- services/proxy/pkg/server/http/option.go | 11 ++++++----- services/settings/pkg/server/http/option.go | 9 +++++---- services/thumbnails/pkg/server/http/option.go | 12 ++++++++++-- services/userlog/pkg/server/http/option.go | 9 +++++---- services/web/pkg/server/http/option.go | 12 ++++++++++-- services/webdav/pkg/server/http/option.go | 9 +++++---- services/webfinger/pkg/server/http/option.go | 15 +++++++++++---- 16 files changed, 90 insertions(+), 65 deletions(-) diff --git a/opencloud/pkg/runtime/options.go b/opencloud/pkg/runtime/options.go index cfebd47f94..aa354743ab 100644 --- a/opencloud/pkg/runtime/options.go +++ b/opencloud/pkg/runtime/options.go @@ -2,14 +2,12 @@ package runtime import ( "github.com/opencloud-eu/opencloud/pkg/log" - "github.com/urfave/cli/v2" ) // Options is a runtime option type Options struct { Services []string Logger log.Logger - Context *cli.Context } // Option undocumented @@ -21,10 +19,3 @@ func Services(s []string) Option { o.Services = append(o.Services, s...) } } - -// Context option -func Context(c *cli.Context) Option { - return func(o *Options) { - o.Context = c - } -} diff --git a/pkg/service/http/option.go b/pkg/service/http/option.go index c495966e3c..604d23cfec 100644 --- a/pkg/service/http/option.go +++ b/pkg/service/http/option.go @@ -6,7 +6,8 @@ import ( "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/pkg/shared" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" "go.opentelemetry.io/otel/trace" ) @@ -23,7 +24,7 @@ type Options struct { Address string Handler http.Handler Context context.Context - Flags []cli.Flag + Flags []pflag.Flag TraceProvider trace.TracerProvider } @@ -83,7 +84,7 @@ func Context(ctx context.Context) Option { } // Flags provides a function to set the flags option. -func Flags(flags ...cli.Flag) Option { +func Flags(flags ...pflag.Flag) Option { return func(o *Options) { o.Flags = append(o.Flags, flags...) } diff --git a/pkg/service/http/service.go b/pkg/service/http/service.go index cf3b9d94e0..ae8d67082f 100644 --- a/pkg/service/http/service.go +++ b/pkg/service/http/service.go @@ -62,7 +62,8 @@ func NewService(opts ...Option) (Service, error) { micro.Name(strings.Join([]string{sopts.Namespace, sopts.Name}, ".")), micro.Version(sopts.Version), micro.Context(sopts.Context), - micro.Flags(sopts.Flags...), + // TODO: clarify if this is actually used on the go-micro side + //micro.Flags(sopts.Flags...), micro.Registry(registry.GetRegistry()), micro.RegisterTTL(registry.GetRegisterTTL()), micro.RegisterInterval(registry.GetRegisterInterval()), diff --git a/services/activitylog/pkg/server/http/option.go b/services/activitylog/pkg/server/http/option.go index 652053145d..6fb3d5cf5c 100644 --- a/services/activitylog/pkg/server/http/option.go +++ b/services/activitylog/pkg/server/http/option.go @@ -11,7 +11,8 @@ import ( "github.com/opencloud-eu/opencloud/services/activitylog/pkg/metrics" "github.com/opencloud-eu/reva/v2/pkg/events" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" "go-micro.dev/v4/store" "go.opentelemetry.io/otel/trace" ) @@ -25,7 +26,7 @@ type Options struct { Context context.Context Config *config.Config Metrics *metrics.Metrics - Flags []cli.Flag + Flags []pflag.Flag Namespace string Store store.Store Stream events.Stream @@ -76,9 +77,9 @@ func Metrics(val *metrics.Metrics) Option { } // Flags provides a function to set the flags option. -func Flags(val []cli.Flag) Option { +func Flags(flags ...pflag.Flag) Option { return func(o *Options) { - o.Flags = append(o.Flags, val...) + o.Flags = append(o.Flags, flags...) } } diff --git a/services/auth-app/pkg/server/http/option.go b/services/auth-app/pkg/server/http/option.go index b0e3b88fb1..7fb3778a59 100644 --- a/services/auth-app/pkg/server/http/option.go +++ b/services/auth-app/pkg/server/http/option.go @@ -8,7 +8,8 @@ import ( settingssvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/settings/v0" "github.com/opencloud-eu/opencloud/services/auth-app/pkg/config" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" "go.opentelemetry.io/otel/trace" ) @@ -20,7 +21,7 @@ type Options struct { Logger log.Logger Context context.Context Config *config.Config - Flags []cli.Flag + Flags []pflag.Flag Namespace string GatewaySelector pool.Selectable[gateway.GatewayAPIClient] RoleClient settingssvc.RoleService @@ -60,9 +61,9 @@ func Config(val *config.Config) Option { } // Flags provides a function to set the flags option. -func Flags(val []cli.Flag) Option { +func Flags(flags ...pflag.Flag) Option { return func(o *Options) { - o.Flags = append(o.Flags, val...) + o.Flags = append(o.Flags, flags...) } } diff --git a/services/graph/pkg/server/http/option.go b/services/graph/pkg/server/http/option.go index a8df4fdecc..350edbad29 100644 --- a/services/graph/pkg/server/http/option.go +++ b/services/graph/pkg/server/http/option.go @@ -3,13 +3,13 @@ package http import ( "context" - "github.com/nats-io/nats.go/jetstream" - "github.com/urfave/cli/v2" - "go.opentelemetry.io/otel/trace" - "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/graph/pkg/config" "github.com/opencloud-eu/opencloud/services/graph/pkg/metrics" + + "github.com/nats-io/nats.go/jetstream" + "github.com/spf13/pflag" + "go.opentelemetry.io/otel/trace" ) // Option defines a single option function. @@ -21,7 +21,7 @@ type Options struct { Context context.Context Config *config.Config Metrics *metrics.Metrics - Flags []cli.Flag + Flags []pflag.Flag Namespace string TraceProvider trace.TracerProvider NatsKeyValue jetstream.KeyValue @@ -67,9 +67,9 @@ func Metrics(val *metrics.Metrics) Option { } // Flags provides a function to set the flags option. -func Flags(val []cli.Flag) Option { +func Flags(flags ...pflag.Flag) Option { return func(o *Options) { - o.Flags = append(o.Flags, val...) + o.Flags = append(o.Flags, flags...) } } diff --git a/services/idp/pkg/server/http/option.go b/services/idp/pkg/server/http/option.go index 1c1b60cdaa..7e897ee2fa 100644 --- a/services/idp/pkg/server/http/option.go +++ b/services/idp/pkg/server/http/option.go @@ -6,7 +6,8 @@ import ( "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/idp/pkg/config" "github.com/opencloud-eu/opencloud/services/idp/pkg/metrics" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" "go.opentelemetry.io/otel/trace" ) @@ -20,7 +21,7 @@ type Options struct { Context context.Context Config *config.Config Metrics *metrics.Metrics - Flags []cli.Flag + Flags []pflag.Flag TraceProvider trace.TracerProvider } @@ -64,9 +65,9 @@ func Metrics(val *metrics.Metrics) Option { } // Flags provides a function to set the flags option. -func Flags(val []cli.Flag) Option { +func Flags(flags ...pflag.Flag) Option { return func(o *Options) { - o.Flags = append(o.Flags, val...) + o.Flags = append(o.Flags, flags...) } } diff --git a/services/invitations/pkg/server/http/option.go b/services/invitations/pkg/server/http/option.go index 3c3204f7f5..30a73f8e17 100644 --- a/services/invitations/pkg/server/http/option.go +++ b/services/invitations/pkg/server/http/option.go @@ -6,7 +6,8 @@ import ( "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/invitations/pkg/config" svc "github.com/opencloud-eu/opencloud/services/invitations/pkg/service/v0" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" ) // Option defines a single option function. @@ -19,7 +20,7 @@ type Options struct { Logger log.Logger Context context.Context Config *config.Config - Flags []cli.Flag + Flags []pflag.Flag Service svc.Service } @@ -63,9 +64,9 @@ func Config(val *config.Config) Option { } // Flags provides a function to set the flags option. -func Flags(val []cli.Flag) Option { +func Flags(flags ...pflag.Flag) Option { return func(o *Options) { - o.Flags = append(o.Flags, val...) + o.Flags = append(o.Flags, flags...) } } diff --git a/services/ocs/pkg/server/http/option.go b/services/ocs/pkg/server/http/option.go index 3ec05cd75c..00a52efb84 100644 --- a/services/ocs/pkg/server/http/option.go +++ b/services/ocs/pkg/server/http/option.go @@ -6,7 +6,8 @@ import ( "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/ocs/pkg/config" "github.com/opencloud-eu/opencloud/services/ocs/pkg/metrics" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" "go.opentelemetry.io/otel/trace" ) @@ -20,7 +21,7 @@ type Options struct { Context context.Context Config *config.Config Metrics *metrics.Metrics - Flags []cli.Flag + Flags []pflag.Flag TraceProvider trace.TracerProvider } @@ -64,9 +65,9 @@ func Metrics(val *metrics.Metrics) Option { } // Flags provides a function to set the flags option. -func Flags(val []cli.Flag) Option { +func Flags(flags ...pflag.Flag) Option { return func(o *Options) { - o.Flags = append(o.Flags, val...) + o.Flags = append(o.Flags, flags...) } } diff --git a/services/proxy/pkg/server/http/option.go b/services/proxy/pkg/server/http/option.go index 28e3d06267..c7ba8bad76 100644 --- a/services/proxy/pkg/server/http/option.go +++ b/services/proxy/pkg/server/http/option.go @@ -4,11 +4,12 @@ import ( "context" "net/http" - "github.com/justinas/alice" "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/proxy/pkg/config" "github.com/opencloud-eu/opencloud/services/proxy/pkg/metrics" - "github.com/urfave/cli/v2" + + "github.com/justinas/alice" + "github.com/spf13/pflag" ) // Option defines a single option function. @@ -21,7 +22,7 @@ type Options struct { Config *config.Config Handler http.Handler Metrics *metrics.Metrics - Flags []cli.Flag + Flags []pflag.Flag Middlewares alice.Chain } @@ -65,9 +66,9 @@ func Metrics(val *metrics.Metrics) Option { } // Flags provides a function to set the flags option. -func Flags(val []cli.Flag) Option { +func Flags(flags ...pflag.Flag) Option { return func(o *Options) { - o.Flags = append(o.Flags, val...) + o.Flags = append(o.Flags, flags...) } } diff --git a/services/settings/pkg/server/http/option.go b/services/settings/pkg/server/http/option.go index 1293259eb5..f92ac3b582 100644 --- a/services/settings/pkg/server/http/option.go +++ b/services/settings/pkg/server/http/option.go @@ -7,7 +7,8 @@ import ( "github.com/opencloud-eu/opencloud/services/settings/pkg/config" "github.com/opencloud-eu/opencloud/services/settings/pkg/metrics" "github.com/opencloud-eu/opencloud/services/settings/pkg/settings" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" "go.opentelemetry.io/otel/trace" ) @@ -22,7 +23,7 @@ type Options struct { Config *config.Config Metrics *metrics.Metrics ServiceHandler settings.ServiceHandler - Flags []cli.Flag + Flags []pflag.Flag TraceProvider trace.TracerProvider } @@ -73,9 +74,9 @@ func Metrics(val *metrics.Metrics) Option { } // Flags provides a function to set the flags option. -func Flags(val []cli.Flag) Option { +func Flags(flags ...pflag.Flag) Option { return func(o *Options) { - o.Flags = append(o.Flags, val...) + o.Flags = append(o.Flags, flags...) } } diff --git a/services/thumbnails/pkg/server/http/option.go b/services/thumbnails/pkg/server/http/option.go index b840bfb9fd..480510a7b6 100644 --- a/services/thumbnails/pkg/server/http/option.go +++ b/services/thumbnails/pkg/server/http/option.go @@ -6,7 +6,8 @@ import ( "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/thumbnails/pkg/config" "github.com/opencloud-eu/opencloud/services/thumbnails/pkg/metrics" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace/noop" ) @@ -21,7 +22,7 @@ type Options struct { Context context.Context Config *config.Config Metrics *metrics.Metrics - Flags []cli.Flag + Flags []pflag.Flag TraceProvider trace.TracerProvider } @@ -81,3 +82,10 @@ func TraceProvider(traceProvider trace.TracerProvider) Option { } } } + +// Flags provides a function to set the flags option. +func Flags(flags ...pflag.Flag) Option { + return func(o *Options) { + o.Flags = append(o.Flags, flags...) + } +} diff --git a/services/userlog/pkg/server/http/option.go b/services/userlog/pkg/server/http/option.go index b6ce605c97..aee27b1258 100644 --- a/services/userlog/pkg/server/http/option.go +++ b/services/userlog/pkg/server/http/option.go @@ -11,7 +11,8 @@ import ( "github.com/opencloud-eu/opencloud/services/userlog/pkg/metrics" "github.com/opencloud-eu/reva/v2/pkg/events" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" "go-micro.dev/v4/store" "go.opentelemetry.io/otel/trace" ) @@ -25,7 +26,7 @@ type Options struct { Context context.Context Config *config.Config Metrics *metrics.Metrics - Flags []cli.Flag + Flags []pflag.Flag Namespace string Store store.Store Stream events.Stream @@ -77,9 +78,9 @@ func Metrics(val *metrics.Metrics) Option { } // Flags provides a function to set the flags option. -func Flags(val []cli.Flag) Option { +func Flags(flags ...pflag.Flag) Option { return func(o *Options) { - o.Flags = append(o.Flags, val...) + o.Flags = append(o.Flags, flags...) } } diff --git a/services/web/pkg/server/http/option.go b/services/web/pkg/server/http/option.go index 1187cb4b9e..16e4c5f7db 100644 --- a/services/web/pkg/server/http/option.go +++ b/services/web/pkg/server/http/option.go @@ -6,7 +6,8 @@ import ( "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/web/pkg/config" "github.com/opencloud-eu/opencloud/services/web/pkg/metrics" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" "go.opentelemetry.io/otel/trace" ) @@ -19,7 +20,7 @@ type Options struct { Context context.Context Config *config.Config Metrics *metrics.Metrics - Flags []cli.Flag + Flags []pflag.Flag Namespace string TraceProvider trace.TracerProvider } @@ -76,3 +77,10 @@ func TraceProvider(val trace.TracerProvider) Option { o.TraceProvider = val } } + +// Flags provides a function to set the flags option. +func Flags(flags ...pflag.Flag) Option { + return func(o *Options) { + o.Flags = append(o.Flags, flags...) + } +} diff --git a/services/webdav/pkg/server/http/option.go b/services/webdav/pkg/server/http/option.go index 56859aef7c..0128c54f08 100644 --- a/services/webdav/pkg/server/http/option.go +++ b/services/webdav/pkg/server/http/option.go @@ -6,7 +6,8 @@ import ( "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/webdav/pkg/config" "github.com/opencloud-eu/opencloud/services/webdav/pkg/metrics" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" "go.opentelemetry.io/otel/trace" ) @@ -20,7 +21,7 @@ type Options struct { Context context.Context Config *config.Config Metrics *metrics.Metrics - Flags []cli.Flag + Flags []pflag.Flag TraceProvider trace.TracerProvider } @@ -64,9 +65,9 @@ func Metrics(val *metrics.Metrics) Option { } // Flags provides a function to set the flags option. -func Flags(val []cli.Flag) Option { +func Flags(flags ...pflag.Flag) Option { return func(o *Options) { - o.Flags = append(o.Flags, val...) + o.Flags = append(o.Flags, flags...) } } diff --git a/services/webfinger/pkg/server/http/option.go b/services/webfinger/pkg/server/http/option.go index 5f9b9153e1..8dee2722b7 100644 --- a/services/webfinger/pkg/server/http/option.go +++ b/services/webfinger/pkg/server/http/option.go @@ -3,13 +3,13 @@ package http import ( "context" - "go.opentelemetry.io/otel/trace/noop" - "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/webfinger/pkg/config" svc "github.com/opencloud-eu/opencloud/services/webfinger/pkg/service/v0" - "github.com/urfave/cli/v2" + + "github.com/spf13/pflag" "go.opentelemetry.io/otel/trace" + "go.opentelemetry.io/otel/trace/noop" ) // Option defines a single option function. @@ -22,7 +22,7 @@ type Options struct { Logger log.Logger Context context.Context Config *config.Config - Flags []cli.Flag + Flags []pflag.Flag Service svc.Service TraceProvider trace.TracerProvider } @@ -66,6 +66,13 @@ func Service(val svc.Service) Option { } } +// Flags provides a function to set the flags option. +func Flags(flags ...pflag.Flag) Option { + return func(o *Options) { + o.Flags = append(o.Flags, flags...) + } +} + // TraceProvider provides a function to configure the trace provider func TraceProvider(traceProvider trace.TracerProvider) Option { return func(o *Options) {