github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/cmd/init.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package cmd
     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(cmd *cobra.Command) (*app.App, error) {
    14  	config, err := cmd.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  	return a, nil
    26  }
    27  
    28  func InitDBCommandContext(configFileLocation string) (*app.App, error) {
    29  	if err := utils.TranslationsPreInit(); err != nil {
    30  		return nil, err
    31  	}
    32  	model.AppErrorInit(utils.T)
    33  
    34  	utils.ConfigureCmdLineLog()
    35  
    36  	a, err := app.New(app.ConfigFile(configFileLocation))
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  
    41  	if model.BuildEnterpriseReady == "true" {
    42  		a.LoadLicense()
    43  	}
    44  
    45  	return a, nil
    46  }