align commands to always execute the original Before()
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
@@ -217,6 +217,7 @@ github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVO
|
||||
github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw=
|
||||
github.com/caddyserver/certmagic v0.10.6 h1:sCya6FmfaN74oZE46kqfaFOVoROD/mF36rTQfjN7TZc=
|
||||
github.com/caddyserver/certmagic v0.10.6/go.mod h1:Y8jcUBctgk/IhpAzlHKfimZNyXCkfGgRTC0orl8gROQ=
|
||||
github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY=
|
||||
github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||
|
||||
@@ -28,12 +28,13 @@ func AccountsCommand(cfg *config.Config) *cli.Command {
|
||||
command.PrintVersion(cfg.Accounts),
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
accountsCommand := command.Server(configureAccounts(cfg))
|
||||
if err := accountsCommand.Before(c); err != nil {
|
||||
origCmd := command.Server(configureAccounts(cfg))
|
||||
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(accountsCommand.Action, c)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,16 +18,13 @@ func GLAuthCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.GLAuth),
|
||||
Action: func(c *cli.Context) error {
|
||||
origCmd := command.Server(configureGLAuth(cfg))
|
||||
|
||||
cfg.GLAuth.Backend.Servers = c.StringSlice("backend-server")
|
||||
cfg.GLAuth.Fallback.Servers = c.StringSlice("fallback-server")
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
scfg := configureGLAuth(cfg)
|
||||
|
||||
return cli.HandleAction(
|
||||
command.Server(scfg).Action,
|
||||
c,
|
||||
)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ func OCSCommand(cfg *config.Config) *cli.Command {
|
||||
Subcommands: []*cli.Command{
|
||||
command.PrintVersion(cfg.OCS),
|
||||
},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
ocsCommand := command.Server(configureOCS(cfg))
|
||||
Action: func(c *cli.Context) error {
|
||||
origCmd := command.Server(configureOCS(cfg))
|
||||
|
||||
if err := ocsCommand.Before(ctx); err != nil {
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(ocsCommand.Action, ctx)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/micro/cli/v2"
|
||||
"github.com/owncloud/ocis/ocis/pkg/config"
|
||||
"github.com/owncloud/ocis/ocis/pkg/register"
|
||||
"github.com/owncloud/ocis/onlyoffice/pkg/command"
|
||||
svcconfig "github.com/owncloud/ocis/onlyoffice/pkg/config"
|
||||
"github.com/owncloud/ocis/onlyoffice/pkg/flagset"
|
||||
)
|
||||
|
||||
@@ -17,26 +16,19 @@ func OnlyofficeCommand(cfg *config.Config) *cli.Command {
|
||||
Usage: "Start onlyoffice server",
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.Onlyoffice),
|
||||
Before: func(c *cli.Context) error {
|
||||
if cfg.HTTP.Root != "/" {
|
||||
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
onlyofficeCommand := command.Server(configureOnlyoffice(cfg).Onlyoffice)
|
||||
origCmd := command.Server(configureOnlyoffice(cfg))
|
||||
|
||||
if err := onlyofficeCommand.Before(c); err != nil {
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(onlyofficeCommand.Action, c)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func configureOnlyoffice(cfg *config.Config) *config.Config {
|
||||
func configureOnlyoffice(cfg *config.Config) *svcconfig.Config {
|
||||
cfg.Onlyoffice.Log.Level = cfg.Log.Level
|
||||
cfg.Onlyoffice.Log.Pretty = cfg.Log.Pretty
|
||||
cfg.Onlyoffice.Log.Color = cfg.Log.Color
|
||||
@@ -48,7 +40,7 @@ func configureOnlyoffice(cfg *config.Config) *config.Config {
|
||||
cfg.Onlyoffice.Tracing.Collector = cfg.Tracing.Collector
|
||||
}
|
||||
|
||||
return cfg
|
||||
return cfg.Onlyoffice
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -22,14 +22,14 @@ func ProxyCommand(cfg *config.Config) *cli.Command {
|
||||
Subcommands: []*cli.Command{
|
||||
command.PrintVersion(cfg.Proxy),
|
||||
},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
proxyCommand := command.Server(configureProxy(cfg))
|
||||
Action: func(c *cli.Context) error {
|
||||
origCmd := command.Server(configureProxy(cfg))
|
||||
|
||||
if err := proxyCommand.Before(ctx); err != nil {
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(proxyCommand.Action, ctx)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ func SettingsCommand(cfg *config.Config) *cli.Command {
|
||||
Subcommands: []*cli.Command{
|
||||
command.PrintVersion(cfg.Settings),
|
||||
},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
settingsCommand := command.Server(configureSettings(cfg))
|
||||
Action: func(c *cli.Context) error {
|
||||
origCmd := command.Server(configureSettings(cfg))
|
||||
|
||||
if err := settingsCommand.Before(ctx); err != nil {
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(settingsCommand.Action, ctx)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@ func StorageAuthBasicCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.AuthBasicWithConfig(cfg.Storage),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureStorageAuthBasic(cfg)
|
||||
origCmd := command.AuthBasic(configureStorageAuthBasic(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.AuthBasic(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@ func StorageAuthBearerCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.AuthBearerWithConfig(cfg.Storage),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureStorageAuthBearer(cfg)
|
||||
origCmd := command.AuthBearer(configureStorageAuthBearer(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.AuthBearer(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,13 @@ func StorageFrontendCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.FrontendWithConfig(cfg.Storage),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureStorageFrontend(cfg)
|
||||
origCmd := command.Frontend(configureStorageFrontend(cfg))
|
||||
|
||||
if err := command.Frontend(scfg).Before(c); err != nil {
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(
|
||||
command.Frontend(scfg).Action,
|
||||
c,
|
||||
)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@ func StorageGatewayCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.GatewayWithConfig(cfg.Storage),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureStorageGateway(cfg)
|
||||
origCmd := command.Gateway(configureStorageGateway(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.Gateway(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@ func StorageHomeCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.StorageHomeWithConfig(cfg.Storage),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureStorageHome(cfg)
|
||||
origCmd := command.StorageHome(configureStorageHome(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.StorageHome(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ func StorageMetadataCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.StorageMetadata(cfg.Storage),
|
||||
Action: func(c *cli.Context) error {
|
||||
revaStorageMetadataCommand := command.StorageMetadata(configureStorageMetadata(cfg))
|
||||
origCmd := command.StorageMetadata(configureStorageMetadata(cfg))
|
||||
|
||||
if err := revaStorageMetadataCommand.Before(c); err != nil {
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(revaStorageMetadataCommand.Action, c)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@ func StoragePublicLinkCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.StoragePublicLink(cfg.Storage),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureStoragePublicLink(cfg)
|
||||
origCmd := command.StoragePublicLink(configureStoragePublicLink(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.StoragePublicLink(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@ func StorageSharingCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.SharingWithConfig(cfg.Storage),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureStorageSharing(cfg)
|
||||
origCmd := command.Sharing(configureStorageSharing(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.Sharing(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@ func StorageUserProviderCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.UsersWithConfig(cfg.Storage),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureStorageUserProvider(cfg)
|
||||
origCmd := command.Users(configureStorageUserProvider(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.Users(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@ func StorageUsersCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.StorageUsersWithConfig(cfg.Storage),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureStorageUsers(cfg)
|
||||
origCmd := command.StorageUsers(configureStorageUsers(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.StorageUsers(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ func StoreCommand(cfg *config.Config) *cli.Command {
|
||||
Subcommands: []*cli.Command{
|
||||
command.PrintVersion(cfg.Store),
|
||||
},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
storeCommand := command.Server(configureStore(cfg))
|
||||
Action: func(c *cli.Context) error {
|
||||
origCmd := command.Server(configureStore(cfg))
|
||||
|
||||
if err := storeCommand.Before(ctx); err != nil {
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(storeCommand.Action, ctx)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command {
|
||||
command.PrintVersion(cfg.Thumbnails),
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
thumbnailsCommand := command.Server(configureThumbnails(cfg))
|
||||
origCmd := command.Server(configureThumbnails(cfg))
|
||||
|
||||
if err := thumbnailsCommand.Before(c); err != nil {
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(thumbnailsCommand.Action, c)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
+6
-15
@@ -1,12 +1,11 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/micro/cli/v2"
|
||||
"github.com/owncloud/ocis/ocis/pkg/config"
|
||||
"github.com/owncloud/ocis/ocis/pkg/register"
|
||||
"github.com/owncloud/ocis/web/pkg/command"
|
||||
svcconfig "github.com/owncloud/ocis/web/pkg/config"
|
||||
"github.com/owncloud/ocis/web/pkg/flagset"
|
||||
)
|
||||
|
||||
@@ -17,27 +16,19 @@ func WebCommand(cfg *config.Config) *cli.Command {
|
||||
Usage: "Start web server",
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.Web),
|
||||
Before: func(c *cli.Context) error {
|
||||
if cfg.HTTP.Root != "/" {
|
||||
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
|
||||
}
|
||||
|
||||
cfg.Web.Web.Config.Apps = c.StringSlice("web-config-app")
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
webCommand := command.Server(configureWeb(cfg).Web)
|
||||
origCmd := command.Server(configureWeb(cfg))
|
||||
|
||||
if err := webCommand.Before(c); err != nil {
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(webCommand.Action, c)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func configureWeb(cfg *config.Config) *config.Config {
|
||||
func configureWeb(cfg *config.Config) *svcconfig.Config {
|
||||
cfg.Web.Log.Level = cfg.Log.Level
|
||||
cfg.Web.Log.Pretty = cfg.Log.Pretty
|
||||
cfg.Web.Log.Color = cfg.Log.Color
|
||||
@@ -49,7 +40,7 @@ func configureWeb(cfg *config.Config) *config.Config {
|
||||
cfg.Web.Tracing.Collector = cfg.Tracing.Collector
|
||||
}
|
||||
|
||||
return cfg
|
||||
return cfg.Web
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -23,13 +23,13 @@ func WebDAVCommand(cfg *config.Config) *cli.Command {
|
||||
command.PrintVersion(cfg.WebDAV),
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
webdavCommand := command.Server(configureWebDAV(cfg))
|
||||
origCmd := command.Server(configureWebDAV(cfg))
|
||||
|
||||
if err := webdavCommand.Before(c); err != nil {
|
||||
if err := origCmd.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(webdavCommand.Action, c)
|
||||
return cli.HandleAction(origCmd.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,6 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
|
||||
}
|
||||
|
||||
// When running on single binary mode the before hook from the root command won't get called. We manually
|
||||
// call this before hook from ocis command, so the configuration can be loaded.
|
||||
return ParseConfig(ctx, cfg)
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
|
||||
Reference in New Issue
Block a user