PLT-6471 Properly panic when translations can't be loaded (#6414)
* PLT-6471 Properly panic when translations can't be loaded * Print usage messages when errors occur during CLI initialization * Reverted behaviour of FindDir and added second return value to it * Fixed merge conflict
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
69f3f2fdce
Коммит
5c1049054e
@@ -102,7 +102,9 @@ func init() {
|
||||
}
|
||||
|
||||
func createChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !utils.IsLicensed {
|
||||
return errors.New(utils.T("cli.license.critical"))
|
||||
@@ -152,7 +154,9 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func removeChannelUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !utils.IsLicensed {
|
||||
return errors.New(utils.T("cli.license.critical"))
|
||||
@@ -186,7 +190,9 @@ func removeUserFromChannel(channel *model.Channel, user *model.User, userArg str
|
||||
}
|
||||
|
||||
func addChannelUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !utils.IsLicensed {
|
||||
return errors.New(utils.T("cli.license.critical"))
|
||||
@@ -220,7 +226,9 @@ func addUserToChannel(channel *model.Channel, user *model.User, userArg string)
|
||||
}
|
||||
|
||||
func archiveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Enter at least one channel to delete.")
|
||||
@@ -241,7 +249,9 @@ func archiveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func deleteChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Enter at least one channel to delete.")
|
||||
@@ -278,7 +288,9 @@ func deleteChannel(channel *model.Channel) *model.AppError {
|
||||
}
|
||||
|
||||
func listChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !utils.IsLicensed {
|
||||
return errors.New(utils.T("cli.license.critical"))
|
||||
@@ -313,7 +325,9 @@ func listChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func restoreChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !utils.IsLicensed {
|
||||
return errors.New(utils.T("cli.license.critical"))
|
||||
|
||||
@@ -44,7 +44,9 @@ func init() {
|
||||
}
|
||||
|
||||
func slackImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) != 2 {
|
||||
return errors.New("Incorrect number of arguments.")
|
||||
@@ -76,7 +78,9 @@ func slackImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func bulkImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
apply, err := cmd.Flags().GetBool("apply")
|
||||
if err != nil {
|
||||
|
||||
@@ -12,14 +12,18 @@ func initDBCommandContextCobra(cmd *cobra.Command) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
initDBCommandContext(config)
|
||||
|
||||
if err := initDBCommandContext(config); err != nil {
|
||||
// Returning an error just prints the usage message, so actually panic
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initDBCommandContext(configFileLocation string) {
|
||||
if errstr := utils.InitAndLoadConfig(configFileLocation); errstr != "" {
|
||||
return
|
||||
func initDBCommandContext(configFileLocation string) error {
|
||||
if err := utils.InitAndLoadConfig(configFileLocation); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
utils.ConfigureCmdLineLog()
|
||||
@@ -29,4 +33,6 @@ func initDBCommandContext(configFileLocation string) {
|
||||
if model.BuildEnterpriseReady == "true" {
|
||||
app.LoadLicense()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@ func init() {
|
||||
}
|
||||
|
||||
func uploadLicenseCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) != 1 {
|
||||
return errors.New("Enter one license file to upload")
|
||||
|
||||
@@ -59,7 +59,9 @@ var resetCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func resetCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
confirmFlag, _ := cmd.Flags().GetBool("confirm")
|
||||
if !confirmFlag {
|
||||
|
||||
@@ -38,7 +38,10 @@ func init() {
|
||||
}
|
||||
|
||||
func makeSystemAdminCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Enter at least one user.")
|
||||
}
|
||||
@@ -58,7 +61,10 @@ func makeSystemAdminCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func makeMemberCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Enter at least one user.")
|
||||
}
|
||||
|
||||
@@ -44,12 +44,16 @@ func runServerCmd(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func runServer(configFileLocation string) {
|
||||
if errstr := utils.InitAndLoadConfig(configFileLocation); errstr != "" {
|
||||
l4g.Exit("Unable to load mattermost configuration file: ", errstr)
|
||||
if err := utils.InitAndLoadConfig(configFileLocation); err != nil {
|
||||
l4g.Exit("Unable to load Mattermost configuration file: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := utils.InitTranslations(utils.Cfg.LocalizationSettings); err != nil {
|
||||
l4g.Exit("Unable to load Mattermost translation files: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
utils.TestConnection(utils.Cfg)
|
||||
|
||||
pwd, _ := os.Getwd()
|
||||
|
||||
@@ -67,7 +67,9 @@ func init() {
|
||||
}
|
||||
|
||||
func createTeamCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name, errn := cmd.Flags().GetString("name")
|
||||
if errn != nil || name == "" {
|
||||
@@ -100,7 +102,9 @@ func createTeamCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func removeUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 2 {
|
||||
return errors.New("Not enough arguments.")
|
||||
@@ -130,7 +134,9 @@ func removeUserFromTeam(team *model.Team, user *model.User, userArg string) {
|
||||
}
|
||||
|
||||
func addUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 2 {
|
||||
return errors.New("Not enough arguments.")
|
||||
@@ -160,7 +166,9 @@ func addUserToTeam(team *model.Team, user *model.User, userArg string) {
|
||||
}
|
||||
|
||||
func deleteTeamsCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Not enough arguments.")
|
||||
|
||||
@@ -45,7 +45,10 @@ func init() {
|
||||
}
|
||||
|
||||
func webClientTestsCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
api.InitRouter()
|
||||
wsapi.InitRouter()
|
||||
@@ -61,7 +64,10 @@ func webClientTestsCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func serverForWebClientTestsCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
api.InitRouter()
|
||||
wsapi.InitRouter()
|
||||
|
||||
@@ -157,7 +157,9 @@ func init() {
|
||||
}
|
||||
|
||||
func userActivateCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Enter user(s) to activate.")
|
||||
@@ -193,7 +195,9 @@ func changeUserActiveStatus(user *model.User, userArg string, activate bool) err
|
||||
}
|
||||
|
||||
func userDeactivateCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Enter user(s) to deactivate.")
|
||||
@@ -204,7 +208,10 @@ func userDeactivateCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func userCreateCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
username, erru := cmd.Flags().GetString("username")
|
||||
if erru != nil || username == "" {
|
||||
return errors.New("Username is required")
|
||||
@@ -248,7 +255,10 @@ func userCreateCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func userInviteCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
utils.InitHTML()
|
||||
|
||||
if len(args) < 2 {
|
||||
@@ -285,7 +295,10 @@ func inviteUser(email string, team *model.Team, teamArg string) error {
|
||||
}
|
||||
|
||||
func resetUserPasswordCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) != 2 {
|
||||
return errors.New("Incorect number of arguments.")
|
||||
}
|
||||
@@ -304,7 +317,10 @@ func resetUserPasswordCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func resetUserMfaCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Enter at least one user.")
|
||||
}
|
||||
@@ -325,7 +341,10 @@ func resetUserMfaCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func deleteUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Enter at least one user.")
|
||||
}
|
||||
@@ -362,7 +381,10 @@ func deleteUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
return errors.New("Don't enter any agruments.")
|
||||
}
|
||||
@@ -393,7 +415,10 @@ func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func migrateAuthCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) != 3 {
|
||||
return errors.New("Enter the correct number of arguments.")
|
||||
}
|
||||
@@ -431,7 +456,10 @@ func migrateAuthCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func verifyUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Enter at least one user.")
|
||||
}
|
||||
@@ -452,7 +480,10 @@ func verifyUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func searchUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
initDBCommandContextCobra(cmd)
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Enter at least one query.")
|
||||
}
|
||||
|
||||
@@ -12,12 +12,17 @@ import (
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Display version information",
|
||||
Run: versionCmdF,
|
||||
RunE: versionCmdF,
|
||||
}
|
||||
|
||||
func versionCmdF(cmd *cobra.Command, args []string) {
|
||||
initDBCommandContextCobra(cmd)
|
||||
func versionCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printVersion()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func printVersion() {
|
||||
|
||||
Ссылка в новой задаче
Block a user