github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/cmd/mattermost/commands/init.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package commands 5 6 import ( 7 "github.com/mattermost/mattermost-server/v5/app" 8 "github.com/mattermost/mattermost-server/v5/model" 9 "github.com/mattermost/mattermost-server/v5/utils" 10 "github.com/mattermost/viper" 11 "github.com/spf13/cobra" 12 ) 13 14 func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) { 15 config := viper.GetString("config") 16 17 a, err := InitDBCommandContext(config) 18 19 if err != nil { 20 // Returning an error just prints the usage message, so actually panic 21 panic(err) 22 } 23 24 a.InitPlugins(*a.Config().PluginSettings.Directory, *a.Config().PluginSettings.ClientDirectory) 25 a.DoAppMigrations() 26 27 return a, nil 28 } 29 30 func InitDBCommandContext(configDSN string) (*app.App, error) { 31 if err := utils.TranslationsPreInit(); err != nil { 32 return nil, err 33 } 34 model.AppErrorInit(utils.T) 35 36 s, err := app.NewServer( 37 app.Config(configDSN, false), 38 app.StartSearchEngine, 39 ) 40 if err != nil { 41 return nil, err 42 } 43 44 a := app.New(app.ServerConnector(s)) 45 46 if model.BuildEnterpriseReady == "true" { 47 a.Srv().LoadLicense() 48 } 49 50 return a, nil 51 }