Skip to content

Commit

Permalink
align commands to always execute the original Before()
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Dec 23, 2020
1 parent f48b3f4 commit 63ae28f
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 113 deletions.
1 change: 1 addition & 0 deletions ocis/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 4 additions & 3 deletions ocis/pkg/command/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
13 changes: 5 additions & 8 deletions ocis/pkg/command/glauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions ocis/pkg/command/ocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
20 changes: 6 additions & 14 deletions ocis/pkg/command/onlyoffice.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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
Expand All @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions ocis/pkg/command/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions ocis/pkg/command/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
11 changes: 6 additions & 5 deletions ocis/pkg/command/storageauthbasic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
11 changes: 6 additions & 5 deletions ocis/pkg/command/storageauthbearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
9 changes: 3 additions & 6 deletions ocis/pkg/command/storagefrontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
11 changes: 6 additions & 5 deletions ocis/pkg/command/storagegateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
11 changes: 6 additions & 5 deletions ocis/pkg/command/storagehome.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions ocis/pkg/command/storagemetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
11 changes: 6 additions & 5 deletions ocis/pkg/command/storagepubliclink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
11 changes: 6 additions & 5 deletions ocis/pkg/command/storagesharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
11 changes: 6 additions & 5 deletions ocis/pkg/command/storageuserprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
11 changes: 6 additions & 5 deletions ocis/pkg/command/storageusers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions ocis/pkg/command/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions ocis/pkg/command/thumbnails.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand Down
Loading

0 comments on commit 63ae28f

Please sign in to comment.