migrate activitylog from urfave/cli to spf13/cobra

Signed-off-by: Christian Richter <c.richter@opencloud.eu>
This commit is contained in:
Christian Richter
2025-12-15 16:40:25 +01:00
committed by Florian Schade
parent 4dcecbf5c0
commit 783503851e
5 changed files with 44 additions and 33 deletions
+13
View File
@@ -1,10 +1,14 @@
package clihelper
import (
"fmt"
"github.com/opencloud-eu/opencloud/pkg/version"
"github.com/spf13/cobra"
"github.com/urfave/cli/v2"
)
// DefaultApp provides some default settings for the cli app
func DefaultApp(app *cli.App) *cli.App {
// version info
app.Version = version.String
@@ -24,3 +28,12 @@ func DefaultApp(app *cli.App) *cli.App {
return app
}
// DefaultAppCobra is a wrapper for DefaultApp that adds Cobra specific settings
func DefaultAppCobra(app *cobra.Command) *cobra.Command {
// TODO: when migration is done this has to become DefaultApp
// version info
app.Version = fmt.Sprintf("%s (%s <%s>) (%s)", version.String, "OpenCloud GmbH", "support@opencloud.eu", version.Compiled())
return app
}
+7 -7
View File
@@ -2,16 +2,16 @@ package command
import (
"github.com/opencloud-eu/opencloud/services/activitylog/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 {
// Not implemented
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
},
}
+9 -9
View File
@@ -5,12 +5,12 @@ import (
"github.com/opencloud-eu/opencloud/pkg/clihelper"
"github.com/opencloud-eu/opencloud/services/activitylog/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,11 @@ func GetCommands(cfg *config.Config) cli.Commands {
// Execute is the entry point for the activitylog command.
func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "activitylog",
Usage: "starts activitylog service",
Commands: GetCommands(cfg),
app := clihelper.DefaultAppCobra(&cobra.Command{
Use: "activitylog",
Short: "starts activitylog service",
})
return app.RunContext(cfg.Context, os.Args)
app.AddCommand(GetCommands(cfg)...)
app.SetArgs(os.Args[1:])
return app.ExecuteContext(cfg.Context)
}
+9 -10
View File
@@ -9,7 +9,7 @@ import (
"github.com/opencloud-eu/reva/v2/pkg/events/stream"
"github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool"
"github.com/opencloud-eu/reva/v2/pkg/store"
"github.com/urfave/cli/v2"
"github.com/spf13/cobra"
microstore "go-micro.dev/v4/store"
"github.com/opencloud-eu/opencloud/pkg/config/configlog"
@@ -47,24 +47,23 @@ 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 {
logger.Error().Err(err).Msg("Failed to initialize tracer")
return err
}
gr := run.Group{}
ctx, cancel := context.WithCancel(c.Context)
ctx, cancel := context.WithCancel(cmd.Context())
mtrcs := metrics.New()
mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1)
+6 -7
View File
@@ -2,16 +2,15 @@ package command
import (
"github.com/opencloud-eu/opencloud/services/activitylog/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
},