diff --git a/opencloud/pkg/command/services.go b/opencloud/pkg/command/services.go index e87548979c..f6b05e843b 100644 --- a/opencloud/pkg/command/services.go +++ b/opencloud/pkg/command/services.go @@ -1,8 +1,6 @@ package command import ( - "github.com/urfave/cli/v2" - "github.com/opencloud-eu/opencloud/opencloud/pkg/command/helper" "github.com/opencloud-eu/opencloud/opencloud/pkg/register" "github.com/opencloud-eu/opencloud/pkg/config" @@ -50,215 +48,217 @@ import ( web "github.com/opencloud-eu/opencloud/services/web/pkg/command" webdav "github.com/opencloud-eu/opencloud/services/webdav/pkg/command" webfinger "github.com/opencloud-eu/opencloud/services/webfinger/pkg/command" + + "github.com/spf13/cobra" ) var svccmds = []register.Command{ - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Activitylog.Service.Name, activitylog.GetCommands(cfg.Activitylog), func(c *config.Config) { cfg.Activitylog.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Antivirus.Service.Name, antivirus.GetCommands(cfg.Antivirus), func(c *config.Config) { // cfg.Antivirus.Commons = cfg.Commons // antivirus needs no commons atm }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.AppProvider.Service.Name, appprovider.GetCommands(cfg.AppProvider), func(c *config.Config) { cfg.AppProvider.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.AppRegistry.Service.Name, appregistry.GetCommands(cfg.AppRegistry), func(c *config.Config) { cfg.AppRegistry.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Audit.Service.Name, audit.GetCommands(cfg.Audit), func(c *config.Config) { cfg.Audit.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.AuthApp.Service.Name, authapp.GetCommands(cfg.AuthApp), func(_ *config.Config) { cfg.AuthApp.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.AuthBasic.Service.Name, authbasic.GetCommands(cfg.AuthBasic), func(c *config.Config) { cfg.AuthBasic.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.AuthBearer.Service.Name, authbearer.GetCommands(cfg.AuthBearer), func(c *config.Config) { cfg.AuthBearer.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.AuthMachine.Service.Name, authmachine.GetCommands(cfg.AuthMachine), func(c *config.Config) { cfg.AuthMachine.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.AuthService.Service.Name, authservice.GetCommands(cfg.AuthService), func(c *config.Config) { cfg.AuthService.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Clientlog.Service.Name, clientlog.GetCommands(cfg.Clientlog), func(c *config.Config) { cfg.Clientlog.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Collaboration.Service.Name, collaboration.GetCommands(cfg.Collaboration), func(c *config.Config) { cfg.Collaboration.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.EventHistory.Service.Name, eventhistory.GetCommands(cfg.EventHistory), func(c *config.Config) { cfg.EventHistory.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Frontend.Service.Name, frontend.GetCommands(cfg.Frontend), func(c *config.Config) { cfg.Frontend.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Gateway.Service.Name, gateway.GetCommands(cfg.Gateway), func(c *config.Config) { cfg.Gateway.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Graph.Service.Name, graph.GetCommands(cfg.Graph), func(c *config.Config) { cfg.Graph.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Groups.Service.Name, groups.GetCommands(cfg.Groups), func(c *config.Config) { cfg.Groups.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.IDM.Service.Name, idm.GetCommands(cfg.IDM), func(c *config.Config) { cfg.IDM.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.IDP.Service.Name, idp.GetCommands(cfg.IDP), func(c *config.Config) { cfg.IDP.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Invitations.Service.Name, invitations.GetCommands(cfg.Invitations), func(c *config.Config) { cfg.Invitations.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Nats.Service.Name, nats.GetCommands(cfg.Nats), func(c *config.Config) { cfg.Nats.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Notifications.Service.Name, notifications.GetCommands(cfg.Notifications), func(c *config.Config) { cfg.Notifications.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.OCDav.Service.Name, ocdav.GetCommands(cfg.OCDav), func(c *config.Config) { cfg.OCDav.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.OCM.Service.Name, ocm.GetCommands(cfg.OCM), func(c *config.Config) { cfg.OCM.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.OCS.Service.Name, ocs.GetCommands(cfg.OCS), func(c *config.Config) { cfg.OCS.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Policies.Service.Name, policies.GetCommands(cfg.Policies), func(c *config.Config) { cfg.Policies.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Postprocessing.Service.Name, postprocessing.GetCommands(cfg.Postprocessing), func(c *config.Config) { cfg.Postprocessing.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Proxy.Service.Name, proxy.GetCommands(cfg.Proxy), func(c *config.Config) { cfg.Proxy.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Search.Service.Name, search.GetCommands(cfg.Search), func(c *config.Config) { cfg.Search.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Settings.Service.Name, settings.GetCommands(cfg.Settings), func(c *config.Config) { cfg.Settings.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Sharing.Service.Name, sharing.GetCommands(cfg.Sharing), func(c *config.Config) { cfg.Sharing.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.SSE.Service.Name, sse.GetCommands(cfg.SSE), func(c *config.Config) { cfg.SSE.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.StoragePublicLink.Service.Name, storagepubliclink.GetCommands(cfg.StoragePublicLink), func(c *config.Config) { cfg.StoragePublicLink.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.StorageShares.Service.Name, storageshares.GetCommands(cfg.StorageShares), func(c *config.Config) { cfg.StorageShares.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.StorageSystem.Service.Name, storagesystem.GetCommands(cfg.StorageSystem), func(c *config.Config) { cfg.StorageSystem.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.StorageUsers.Service.Name, storageusers.GetCommands(cfg.StorageUsers), func(c *config.Config) { cfg.StorageUsers.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Thumbnails.Service.Name, thumbnails.GetCommands(cfg.Thumbnails), func(c *config.Config) { cfg.Thumbnails.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Userlog.Service.Name, userlog.GetCommands(cfg.Userlog), func(c *config.Config) { cfg.Userlog.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Users.Service.Name, users.GetCommands(cfg.Users), func(c *config.Config) { cfg.Users.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Web.Service.Name, web.GetCommands(cfg.Web), func(c *config.Config) { cfg.Web.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.WebDAV.Service.Name, webdav.GetCommands(cfg.WebDAV), func(c *config.Config) { cfg.WebDAV.Commons = cfg.Commons }) }, - func(cfg *config.Config) *cli.Command { + func(cfg *config.Config) *cobra.Command { return ServiceCommand(cfg, cfg.Webfinger.Service.Name, webfinger.GetCommands(cfg.Webfinger), func(c *config.Config) { cfg.Webfinger.Commons = cfg.Commons }) @@ -266,18 +266,18 @@ var svccmds = []register.Command{ } // ServiceCommand is the entry point for the all service commands. -func ServiceCommand(cfg *config.Config, serviceName string, subcommands []*cli.Command, f func(*config.Config)) *cli.Command { - return &cli.Command{ - Name: serviceName, - Usage: helper.SubcommandDescription(serviceName), - Category: "services", - Before: func(c *cli.Context) error { +func ServiceCommand(cfg *config.Config, serviceName string, subcommands []*cobra.Command, f func(*config.Config)) *cobra.Command { + svcCommand := &cobra.Command{ + Use: serviceName, + Short: helper.SubcommandDescription(serviceName), + RunE: func(cmd *cobra.Command, args []string) error { configlog.Error(parser.ParseConfig(cfg, true)) f(cfg) return nil }, - Subcommands: subcommands, } + svcCommand.AddCommand(subcommands...) + return svcCommand } func init() {