github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+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  	if err != nil {
    21  		// Returning an error just prints the usage message, so actually panic
    22  		panic(err)
    23  	}
    24  
    25  	a.DoAdvancedPermissionsMigration()
    26  	a.DoEmojisPermissionsMigration()
    27  
    28  	return a, nil
    29  }
    30  
    31  func InitDBCommandContext(configFileLocation string) (*app.App, error) {
    32  	if err := utils.TranslationsPreInit(); err != nil {
    33  		return nil, err
    34  	}
    35  	model.AppErrorInit(utils.T)
    36  
    37  	a, err := app.New(app.ConfigFile(configFileLocation))
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  
    42  	if model.BuildEnterpriseReady == "true" {
    43  		a.LoadLicense()
    44  	}
    45  
    46  	return a, nil
    47  }