github.com/lologarithm/mattermost-server@v5.3.2-0.20181002060438-c82a84ed765b+incompatible/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/app"
     8  	"github.com/mattermost/mattermost-server/model"
     9  	"github.com/mattermost/mattermost-server/utils"
    10  	"github.com/spf13/cobra"
    11  )
    12  
    13  func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) {
    14  	config, err := command.Flags().GetString("config")
    15  	if err != nil {
    16  		return nil, err
    17  	}
    18  
    19  	a, err := InitDBCommandContext(config)
    20  	a.InitPlugins(*a.Config().PluginSettings.Directory, *a.Config().PluginSettings.ClientDirectory)
    21  
    22  	if err != nil {
    23  		// Returning an error just prints the usage message, so actually panic
    24  		panic(err)
    25  	}
    26  
    27  	a.DoAdvancedPermissionsMigration()
    28  	a.DoEmojisPermissionsMigration()
    29  
    30  	return a, nil
    31  }
    32  
    33  func InitDBCommandContext(configFileLocation string) (*app.App, error) {
    34  	if err := utils.TranslationsPreInit(); err != nil {
    35  		return nil, err
    36  	}
    37  	model.AppErrorInit(utils.T)
    38  
    39  	a, err := app.New(app.ConfigFile(configFileLocation))
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  
    44  	if model.BuildEnterpriseReady == "true" {
    45  		a.LoadLicense()
    46  	}
    47  
    48  	return a, nil
    49  }