diff --git a/cmd/mattermost/commands/db.go b/cmd/mattermost/commands/db.go index db33032297..c0d186c265 100644 --- a/cmd/mattermost/commands/db.go +++ b/cmd/mattermost/commands/db.go @@ -10,6 +10,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/mattermost/mattermost-server/v6/app" "github.com/mattermost/mattermost-server/v6/audit" "github.com/mattermost/mattermost-server/v6/config" "github.com/mattermost/mattermost-server/v6/store/sqlstore" @@ -100,7 +101,7 @@ func initDbCmdF(command *cobra.Command, _ []string) error { } func resetCmdF(command *cobra.Command, args []string) error { - a, err := InitDBCommandContextCobra(command) + a, err := InitDBCommandContextCobra(command, app.SkipPostInitialization()) if err != nil { return err } diff --git a/cmd/mattermost/commands/export.go b/cmd/mattermost/commands/export.go index fa0f251e1b..d5573ee975 100644 --- a/cmd/mattermost/commands/export.go +++ b/cmd/mattermost/commands/export.go @@ -10,6 +10,7 @@ import ( "path/filepath" "time" + "github.com/mattermost/mattermost-server/v6/app" "github.com/mattermost/mattermost-server/v6/app/request" "github.com/mattermost/mattermost-server/v6/audit" "github.com/mattermost/mattermost-server/v6/model" @@ -93,7 +94,7 @@ func init() { } func scheduleExportCmdF(command *cobra.Command, args []string) error { - a, err := InitDBCommandContextCobra(command) + a, err := InitDBCommandContextCobra(command, app.SkipPostInitialization()) if err != nil { return err } @@ -153,7 +154,7 @@ func scheduleExportCmdF(command *cobra.Command, args []string) error { func buildExportCmdF(format string) func(command *cobra.Command, args []string) error { return func(command *cobra.Command, args []string) error { - a, err := InitDBCommandContextCobra(command) + a, err := InitDBCommandContextCobra(command, app.SkipPostInitialization()) license := a.Srv().License() if err != nil { return err @@ -201,7 +202,7 @@ func buildExportCmdF(format string) func(command *cobra.Command, args []string) } func bulkExportCmdF(command *cobra.Command, args []string) error { - a, err := InitDBCommandContextCobra(command) + a, err := InitDBCommandContextCobra(command, app.SkipPostInitialization()) if err != nil { return err } diff --git a/cmd/mattermost/commands/init.go b/cmd/mattermost/commands/init.go index e93d9640fe..1c7e8baf07 100644 --- a/cmd/mattermost/commands/init.go +++ b/cmd/mattermost/commands/init.go @@ -14,8 +14,8 @@ import ( "github.com/mattermost/mattermost-server/v6/utils" ) -func initDBCommandContextCobra(command *cobra.Command, readOnlyConfigStore bool) (*app.App, error) { - a, err := initDBCommandContext(getConfigDSN(command, config.GetEnvironment()), readOnlyConfigStore) +func initDBCommandContextCobra(command *cobra.Command, readOnlyConfigStore bool, options ...app.Option) (*app.App, error) { + a, err := initDBCommandContext(getConfigDSN(command, config.GetEnvironment()), readOnlyConfigStore, options...) if err != nil { // Returning an error just prints the usage message, so actually panic panic(err) @@ -27,25 +27,19 @@ func initDBCommandContextCobra(command *cobra.Command, readOnlyConfigStore bool) return a, nil } -func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) { - return initDBCommandContextCobra(command, true) +func InitDBCommandContextCobra(command *cobra.Command, options ...app.Option) (*app.App, error) { + return initDBCommandContextCobra(command, true, options...) } -func InitDBCommandContextCobraReadWrite(command *cobra.Command) (*app.App, error) { - return initDBCommandContextCobra(command, false) -} - -func initDBCommandContext(configDSN string, readOnlyConfigStore bool) (*app.App, error) { +func initDBCommandContext(configDSN string, readOnlyConfigStore bool, options ...app.Option) (*app.App, error) { if err := utils.TranslationsPreInit(); err != nil { return nil, err } model.AppErrorInit(i18n.T) - s, err := app.NewServer( - // The option order is important as app.Config option reads app.StartMetrics option. - app.StartMetrics, - app.Config(configDSN, readOnlyConfigStore, nil), - ) + // The option order is important as app.Config option reads app.StartMetrics option. + options = append(options, app.Config(configDSN, readOnlyConfigStore, nil)) + s, err := app.NewServer(options...) if err != nil { return nil, err } diff --git a/cmd/mattermost/commands/jobserver.go b/cmd/mattermost/commands/jobserver.go index 488b3f8fe7..be59971aab 100644 --- a/cmd/mattermost/commands/jobserver.go +++ b/cmd/mattermost/commands/jobserver.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/cobra" + "github.com/mattermost/mattermost-server/v6/app" "github.com/mattermost/mattermost-server/v6/audit" "github.com/mattermost/mattermost-server/v6/config" "github.com/mattermost/mattermost-server/v6/shared/mlog" @@ -34,7 +35,7 @@ func jobserverCmdF(command *cobra.Command, args []string) error { noSchedule, _ := command.Flags().GetBool("noschedule") // Initialize - a, err := initDBCommandContext(getConfigDSN(command, config.GetEnvironment()), false) + a, err := initDBCommandContext(getConfigDSN(command, config.GetEnvironment()), false, app.StartMetrics) if err != nil { return err } diff --git a/cmd/mattermost/commands/test.go b/cmd/mattermost/commands/test.go index 75c49a4ee7..1a50d53221 100644 --- a/cmd/mattermost/commands/test.go +++ b/cmd/mattermost/commands/test.go @@ -14,6 +14,7 @@ import ( "github.com/spf13/cobra" "github.com/mattermost/mattermost-server/v6/api4" + "github.com/mattermost/mattermost-server/v6/app" "github.com/mattermost/mattermost-server/v6/model" "github.com/mattermost/mattermost-server/v6/shared/i18n" "github.com/mattermost/mattermost-server/v6/wsapi" @@ -46,7 +47,7 @@ func init() { } func webClientTestsCmdF(command *cobra.Command, args []string) error { - a, err := InitDBCommandContextCobra(command) + a, err := InitDBCommandContextCobra(command, app.StartMetrics) if err != nil { return err } @@ -70,7 +71,7 @@ func webClientTestsCmdF(command *cobra.Command, args []string) error { } func serverForWebClientTestsCmdF(command *cobra.Command, args []string) error { - a, err := InitDBCommandContextCobra(command) + a, err := InitDBCommandContextCobra(command, app.StartMetrics) if err != nil { return err }