diff --git a/opencloud/pkg/command/services.go b/opencloud/pkg/command/services.go index 6cdc95cec4..cb942b520e 100644 --- a/opencloud/pkg/command/services.go +++ b/opencloud/pkg/command/services.go @@ -265,7 +265,7 @@ var serviceCommands = []register.Command{ cfg.Webfinger.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.AuthApi.Service.Name, authapi.GetCommands(cfg.AuthApi), func(c *config.Config) { cfg.AuthApi.Commons = cfg.Commons }) diff --git a/services/auth-api/pkg/command/root.go b/services/auth-api/pkg/command/root.go index 1053eace93..964c9884ea 100644 --- a/services/auth-api/pkg/command/root.go +++ b/services/auth-api/pkg/command/root.go @@ -5,23 +5,29 @@ import ( "github.com/opencloud-eu/opencloud/pkg/clihelper" "github.com/opencloud-eu/opencloud/services/auth-api/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), + // infos about this service + // Health(cfg), Version(cfg), } } +// Execute is the entry point for the opencloud group command. func Execute(cfg *config.Config) error { - app := clihelper.DefaultApp(&cli.App{ - Name: "auth-api", - Usage: "OpenCloud authentication API for external services", - Commands: GetCommands(cfg), + app := clihelper.DefaultApp(&cobra.Command{ + Use: "auth-api", + Short: "OpenCloud authentication API for external services", }) + 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/auth-api/pkg/command/server.go b/services/auth-api/pkg/command/server.go index 2e4812b203..f4879c577c 100644 --- a/services/auth-api/pkg/command/server.go +++ b/services/auth-api/pkg/command/server.go @@ -13,24 +13,24 @@ import ( "github.com/opencloud-eu/opencloud/services/auth-api/pkg/metrics" "github.com/opencloud-eu/opencloud/services/auth-api/pkg/server/debug" "github.com/opencloud-eu/opencloud/services/auth-api/pkg/server/http" - "github.com/urfave/cli/v2" + + "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(_ *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) var ( gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) + ctx, cancel = context.WithCancel(context.Background()) m = metrics.New() ) diff --git a/services/auth-api/pkg/command/version.go b/services/auth-api/pkg/command/version.go index 35b1243402..af83532eaf 100644 --- a/services/auth-api/pkg/command/version.go +++ b/services/auth-api/pkg/command/version.go @@ -6,16 +6,15 @@ import ( "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/auth-api/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("") diff --git a/services/groupware/pkg/command/root.go b/services/groupware/pkg/command/root.go index aa13cb6a5a..8dc8b338eb 100644 --- a/services/groupware/pkg/command/root.go +++ b/services/groupware/pkg/command/root.go @@ -5,23 +5,30 @@ import ( "github.com/opencloud-eu/opencloud/pkg/clihelper" "github.com/opencloud-eu/opencloud/services/groupware/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), + + // infos about this service + // Health(cfg), Version(cfg), } } +// Execute is the entry point for the opencloud group command. func Execute(cfg *config.Config) error { - app := clihelper.DefaultApp(&cli.App{ - Name: "groupware", - Usage: "Groupware service for OpenCloud", - Commands: GetCommands(cfg), + app := clihelper.DefaultApp(&cobra.Command{ + Use: "groupware", + Short: "Groupware service 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/groupware/pkg/command/server.go b/services/groupware/pkg/command/server.go index 4af34fa62b..8b8b4be1cf 100644 --- a/services/groupware/pkg/command/server.go +++ b/services/groupware/pkg/command/server.go @@ -12,24 +12,24 @@ import ( "github.com/opencloud-eu/opencloud/services/groupware/pkg/metrics" "github.com/opencloud-eu/opencloud/services/groupware/pkg/server/debug" "github.com/opencloud-eu/opencloud/services/groupware/pkg/server/http" - "github.com/urfave/cli/v2" + + "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(_ *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) var ( gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) + ctx, cancel = context.WithCancel(context.Background()) m = metrics.NewHttpMetrics() ) diff --git a/services/groupware/pkg/command/version.go b/services/groupware/pkg/command/version.go index b335cb2f12..9cd3f45558 100644 --- a/services/groupware/pkg/command/version.go +++ b/services/groupware/pkg/command/version.go @@ -6,16 +6,15 @@ import ( "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/groupware/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("")