diff --git a/services/collaboration/cmd/collaboration/main.go b/services/collaboration/cmd/collaboration/main.go new file mode 100644 index 000000000..64571354f --- /dev/null +++ b/services/collaboration/cmd/collaboration/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "context" + "os" + "os/signal" + "syscall" + + "github.com/opencloud-eu/opencloud/services/activitylog/pkg/command" + "github.com/opencloud-eu/opencloud/services/activitylog/pkg/config/defaults" +) + +func main() { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) + if err := command.Execute(cfg); err != nil { + os.Exit(1) + } +} diff --git a/services/collaboration/pkg/command/health.go b/services/collaboration/pkg/command/health.go index e85436ea0..35e8414d4 100644 --- a/services/collaboration/pkg/command/health.go +++ b/services/collaboration/pkg/command/health.go @@ -8,19 +8,19 @@ import ( "github.com/opencloud-eu/opencloud/services/collaboration/pkg/config" "github.com/opencloud-eu/opencloud/services/collaboration/pkg/config/parser" "github.com/opencloud-eu/opencloud/services/collaboration/pkg/logging" - "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", - 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 := logging.Configure(cfg.Service.Name, cfg.Log) resp, err := http.Get( diff --git a/services/collaboration/pkg/command/root.go b/services/collaboration/pkg/command/root.go index 402bba75f..779287dba 100644 --- a/services/collaboration/pkg/command/root.go +++ b/services/collaboration/pkg/command/root.go @@ -5,12 +5,13 @@ import ( "github.com/opencloud-eu/opencloud/pkg/clihelper" "github.com/opencloud-eu/opencloud/services/collaboration/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{ Server(cfg), Health(cfg), Version(cfg), @@ -19,11 +20,12 @@ func GetCommands(cfg *config.Config) cli.Commands { // Execute is the entry point for the antivirus command. func Execute(cfg *config.Config) error { - app := clihelper.DefaultApp(&cli.App{ - Name: "collaboration", - Usage: "Serve WOPI for OpenCloud", - Commands: GetCommands(cfg), + app := clihelper.DefaultAppCobra(&cobra.Command{ + Use: "collaboration", + Short: "Serve WOPI 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/collaboration/pkg/command/server.go b/services/collaboration/pkg/command/server.go index e6f3e135d..ea47dabe3 100644 --- a/services/collaboration/pkg/command/server.go +++ b/services/collaboration/pkg/command/server.go @@ -7,9 +7,6 @@ import ( "os/signal" "time" - "github.com/urfave/cli/v2" - microstore "go-micro.dev/v4/store" - "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -24,20 +21,22 @@ import ( "github.com/opencloud-eu/opencloud/services/collaboration/pkg/server/http" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" "github.com/opencloud-eu/reva/v2/pkg/store" + + "github.com/spf13/cobra" + microstore "go-micro.dev/v4/store" ) // 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) - traceProvider, err := tracing.GetTraceProvider(c.Context, cfg.Commons.TracesExporter, cfg.Service.Name) + traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name) if err != nil { return err } diff --git a/services/collaboration/pkg/command/version.go b/services/collaboration/pkg/command/version.go index 42ebc90ea..d651c48bd 100644 --- a/services/collaboration/pkg/command/version.go +++ b/services/collaboration/pkg/command/version.go @@ -6,20 +6,19 @@ import ( "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/version" + "github.com/opencloud-eu/opencloud/services/collaboration/pkg/config" "github.com/olekukonko/tablewriter" "github.com/olekukonko/tablewriter/tw" - "github.com/opencloud-eu/opencloud/services/collaboration/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 { fmt.Println("Version: " + version.GetString()) fmt.Printf("Compiled: %s\n", version.Compiled()) fmt.Println("")