Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-2

Этот коммит содержится в:
Martin Kraft
2018-05-18 08:23:02 -04:00
родитель 8a0702e0c3 e591fcf3d8
Коммит 78d95a25f7
41 изменённых файлов: 288 добавлений и 264 удалений

Просмотреть файл

@@ -8,7 +8,6 @@ import (
"fmt"
"github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/spf13/cobra"
)
@@ -128,11 +127,11 @@ func init() {
ModifyChannelCmd,
)
cmd.RootCmd.AddCommand(ChannelCmd)
RootCmd.AddCommand(ChannelCmd)
}
func createChannelCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -182,7 +181,7 @@ func createChannelCmdF(command *cobra.Command, args []string) error {
}
func removeChannelUsersCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -207,16 +206,16 @@ func removeChannelUsersCmdF(command *cobra.Command, args []string) error {
func removeUserFromChannel(a *app.App, channel *model.Channel, user *model.User, userArg string) {
if user == nil {
cmd.CommandPrintErrorln("Can't find user '" + userArg + "'")
CommandPrintErrorln("Can't find user '" + userArg + "'")
return
}
if err := a.RemoveUserFromChannel(user.Id, "", channel); err != nil {
cmd.CommandPrintErrorln("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
}
}
func addChannelUsersCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -241,16 +240,16 @@ func addChannelUsersCmdF(command *cobra.Command, args []string) error {
func addUserToChannel(a *app.App, channel *model.Channel, user *model.User, userArg string) {
if user == nil {
cmd.CommandPrintErrorln("Can't find user '" + userArg + "'")
CommandPrintErrorln("Can't find user '" + userArg + "'")
return
}
if _, err := a.AddUserToChannel(user, channel); err != nil {
cmd.CommandPrintErrorln("Unable to add '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
CommandPrintErrorln("Unable to add '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
}
}
func archiveChannelsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -263,11 +262,11 @@ func archiveChannelsCmdF(command *cobra.Command, args []string) error {
channels := getChannelsFromChannelArgs(a, args)
for i, channel := range channels {
if channel == nil {
cmd.CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
continue
}
if result := <-a.Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); result.Err != nil {
cmd.CommandPrintErrorln("Unable to archive channel '" + channel.Name + "' error: " + result.Err.Error())
CommandPrintErrorln("Unable to archive channel '" + channel.Name + "' error: " + result.Err.Error())
}
}
@@ -275,7 +274,7 @@ func archiveChannelsCmdF(command *cobra.Command, args []string) error {
}
func deleteChannelsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -288,7 +287,7 @@ func deleteChannelsCmdF(command *cobra.Command, args []string) error {
confirmFlag, _ := command.Flags().GetBool("confirm")
if !confirmFlag {
var confirm string
cmd.CommandPrettyPrintln("Are you sure you want to delete the channels specified? All data will be permanently deleted? (YES/NO): ")
CommandPrettyPrintln("Are you sure you want to delete the channels specified? All data will be permanently deleted? (YES/NO): ")
fmt.Scanln(&confirm)
if confirm != "YES" {
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
@@ -298,13 +297,13 @@ func deleteChannelsCmdF(command *cobra.Command, args []string) error {
channels := getChannelsFromChannelArgs(a, args)
for i, channel := range channels {
if channel == nil {
cmd.CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
continue
}
if err := deleteChannel(a, channel); err != nil {
cmd.CommandPrintErrorln("Unable to delete channel '" + channel.Name + "' error: " + err.Error())
CommandPrintErrorln("Unable to delete channel '" + channel.Name + "' error: " + err.Error())
} else {
cmd.CommandPrettyPrintln("Deleted channel '" + channel.Name + "'")
CommandPrettyPrintln("Deleted channel '" + channel.Name + "'")
}
}
@@ -316,7 +315,7 @@ func deleteChannel(a *app.App, channel *model.Channel) *model.AppError {
}
func moveChannelsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -340,14 +339,14 @@ func moveChannelsCmdF(command *cobra.Command, args []string) error {
channels := getChannelsFromChannelArgs(a, args[1:])
for i, channel := range channels {
if channel == nil {
cmd.CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
continue
}
originTeamID := channel.TeamId
if err := moveChannel(a, team, channel, user); err != nil {
cmd.CommandPrintErrorln("Unable to move channel '" + channel.Name + "' error: " + err.Error())
CommandPrintErrorln("Unable to move channel '" + channel.Name + "' error: " + err.Error())
} else {
cmd.CommandPrettyPrintln("Moved channel '" + channel.Name + "' to " + team.Name + "(" + team.Id + ") from " + originTeamID + ".")
CommandPrettyPrintln("Moved channel '" + channel.Name + "' to " + team.Name + "(" + team.Id + ") from " + originTeamID + ".")
}
}
@@ -368,7 +367,7 @@ func moveChannel(a *app.App, team *model.Team, channel *model.Channel, user *mod
if webhook.ChannelId == channel.Id {
webhook.TeamId = team.Id
if result := <-a.Srv.Store.Webhook().UpdateIncoming(webhook); result.Err != nil {
cmd.CommandPrintErrorln("Failed to move incoming webhook '" + webhook.Id + "' to new team.")
CommandPrintErrorln("Failed to move incoming webhook '" + webhook.Id + "' to new team.")
}
}
}
@@ -381,7 +380,7 @@ func moveChannel(a *app.App, team *model.Team, channel *model.Channel, user *mod
if webhook.ChannelId == channel.Id {
webhook.TeamId = team.Id
if result := <-a.Srv.Store.Webhook().UpdateOutgoing(webhook); result.Err != nil {
cmd.CommandPrintErrorln("Failed to move outgoing webhook '" + webhook.Id + "' to new team.")
CommandPrintErrorln("Failed to move outgoing webhook '" + webhook.Id + "' to new team.")
}
}
}
@@ -391,7 +390,7 @@ func moveChannel(a *app.App, team *model.Team, channel *model.Channel, user *mod
}
func listChannelsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -404,19 +403,19 @@ func listChannelsCmdF(command *cobra.Command, args []string) error {
teams := getTeamsFromTeamArgs(a, args)
for i, team := range teams {
if team == nil {
cmd.CommandPrintErrorln("Unable to find team '" + args[i] + "'")
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
continue
}
if result := <-a.Srv.Store.Channel().GetAll(team.Id); result.Err != nil {
cmd.CommandPrintErrorln("Unable to list channels for '" + args[i] + "'")
CommandPrintErrorln("Unable to list channels for '" + args[i] + "'")
} else {
channels := result.Data.([]*model.Channel)
for _, channel := range channels {
if channel.DeleteAt > 0 {
cmd.CommandPrettyPrintln(channel.Name + " (archived)")
CommandPrettyPrintln(channel.Name + " (archived)")
} else {
cmd.CommandPrettyPrintln(channel.Name)
CommandPrettyPrintln(channel.Name)
}
}
}
@@ -426,7 +425,7 @@ func listChannelsCmdF(command *cobra.Command, args []string) error {
}
func restoreChannelsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -439,11 +438,11 @@ func restoreChannelsCmdF(command *cobra.Command, args []string) error {
channels := getChannelsFromChannelArgs(a, args)
for i, channel := range channels {
if channel == nil {
cmd.CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
continue
}
if result := <-a.Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil {
cmd.CommandPrintErrorln("Unable to restore channel '" + args[i] + "'")
CommandPrintErrorln("Unable to restore channel '" + args[i] + "'")
}
}
@@ -451,7 +450,7 @@ func restoreChannelsCmdF(command *cobra.Command, args []string) error {
}
func modifyChannelCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}

Просмотреть файл

@@ -8,7 +8,6 @@ import (
"testing"
"github.com/mattermost/mattermost-server/api4"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/stretchr/testify/require"
)
@@ -19,13 +18,13 @@ func TestJoinChannel(t *testing.T) {
channel := th.CreatePublicChannel()
cmd.CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
// Joining twice should succeed
cmd.CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
// should fail because channel does not exist
require.Error(t, cmd.RunCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name+"asdf", th.BasicUser2.Email))
require.Error(t, RunCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name+"asdf", th.BasicUser2.Email))
}
func TestRemoveChannel(t *testing.T) {
@@ -34,15 +33,15 @@ func TestRemoveChannel(t *testing.T) {
channel := th.CreatePublicChannel()
cmd.CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
// should fail because channel does not exist
require.Error(t, cmd.RunCommand(t, "channel", "remove", th.BasicTeam.Name+":doesnotexist", th.BasicUser2.Email))
require.Error(t, RunCommand(t, "channel", "remove", th.BasicTeam.Name+":doesnotexist", th.BasicUser2.Email))
cmd.CheckCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
CheckCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
// Leaving twice should succeed
cmd.CheckCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
CheckCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
}
func TestMoveChannel(t *testing.T) {
@@ -63,12 +62,12 @@ func TestMoveChannel(t *testing.T) {
origin := team1.Name + ":" + channel.Name
dest := team2.Name
cmd.CheckCommand(t, "channel", "add", origin, adminEmail)
CheckCommand(t, "channel", "add", origin, adminEmail)
// should fail with nill because errors are logged instead of returned when a channel does not exist
require.Nil(t, cmd.RunCommand(t, "channel", "move", dest, team1.Name+":doesnotexist", "--username", adminUsername))
require.Nil(t, RunCommand(t, "channel", "move", dest, team1.Name+":doesnotexist", "--username", adminUsername))
cmd.CheckCommand(t, "channel", "move", dest, origin, "--username", adminUsername)
CheckCommand(t, "channel", "move", dest, origin, "--username", adminUsername)
}
func TestListChannels(t *testing.T) {
@@ -78,7 +77,7 @@ func TestListChannels(t *testing.T) {
channel := th.CreatePublicChannel()
th.Client.Must(th.Client.DeleteChannel(channel.Id))
output := cmd.CheckCommand(t, "channel", "list", th.BasicTeam.Name)
output := CheckCommand(t, "channel", "list", th.BasicTeam.Name)
if !strings.Contains(string(output), "town-square") {
t.Fatal("should have channels")
@@ -96,10 +95,10 @@ func TestRestoreChannel(t *testing.T) {
channel := th.CreatePublicChannel()
th.Client.Must(th.Client.DeleteChannel(channel.Id))
cmd.CheckCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name)
CheckCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name)
// restoring twice should succeed
cmd.CheckCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name)
CheckCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name)
}
func TestCreateChannel(t *testing.T) {
@@ -109,8 +108,8 @@ func TestCreateChannel(t *testing.T) {
id := model.NewId()
name := "name" + id
cmd.CheckCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--name", name)
CheckCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--name", name)
name = name + "-private"
cmd.CheckCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--private", "--name", name)
CheckCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--private", "--name", name)
}

Просмотреть файл

Просмотреть файл

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package cmd
package commands
import (
"flag"

Просмотреть файл

@@ -7,7 +7,6 @@ import (
"errors"
"github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/spf13/cobra"
)
@@ -29,11 +28,11 @@ func init() {
CommandCmd.AddCommand(
CommandMoveCmd,
)
cmd.RootCmd.AddCommand(CommandCmd)
RootCmd.AddCommand(CommandCmd)
}
func moveCommandCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -49,16 +48,16 @@ func moveCommandCmdF(command *cobra.Command, args []string) error {
}
commands := getCommandsFromCommandArgs(a, args[1:])
cmd.CommandPrintErrorln(commands)
CommandPrintErrorln(commands)
for i, command := range commands {
if command == nil {
cmd.CommandPrintErrorln("Unable to find command '" + args[i+1] + "'")
CommandPrintErrorln("Unable to find command '" + args[i+1] + "'")
continue
}
if err := moveCommand(a, team, command); err != nil {
cmd.CommandPrintErrorln("Unable to move command '" + command.Trigger + "' error: " + err.Error())
CommandPrintErrorln("Unable to move command '" + command.Trigger + "' error: " + err.Error())
} else {
cmd.CommandPrettyPrintln("Moved command '" + command.Trigger + "'")
CommandPrettyPrintln("Moved command '" + command.Trigger + "'")
}
}

Просмотреть файл

Просмотреть файл

@@ -8,7 +8,6 @@ import (
"errors"
"os"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
"github.com/spf13/cobra"
@@ -30,7 +29,7 @@ func init() {
ConfigCmd.AddCommand(
ValidateConfigCmd,
)
cmd.RootCmd.AddCommand(ConfigCmd)
RootCmd.AddCommand(ConfigCmd)
}
func configValidateCmdF(command *cobra.Command, args []string) error {
@@ -63,6 +62,6 @@ func configValidateCmdF(command *cobra.Command, args []string) error {
return errors.New(utils.T(err.Id))
}
cmd.CommandPrettyPrintln("The document is valid")
CommandPrettyPrintln("The document is valid")
return nil
}

Просмотреть файл

@@ -13,7 +13,6 @@ import (
"encoding/json"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/utils"
)
@@ -42,8 +41,8 @@ func TestConfigFlag(t *testing.T) {
defer os.Chdir(prevDir)
os.Chdir(dir)
require.Error(t, cmd.RunCommand(t, "version"))
cmd.CheckCommand(t, "--config", "foo.json", "version")
cmd.CheckCommand(t, "--config", "./foo.json", "version")
cmd.CheckCommand(t, "--config", configPath, "version")
require.Error(t, RunCommand(t, "version"))
CheckCommand(t, "--config", "foo.json", "version")
CheckCommand(t, "--config", "./foo.json", "version")
CheckCommand(t, "--config", configPath, "version")
}

Просмотреть файл

@@ -9,7 +9,6 @@ import (
"path/filepath"
"testing"
"github.com/mattermost/mattermost-server/cmd"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -26,6 +25,6 @@ func TestConfigValidate(t *testing.T) {
config.SetDefaults()
require.NoError(t, ioutil.WriteFile(path, []byte(config.ToJson()), 0600))
assert.Error(t, cmd.RunCommand(t, "--config", "foo.json", "config", "validate"))
assert.NoError(t, cmd.RunCommand(t, "--config", path, "config", "validate"))
assert.Error(t, RunCommand(t, "--config", "foo.json", "config", "validate"))
assert.NoError(t, RunCommand(t, "--config", path, "config", "validate"))
}

Просмотреть файл

@@ -8,14 +8,12 @@ import (
"testing"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/cmd"
)
func TestExecCommand(t *testing.T) {
if filter := flag.Lookup("test.run").Value.String(); filter != "ExecCommand" {
t.Skip("use -run ExecCommand to execute a command via the test executable")
}
cmd.RootCmd.SetArgs(flag.Args())
require.NoError(t, cmd.RootCmd.Execute())
RootCmd.SetArgs(flag.Args())
require.NoError(t, RootCmd.Execute())
}

Просмотреть файл

@@ -9,7 +9,6 @@ import (
"fmt"
"github.com/mattermost/mattermost-server/cmd"
"github.com/spf13/cobra"
)
@@ -43,11 +42,11 @@ func init() {
BulkImportCmd,
SlackImportCmd,
)
cmd.RootCmd.AddCommand(ImportCmd)
RootCmd.AddCommand(ImportCmd)
}
func slackImportCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -73,17 +72,17 @@ func slackImportCmdF(command *cobra.Command, args []string) error {
return err
}
cmd.CommandPrettyPrintln("Running Slack Import. This may take a long time for large teams or teams with many messages.")
CommandPrettyPrintln("Running Slack Import. This may take a long time for large teams or teams with many messages.")
a.SlackImport(fileReader, fileInfo.Size(), team.Id)
cmd.CommandPrettyPrintln("Finished Slack Import.")
CommandPrettyPrintln("Finished Slack Import.")
return nil
}
func bulkImportCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -115,29 +114,29 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
defer fileReader.Close()
if apply && validate {
cmd.CommandPrettyPrintln("Use only one of --apply or --validate.")
CommandPrettyPrintln("Use only one of --apply or --validate.")
return nil
} else if apply && !validate {
cmd.CommandPrettyPrintln("Running Bulk Import. This may take a long time.")
CommandPrettyPrintln("Running Bulk Import. This may take a long time.")
} else {
cmd.CommandPrettyPrintln("Running Bulk Import Data Validation.")
cmd.CommandPrettyPrintln("** This checks the validity of the entities in the data file, but does not persist any changes **")
cmd.CommandPrettyPrintln("Use the --apply flag to perform the actual data import.")
CommandPrettyPrintln("Running Bulk Import Data Validation.")
CommandPrettyPrintln("** This checks the validity of the entities in the data file, but does not persist any changes **")
CommandPrettyPrintln("Use the --apply flag to perform the actual data import.")
}
cmd.CommandPrettyPrintln("")
CommandPrettyPrintln("")
if err, lineNumber := a.BulkImport(fileReader, !apply, workers); err != nil {
cmd.CommandPrettyPrintln(err.Error())
CommandPrettyPrintln(err.Error())
if lineNumber != 0 {
cmd.CommandPrettyPrintln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
CommandPrettyPrintln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
}
return err
} else {
if apply {
cmd.CommandPrettyPrintln("Finished Bulk Import.")
CommandPrettyPrintln("Finished Bulk Import.")
} else {
cmd.CommandPrettyPrintln("Validation complete. You can now perform the import by rerunning this command with the --apply flag.")
CommandPrettyPrintln("Validation complete. You can now perform the import by rerunning this command with the --apply flag.")
}
}

Просмотреть файл

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package cmd
package commands
import (
"github.com/mattermost/mattermost-server/app"
@@ -10,8 +10,8 @@ import (
"github.com/spf13/cobra"
)
func InitDBCommandContextCobra(cmd *cobra.Command) (*app.App, error) {
config, err := cmd.Flags().GetString("config")
func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) {
config, err := command.Flags().GetString("config")
if err != nil {
return nil, err
}

Просмотреть файл

@@ -8,7 +8,6 @@ import (
"os/signal"
"syscall"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/mlog"
"github.com/spf13/cobra"
)
@@ -23,7 +22,7 @@ func init() {
JobserverCmd.Flags().Bool("nojobs", false, "Do not run jobs on this jobserver.")
JobserverCmd.Flags().Bool("noschedule", false, "Do not schedule jobs from this jobserver.")
cmd.RootCmd.AddCommand(JobserverCmd)
RootCmd.AddCommand(JobserverCmd)
}
func jobserverCmdF(command *cobra.Command, args []string) {
@@ -32,7 +31,7 @@ func jobserverCmdF(command *cobra.Command, args []string) {
noSchedule, _ := command.Flags().GetBool("noschedule")
// Initialize
a, err := cmd.InitDBCommandContext("config.json")
a, err := InitDBCommandContext("config.json")
if err != nil {
panic(err.Error())
}

Просмотреть файл

@@ -4,7 +4,6 @@
package commands
import (
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/spf13/cobra"
)
@@ -36,11 +35,11 @@ func init() {
LdapSyncCmd,
LdapIdMigrate,
)
cmd.RootCmd.AddCommand(LdapCmd)
RootCmd.AddCommand(LdapCmd)
}
func ldapSyncCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -49,9 +48,9 @@ func ldapSyncCmdF(command *cobra.Command, args []string) error {
if ldapI := a.Ldap; ldapI != nil {
job, err := ldapI.StartSynchronizeJob(true)
if err != nil || job.Status == model.JOB_STATUS_ERROR || job.Status == model.JOB_STATUS_CANCELED {
cmd.CommandPrintErrorln("ERROR: AD/LDAP Synchronization please check the server logs")
CommandPrintErrorln("ERROR: AD/LDAP Synchronization please check the server logs")
} else {
cmd.CommandPrettyPrintln("SUCCESS: AD/LDAP Synchronization Complete")
CommandPrettyPrintln("SUCCESS: AD/LDAP Synchronization Complete")
}
}
@@ -59,7 +58,7 @@ func ldapSyncCmdF(command *cobra.Command, args []string) error {
}
func ldapIdMigrateCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -68,9 +67,9 @@ func ldapIdMigrateCmdF(command *cobra.Command, args []string) error {
toAttribute := args[0]
if ldapI := a.Ldap; ldapI != nil {
if err := ldapI.MigrateIDAttribute(toAttribute); err != nil {
cmd.CommandPrintErrorln("ERROR: AD/LDAP IdAttribute migration failed! Error: " + err.Error())
CommandPrintErrorln("ERROR: AD/LDAP IdAttribute migration failed! Error: " + err.Error())
} else {
cmd.CommandPrettyPrintln("SUCCESS: AD/LDAP IdAttribute migration complete. You can now change your IdAttribute to: " + toAttribute)
CommandPrettyPrintln("SUCCESS: AD/LDAP IdAttribute migration complete. You can now change your IdAttribute to: " + toAttribute)
}
}

Просмотреть файл

@@ -7,7 +7,6 @@ import (
"errors"
"io/ioutil"
"github.com/mattermost/mattermost-server/cmd"
"github.com/spf13/cobra"
)
@@ -26,11 +25,11 @@ var UploadLicenseCmd = &cobra.Command{
func init() {
LicenseCmd.AddCommand(UploadLicenseCmd)
cmd.RootCmd.AddCommand(LicenseCmd)
RootCmd.AddCommand(LicenseCmd)
}
func uploadLicenseCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -49,7 +48,7 @@ func uploadLicenseCmdF(command *cobra.Command, args []string) error {
return err
}
cmd.CommandPrettyPrintln("Uploaded license file")
CommandPrettyPrintln("Uploaded license file")
return nil
}

Просмотреть файл

@@ -10,7 +10,6 @@ import (
"time"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/spf13/cobra"
)
@@ -27,11 +26,11 @@ func init() {
MessageExportCmd.Flags().String("format", "actiance", "The format to export data in")
MessageExportCmd.Flags().Int64("exportFrom", -1, "The timestamp of the earliest post to export, expressed in seconds since the unix epoch.")
MessageExportCmd.Flags().Int("timeoutSeconds", -1, "The maximum number of seconds to wait for the job to complete before timing out.")
cmd.RootCmd.AddCommand(MessageExportCmd)
RootCmd.AddCommand(MessageExportCmd)
}
func messageExportCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -72,9 +71,9 @@ func messageExportCmdF(command *cobra.Command, args []string) error {
job, err := messageExportI.StartSynchronizeJob(ctx, startTime)
if err != nil || job.Status == model.JOB_STATUS_ERROR || job.Status == model.JOB_STATUS_CANCELED {
cmd.CommandPrintErrorln("ERROR: Message export job failed. Please check the server logs")
CommandPrintErrorln("ERROR: Message export job failed. Please check the server logs")
} else {
cmd.CommandPrettyPrintln("SUCCESS: Message export job complete")
CommandPrettyPrintln("SUCCESS: Message export job complete")
}
}

Просмотреть файл

@@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
)
@@ -25,7 +24,7 @@ func TestMessageExportNotEnabled(t *testing.T) {
defer os.RemoveAll(filepath.Dir(configPath))
// should fail fast because the feature isn't enabled
require.Error(t, cmd.RunCommand(t, "--config", configPath, "export"))
require.Error(t, RunCommand(t, "--config", configPath, "export"))
}
func TestMessageExportInvalidFormat(t *testing.T) {
@@ -33,7 +32,7 @@ func TestMessageExportInvalidFormat(t *testing.T) {
defer os.RemoveAll(filepath.Dir(configPath))
// should fail fast because format isn't supported
require.Error(t, cmd.RunCommand(t, "--config", configPath, "--format", "not_actiance", "export"))
require.Error(t, RunCommand(t, "--config", configPath, "--format", "not_actiance", "export"))
}
func TestMessageExportNegativeExportFrom(t *testing.T) {
@@ -41,7 +40,7 @@ func TestMessageExportNegativeExportFrom(t *testing.T) {
defer os.RemoveAll(filepath.Dir(configPath))
// should fail fast because export from must be a valid timestamp
require.Error(t, cmd.RunCommand(t, "--config", configPath, "--format", "actiance", "--exportFrom", "-1", "export"))
require.Error(t, RunCommand(t, "--config", configPath, "--format", "actiance", "--exportFrom", "-1", "export"))
}
func TestMessageExportNegativeTimeoutSeconds(t *testing.T) {
@@ -49,7 +48,7 @@ func TestMessageExportNegativeTimeoutSeconds(t *testing.T) {
defer os.RemoveAll(filepath.Dir(configPath))
// should fail fast because timeout seconds must be a positive int
require.Error(t, cmd.RunCommand(t, "--config", configPath, "--format", "actiance", "--exportFrom", "0", "--timeoutSeconds", "-1", "export"))
require.Error(t, RunCommand(t, "--config", configPath, "--format", "actiance", "--exportFrom", "0", "--timeoutSeconds", "-1", "export"))
}
func writeTempConfig(t *testing.T, isMessageExportEnabled bool) string {

Просмотреть файл

@@ -1,7 +1,7 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package cmd
package commands
import (
"fmt"

Просмотреть файл

@@ -10,7 +10,6 @@ import (
"github.com/spf13/cobra"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/utils"
)
@@ -54,11 +53,11 @@ func init() {
ExportPermissionsCmd,
ImportPermissionsCmd,
)
cmd.RootCmd.AddCommand(PermissionsCmd)
RootCmd.AddCommand(PermissionsCmd)
}
func resetPermissionsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -66,13 +65,13 @@ func resetPermissionsCmdF(command *cobra.Command, args []string) error {
confirmFlag, _ := command.Flags().GetBool("confirm")
if !confirmFlag {
var confirm string
cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
fmt.Scanln(&confirm)
if confirm != "YES" {
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
}
cmd.CommandPrettyPrintln("Are you sure you want to reset the permissions system? All data related to the permissions system will be permanently deleted and all users will revert to having the default permissions. (YES/NO): ")
CommandPrettyPrintln("Are you sure you want to reset the permissions system? All data related to the permissions system will be permanently deleted and all users will revert to having the default permissions. (YES/NO): ")
fmt.Scanln(&confirm)
if confirm != "YES" {
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
@@ -83,13 +82,13 @@ func resetPermissionsCmdF(command *cobra.Command, args []string) error {
return errors.New(err.Error())
}
cmd.CommandPrettyPrintln("Permissions system successfully reset")
CommandPrettyPrintln("Permissions system successfully reset")
return nil
}
func exportPermissionsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -107,7 +106,7 @@ func exportPermissionsCmdF(command *cobra.Command, args []string) error {
}
func importPermissionsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}

Просмотреть файл

@@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"github.com/mattermost/mattermost-server/cmd"
"github.com/spf13/cobra"
)
@@ -21,11 +20,11 @@ var ResetCmd = &cobra.Command{
func init() {
ResetCmd.Flags().Bool("confirm", false, "Confirm you really want to delete everything and a DB backup has been performed.")
cmd.RootCmd.AddCommand(ResetCmd)
RootCmd.AddCommand(ResetCmd)
}
func resetCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -34,13 +33,13 @@ func resetCmdF(command *cobra.Command, args []string) error {
confirmFlag, _ := command.Flags().GetBool("confirm")
if !confirmFlag {
var confirm string
cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
fmt.Scanln(&confirm)
if confirm != "YES" {
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
}
cmd.CommandPrettyPrintln("Are you sure you want to delete everything? All data will be permanently deleted? (YES/NO): ")
CommandPrettyPrintln("Are you sure you want to delete everything? All data will be permanently deleted? (YES/NO): ")
fmt.Scanln(&confirm)
if confirm != "YES" {
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
@@ -48,7 +47,7 @@ func resetCmdF(command *cobra.Command, args []string) error {
}
a.Srv.Store.DropAllTables()
cmd.CommandPrettyPrintln("Database successfully reset")
CommandPrettyPrintln("Database successfully reset")
return nil
}

Просмотреть файл

@@ -9,7 +9,6 @@ import (
"github.com/spf13/cobra"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
)
@@ -39,11 +38,11 @@ func init() {
MakeSystemAdminCmd,
MakeMemberCmd,
)
cmd.RootCmd.AddCommand(RolesCmd)
RootCmd.AddCommand(RolesCmd)
}
func makeSystemAdminCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -88,7 +87,7 @@ func makeSystemAdminCmdF(command *cobra.Command, args []string) error {
}
func makeMemberCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}

Просмотреть файл

@@ -7,7 +7,6 @@ import (
"testing"
"github.com/mattermost/mattermost-server/api4"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
)
@@ -15,7 +14,7 @@ func TestAssignRole(t *testing.T) {
th := api4.Setup().InitBasic()
defer th.TearDown()
cmd.CheckCommand(t, "roles", "system_admin", th.BasicUser.Email)
CheckCommand(t, "roles", "system_admin", th.BasicUser.Email)
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
t.Fatal()
@@ -26,7 +25,7 @@ func TestAssignRole(t *testing.T) {
}
}
cmd.CheckCommand(t, "roles", "member", th.BasicUser.Email)
CheckCommand(t, "roles", "member", th.BasicUser.Email)
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
t.Fatal()

Просмотреть файл

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package cmd
package commands
import (
"github.com/spf13/cobra"
@@ -23,4 +23,6 @@ var RootCmd = &cobra.Command{
func init() {
RootCmd.PersistentFlags().StringP("config", "c", "config.json", "Configuration file to use.")
RootCmd.PersistentFlags().Bool("disableconfigwatch", false, "When set config.json will not be loaded from disk when the file is changed.")
RootCmd.PersistentFlags().Bool("platform", false, "This flag signifies that the user tried to start the command from the platform binary, so we can log a mssage")
RootCmd.PersistentFlags().MarkHidden("platform")
}

Просмотреть файл

@@ -17,7 +17,6 @@ import (
"github.com/icrowley/fake"
"github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/cmd"
"github.com/spf13/cobra"
)
@@ -42,7 +41,7 @@ func init() {
SampleDataCmd.Flags().IntP("workers", "w", 2, "How many workers to run during the import.")
SampleDataCmd.Flags().String("profile-images", "", "Optional. Path to folder with images to randomly pick as user profile image.")
SampleDataCmd.Flags().StringP("bulk", "b", "", "Optional. Path to write a JSONL bulk file instead of loading into the database.")
cmd.RootCmd.AddCommand(SampleDataCmd)
RootCmd.AddCommand(SampleDataCmd)
}
func sliceIncludes(vs []string, t string) bool {
@@ -130,7 +129,7 @@ func randomMessage(users []string) string {
}
func sampleDataCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}

Просмотреть файл

@@ -7,7 +7,6 @@ import (
"testing"
"github.com/mattermost/mattermost-server/api4"
"github.com/mattermost/mattermost-server/cmd"
"github.com/stretchr/testify/require"
)
@@ -16,11 +15,11 @@ func TestSampledataBadParameters(t *testing.T) {
defer th.TearDown()
// should fail because you need at least 1 worker
require.Error(t, cmd.RunCommand(t, "sampledata", "--workers", "0"))
require.Error(t, RunCommand(t, "sampledata", "--workers", "0"))
// should fail because you have more team memberships than teams
require.Error(t, cmd.RunCommand(t, "sampledata", "--teams", "10", "--teams-memberships", "11"))
require.Error(t, RunCommand(t, "sampledata", "--teams", "10", "--teams-memberships", "11"))
// should fail because you have more channel memberships than channels per team
require.Error(t, cmd.RunCommand(t, "sampledata", "--channels-per-team", "10", "--channel-memberships", "11"))
require.Error(t, RunCommand(t, "sampledata", "--channels-per-team", "10", "--channel-memberships", "11"))
}

Просмотреть файл

@@ -13,7 +13,6 @@ import (
"github.com/mattermost/mattermost-server/api4"
"github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/manualtesting"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
@@ -37,8 +36,8 @@ var serverCmd = &cobra.Command{
}
func init() {
cmd.RootCmd.AddCommand(serverCmd)
cmd.RootCmd.RunE = serverCmdF
RootCmd.AddCommand(serverCmd)
RootCmd.RunE = serverCmdF
}
func serverCmdF(command *cobra.Command, args []string) error {
@@ -48,12 +47,13 @@ func serverCmdF(command *cobra.Command, args []string) error {
}
disableConfigWatch, _ := command.Flags().GetBool("disableconfigwatch")
usedPlatform, _ := command.Flags().GetBool("platform")
interruptChan := make(chan os.Signal, 1)
return runServer(config, disableConfigWatch, interruptChan)
return runServer(config, disableConfigWatch, usedPlatform, interruptChan)
}
func runServer(configFileLocation string, disableConfigWatch bool, interruptChan chan os.Signal) error {
func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform bool, interruptChan chan os.Signal) error {
options := []app.Option{app.ConfigFile(configFileLocation)}
if disableConfigWatch {
options = append(options, app.DisableConfigWatch)
@@ -69,6 +69,9 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan
utils.TestConnection(a.Config())
pwd, _ := os.Getwd()
if usedPlatform {
mlog.Error("The platform binary has been deprecated, please switch to using the mattermost binary.")
}
mlog.Info(fmt.Sprintf("Current version is %v (%v/%v/%v/%v)", model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash, model.BuildHashEnterprise))
mlog.Info(fmt.Sprintf("Enterprise Enabled: %v", model.BuildEnterpriseReady))
mlog.Info(fmt.Sprintf("Current working directory is %v", pwd))

Просмотреть файл

@@ -52,7 +52,7 @@ func TestRunServerSuccess(t *testing.T) {
th := SetupServerTest()
defer th.TearDownServerTest()
err := runServer(th.configPath, th.disableConfigWatch, th.interruptChan)
err := runServer(th.configPath, th.disableConfigWatch, false, th.interruptChan)
require.NoError(t, err)
}
@@ -68,7 +68,7 @@ func TestRunServerInvalidConfigFile(t *testing.T) {
os.Chmod(unreadableConfigFile.Name(), 0200)
defer os.Remove(unreadableConfigFile.Name())
err = runServer(unreadableConfigFile.Name(), th.disableConfigWatch, th.interruptChan)
err = runServer(unreadableConfigFile.Name(), th.disableConfigWatch, false, th.interruptChan)
require.Error(t, err)
}
@@ -114,7 +114,7 @@ func TestRunServerSystemdNotification(t *testing.T) {
}(socketReader)
// Start and stop the server
err = runServer(th.configPath, th.disableConfigWatch, th.interruptChan)
err = runServer(th.configPath, th.disableConfigWatch, false, th.interruptChan)
require.NoError(t, err)
// Ensure the notification has been sent on the socket and is correct
@@ -131,6 +131,6 @@ func TestRunServerNoSystemd(t *testing.T) {
os.Unsetenv("NOTIFY_SOCKET")
defer os.Setenv("NOTIFY_SOCKET", originalSocket)
err := runServer(th.configPath, th.disableConfigWatch, th.interruptChan)
err := runServer(th.configPath, th.disableConfigWatch, false, th.interruptChan)
require.NoError(t, err)
}

Просмотреть файл

@@ -8,7 +8,6 @@ import (
"fmt"
"github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/spf13/cobra"
)
@@ -75,11 +74,11 @@ func init() {
DeleteTeamsCmd,
ListTeamsCmd,
)
cmd.RootCmd.AddCommand(TeamCmd)
RootCmd.AddCommand(TeamCmd)
}
func createTeamCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -116,7 +115,7 @@ func createTeamCmdF(command *cobra.Command, args []string) error {
}
func removeUsersCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -141,16 +140,16 @@ func removeUsersCmdF(command *cobra.Command, args []string) error {
func removeUserFromTeam(a *app.App, team *model.Team, user *model.User, userArg string) {
if user == nil {
cmd.CommandPrintErrorln("Can't find user '" + userArg + "'")
CommandPrintErrorln("Can't find user '" + userArg + "'")
return
}
if err := a.LeaveTeam(team, user, ""); err != nil {
cmd.CommandPrintErrorln("Unable to remove '" + userArg + "' from " + team.Name + ". Error: " + err.Error())
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + team.Name + ". Error: " + err.Error())
}
}
func addUsersCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -175,16 +174,16 @@ func addUsersCmdF(command *cobra.Command, args []string) error {
func addUserToTeam(a *app.App, team *model.Team, user *model.User, userArg string) {
if user == nil {
cmd.CommandPrintErrorln("Can't find user '" + userArg + "'")
CommandPrintErrorln("Can't find user '" + userArg + "'")
return
}
if err := a.JoinUserToTeam(team, user, ""); err != nil {
cmd.CommandPrintErrorln("Unable to add '" + userArg + "' to " + team.Name)
CommandPrintErrorln("Unable to add '" + userArg + "' to " + team.Name)
}
}
func deleteTeamsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -197,13 +196,13 @@ func deleteTeamsCmdF(command *cobra.Command, args []string) error {
confirmFlag, _ := command.Flags().GetBool("confirm")
if !confirmFlag {
var confirm string
cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
fmt.Scanln(&confirm)
if confirm != "YES" {
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
}
cmd.CommandPrettyPrintln("Are you sure you want to delete the teams specified? All data will be permanently deleted? (YES/NO): ")
CommandPrettyPrintln("Are you sure you want to delete the teams specified? All data will be permanently deleted? (YES/NO): ")
fmt.Scanln(&confirm)
if confirm != "YES" {
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
@@ -213,13 +212,13 @@ func deleteTeamsCmdF(command *cobra.Command, args []string) error {
teams := getTeamsFromTeamArgs(a, args)
for i, team := range teams {
if team == nil {
cmd.CommandPrintErrorln("Unable to find team '" + args[i] + "'")
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
continue
}
if err := deleteTeam(a, team); err != nil {
cmd.CommandPrintErrorln("Unable to delete team '" + team.Name + "' error: " + err.Error())
CommandPrintErrorln("Unable to delete team '" + team.Name + "' error: " + err.Error())
} else {
cmd.CommandPrettyPrintln("Deleted team '" + team.Name + "'")
CommandPrettyPrintln("Deleted team '" + team.Name + "'")
}
}
@@ -231,7 +230,7 @@ func deleteTeam(a *app.App, team *model.Team) *model.AppError {
}
func listTeamsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -243,7 +242,7 @@ func listTeamsCmdF(command *cobra.Command, args []string) error {
}
for _, team := range teams {
cmd.CommandPrettyPrintln(team.Name)
CommandPrettyPrintln(team.Name)
}
return nil

Просмотреть файл

@@ -8,7 +8,6 @@ import (
"testing"
"github.com/mattermost/mattermost-server/api4"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
)
@@ -20,7 +19,7 @@ func TestCreateTeam(t *testing.T) {
name := "name" + id
displayName := "Name " + id
cmd.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
found := th.SystemAdminClient.Must(th.SystemAdminClient.TeamExists(name, "")).(bool)
@@ -33,7 +32,7 @@ func TestJoinTeam(t *testing.T) {
th := api4.Setup().InitSystemAdmin().InitBasic()
defer th.TearDown()
cmd.CheckCommand(t, "team", "add", th.BasicTeam.Name, th.BasicUser.Email)
CheckCommand(t, "team", "add", th.BasicTeam.Name, th.BasicUser.Email)
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
@@ -55,7 +54,7 @@ func TestLeaveTeam(t *testing.T) {
th := api4.Setup().InitBasic()
defer th.TearDown()
cmd.CheckCommand(t, "team", "remove", th.BasicTeam.Name, th.BasicUser.Email)
CheckCommand(t, "team", "remove", th.BasicTeam.Name, th.BasicUser.Email)
profiles := th.Client.Must(th.Client.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
@@ -88,9 +87,9 @@ func TestListTeams(t *testing.T) {
name := "name" + id
displayName := "Name " + id
cmd.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
output := cmd.CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email)
output := CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email)
if !strings.Contains(string(output), name) {
t.Fatal("should have the created team")

Просмотреть файл

Просмотреть файл

@@ -13,7 +13,6 @@ import (
"syscall"
"github.com/mattermost/mattermost-server/api4"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
"github.com/mattermost/mattermost-server/wsapi"
@@ -43,11 +42,11 @@ func init() {
RunWebClientTestsCmd,
RunServerForWebClientTestsCmd,
)
cmd.RootCmd.AddCommand(TestCmd)
RootCmd.AddCommand(TestCmd)
}
func webClientTestsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -68,7 +67,7 @@ func webClientTestsCmdF(command *cobra.Command, args []string) error {
}
func serverForWebClientTestsCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -103,14 +102,14 @@ func setupClientTests(cfg *model.Config) {
func executeTestCommand(command *exec.Cmd) {
cmdOutPipe, err := command.StdoutPipe()
if err != nil {
cmd.CommandPrintErrorln("Failed to run tests")
CommandPrintErrorln("Failed to run tests")
os.Exit(1)
return
}
cmdErrOutPipe, err := command.StderrPipe()
if err != nil {
cmd.CommandPrintErrorln("Failed to run tests")
CommandPrintErrorln("Failed to run tests")
os.Exit(1)
return
}
@@ -130,7 +129,7 @@ func executeTestCommand(command *exec.Cmd) {
}()
if err := command.Run(); err != nil {
cmd.CommandPrintErrorln("Client Tests failed")
CommandPrintErrorln("Client Tests failed")
os.Exit(1)
return
}

Просмотреть файл

@@ -10,7 +10,6 @@ import (
"io/ioutil"
"github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/spf13/cobra"
)
@@ -104,7 +103,7 @@ var MigrateAuthCmd = &cobra.Command{
Short: "Mass migrate user accounts authentication type",
Long: `Migrates accounts from one authentication provider to another. For example, you can upgrade your authentication provider from email to ldap.`,
Example: " user migrate_auth email saml users.json",
Args: func(cmd *cobra.Command, args []string) error {
Args: func(command *cobra.Command, args []string) error {
if len(args) < 2 {
return errors.New("Auth migration requires at least 2 arguments.")
}
@@ -119,7 +118,7 @@ var MigrateAuthCmd = &cobra.Command{
return errors.New("Ldap migration requires 3 arguments.")
}
autoFlag, _ := cmd.Flags().GetBool("auto")
autoFlag, _ := command.Flags().GetBool("auto")
if toAuth == "saml" && autoFlag {
if len(args) != 2 {
@@ -245,11 +244,11 @@ Global Flags:
VerifyUserCmd,
SearchUserCmd,
)
cmd.RootCmd.AddCommand(UserCmd)
RootCmd.AddCommand(UserCmd)
}
func userActivateCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -270,7 +269,7 @@ func changeUsersActiveStatus(a *app.App, userArgs []string, active bool) {
err := changeUserActiveStatus(a, user, userArgs[i], active)
if err != nil {
cmd.CommandPrintErrorln(err.Error())
CommandPrintErrorln(err.Error())
}
}
}
@@ -290,7 +289,7 @@ func changeUserActiveStatus(a *app.App, user *model.User, userArg string, activa
}
func userDeactivateCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -306,7 +305,7 @@ func userDeactivateCmdF(command *cobra.Command, args []string) error {
}
func userCreateCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -346,13 +345,13 @@ func userCreateCmdF(command *cobra.Command, args []string) error {
a.UpdateUserRoles(ruser.Id, "system_user system_admin", false)
}
cmd.CommandPrettyPrintln("Created User")
CommandPrettyPrintln("Created User")
return nil
}
func userInviteCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -372,7 +371,7 @@ func userInviteCmdF(command *cobra.Command, args []string) error {
err := inviteUser(a, email, team, args[i+1])
if err != nil {
cmd.CommandPrintErrorln(err.Error())
CommandPrintErrorln(err.Error())
}
}
@@ -386,13 +385,13 @@ func inviteUser(a *app.App, email string, team *model.Team, teamArg string) erro
}
a.SendInviteEmails(team, "Administrator", invites, *a.Config().ServiceSettings.SiteURL)
cmd.CommandPrettyPrintln("Invites may or may not have been sent.")
CommandPrettyPrintln("Invites may or may not have been sent.")
return nil
}
func resetUserPasswordCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -416,7 +415,7 @@ func resetUserPasswordCmdF(command *cobra.Command, args []string) error {
}
func updateUserEmailCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -451,7 +450,7 @@ func updateUserEmailCmdF(command *cobra.Command, args []string) error {
}
func resetUserMfaCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -477,7 +476,7 @@ func resetUserMfaCmdF(command *cobra.Command, args []string) error {
}
func deleteUserCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -490,13 +489,13 @@ func deleteUserCmdF(command *cobra.Command, args []string) error {
confirmFlag, _ := command.Flags().GetBool("confirm")
if !confirmFlag {
var confirm string
cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
fmt.Scanln(&confirm)
if confirm != "YES" {
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
}
cmd.CommandPrettyPrintln("Are you sure you want to permanently delete the specified users? (YES/NO): ")
CommandPrettyPrintln("Are you sure you want to permanently delete the specified users? (YES/NO): ")
fmt.Scanln(&confirm)
if confirm != "YES" {
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
@@ -519,7 +518,7 @@ func deleteUserCmdF(command *cobra.Command, args []string) error {
}
func deleteAllUsersCommandF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -532,13 +531,13 @@ func deleteAllUsersCommandF(command *cobra.Command, args []string) error {
confirmFlag, _ := command.Flags().GetBool("confirm")
if !confirmFlag {
var confirm string
cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
fmt.Scanln(&confirm)
if confirm != "YES" {
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
}
cmd.CommandPrettyPrintln("Are you sure you want to permanently delete all user accounts? (YES/NO): ")
CommandPrettyPrintln("Are you sure you want to permanently delete all user accounts? (YES/NO): ")
fmt.Scanln(&confirm)
if confirm != "YES" {
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
@@ -549,7 +548,7 @@ func deleteAllUsersCommandF(command *cobra.Command, args []string) error {
return err
}
cmd.CommandPrettyPrintln("All user accounts successfully deleted.")
CommandPrettyPrintln("All user accounts successfully deleted.")
return nil
}
@@ -562,7 +561,7 @@ func migrateAuthCmdF(command *cobra.Command, args []string) error {
}
func migrateAuthToLdapCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -592,14 +591,14 @@ func migrateAuthToLdapCmdF(command *cobra.Command, args []string) error {
return errors.New("Error while migrating users: " + err.Error())
}
cmd.CommandPrettyPrintln("Successfully migrated accounts.")
CommandPrettyPrintln("Successfully migrated accounts.")
}
return nil
}
func migrateAuthToSamlCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -630,7 +629,7 @@ func migrateAuthToSamlCmdF(command *cobra.Command, args []string) error {
if autoFlag && !dryRunFlag {
var confirm string
cmd.CommandPrettyPrintln("You are about to perform an automatic \"" + fromAuth + " to saml\" migration. This must only be done if your current Mattermost users with " + fromAuth + " auth have the same username and email in your SAML service. Otherwise, provide the usernames and emails from your SAML Service using the \"users file\" without the \"--auto\" option.\n\nDo you want to proceed with automatic migration anyway? (YES/NO):")
CommandPrettyPrintln("You are about to perform an automatic \"" + fromAuth + " to saml\" migration. This must only be done if your current Mattermost users with " + fromAuth + " auth have the same username and email in your SAML service. Otherwise, provide the usernames and emails from your SAML Service using the \"users file\" without the \"--auto\" option.\n\nDo you want to proceed with automatic migration anyway? (YES/NO):")
fmt.Scanln(&confirm)
if confirm != "YES" {
@@ -648,14 +647,14 @@ func migrateAuthToSamlCmdF(command *cobra.Command, args []string) error {
return errors.New("Error while migrating users: " + err.Error())
}
cmd.CommandPrettyPrintln("Successfully migrated accounts.")
CommandPrettyPrintln("Successfully migrated accounts.")
}
return nil
}
func verifyUserCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -669,11 +668,11 @@ func verifyUserCmdF(command *cobra.Command, args []string) error {
for i, user := range users {
if user == nil {
cmd.CommandPrintErrorln("Unable to find user '" + args[i] + "'")
CommandPrintErrorln("Unable to find user '" + args[i] + "'")
continue
}
if cresult := <-a.Srv.Store.User().VerifyEmail(user.Id); cresult.Err != nil {
cmd.CommandPrintErrorln("Unable to verify '" + args[i] + "' email. Error: " + cresult.Err.Error())
CommandPrintErrorln("Unable to verify '" + args[i] + "' email. Error: " + cresult.Err.Error())
}
}
@@ -681,7 +680,7 @@ func verifyUserCmdF(command *cobra.Command, args []string) error {
}
func searchUserCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -695,21 +694,21 @@ func searchUserCmdF(command *cobra.Command, args []string) error {
for i, user := range users {
if i > 0 {
cmd.CommandPrettyPrintln("------------------------------")
CommandPrettyPrintln("------------------------------")
}
if user == nil {
cmd.CommandPrintErrorln("Unable to find user '" + args[i] + "'")
CommandPrintErrorln("Unable to find user '" + args[i] + "'")
continue
}
cmd.CommandPrettyPrintln("id: " + user.Id)
cmd.CommandPrettyPrintln("username: " + user.Username)
cmd.CommandPrettyPrintln("nickname: " + user.Nickname)
cmd.CommandPrettyPrintln("position: " + user.Position)
cmd.CommandPrettyPrintln("first_name: " + user.FirstName)
cmd.CommandPrettyPrintln("last_name: " + user.LastName)
cmd.CommandPrettyPrintln("email: " + user.Email)
cmd.CommandPrettyPrintln("auth_service: " + user.AuthService)
CommandPrettyPrintln("id: " + user.Id)
CommandPrettyPrintln("username: " + user.Username)
CommandPrettyPrintln("nickname: " + user.Nickname)
CommandPrettyPrintln("position: " + user.Position)
CommandPrettyPrintln("first_name: " + user.FirstName)
CommandPrettyPrintln("last_name: " + user.LastName)
CommandPrettyPrintln("email: " + user.Email)
CommandPrettyPrintln("auth_service: " + user.AuthService)
}
return nil

Просмотреть файл

@@ -7,7 +7,6 @@ import (
"testing"
"github.com/mattermost/mattermost-server/api4"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/stretchr/testify/require"
)
@@ -20,9 +19,9 @@ func TestCreateUserWithTeam(t *testing.T) {
email := "success+" + id + "@simulator.amazonses.com"
username := "name" + id
cmd.CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username)
CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username)
cmd.CheckCommand(t, "team", "add", th.BasicTeam.Id, email)
CheckCommand(t, "team", "add", th.BasicTeam.Id, email)
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
@@ -48,7 +47,7 @@ func TestCreateUserWithoutTeam(t *testing.T) {
email := "success+" + id + "@simulator.amazonses.com"
username := "name" + id
cmd.CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username)
CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username)
if result := <-th.App.Srv.Store.User().GetByEmail(email); result.Err != nil {
t.Fatal()
@@ -64,7 +63,7 @@ func TestResetPassword(t *testing.T) {
th := api4.Setup().InitBasic()
defer th.TearDown()
cmd.CheckCommand(t, "user", "password", th.BasicUser.Email, "password2")
CheckCommand(t, "user", "password", th.BasicUser.Email, "password2")
th.Client.Logout()
th.BasicUser.Password = "password2"
@@ -76,10 +75,10 @@ func TestMakeUserActiveAndInactive(t *testing.T) {
defer th.TearDown()
// first inactivate the user
cmd.CheckCommand(t, "user", "deactivate", th.BasicUser.Email)
CheckCommand(t, "user", "deactivate", th.BasicUser.Email)
// activate the inactive user
cmd.CheckCommand(t, "user", "activate", th.BasicUser.Email)
CheckCommand(t, "user", "activate", th.BasicUser.Email)
}
func TestChangeUserEmail(t *testing.T) {
@@ -88,7 +87,7 @@ func TestChangeUserEmail(t *testing.T) {
newEmail := model.NewId() + "@mattermost-test.com"
cmd.CheckCommand(t, "user", "email", th.BasicUser.Username, newEmail)
CheckCommand(t, "user", "email", th.BasicUser.Username, newEmail)
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err == nil {
t.Fatal("should've updated to the new email")
}
@@ -102,21 +101,21 @@ func TestChangeUserEmail(t *testing.T) {
}
// should fail because using an invalid email
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username, "wrong$email.com"))
require.Error(t, RunCommand(t, "user", "email", th.BasicUser.Username, "wrong$email.com"))
// should fail because missing one parameter
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username))
require.Error(t, RunCommand(t, "user", "email", th.BasicUser.Username))
// should fail because missing both parameters
require.Error(t, cmd.RunCommand(t, "user", "email"))
require.Error(t, RunCommand(t, "user", "email"))
// should fail because have more than 2 parameters
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username, "new@email.com", "extra!"))
require.Error(t, RunCommand(t, "user", "email", th.BasicUser.Username, "new@email.com", "extra!"))
// should fail because user not found
require.Error(t, cmd.RunCommand(t, "user", "email", "invalidUser", newEmail))
require.Error(t, RunCommand(t, "user", "email", "invalidUser", newEmail))
// should fail because email already in use
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username, th.BasicUser2.Email))
require.Error(t, RunCommand(t, "user", "email", th.BasicUser.Username, th.BasicUser2.Email))
}

Просмотреть файл

Просмотреть файл

@@ -5,7 +5,6 @@ package commands
import (
"github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/cmd"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
"github.com/mattermost/mattermost-server/store/sqlstore"
@@ -19,11 +18,11 @@ var VersionCmd = &cobra.Command{
}
func init() {
cmd.RootCmd.AddCommand(VersionCmd)
RootCmd.AddCommand(VersionCmd)
}
func versionCmdF(command *cobra.Command, args []string) error {
a, err := cmd.InitDBCommandContextCobra(command)
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
@@ -34,12 +33,12 @@ func versionCmdF(command *cobra.Command, args []string) error {
}
func printVersion(a *app.App) {
cmd.CommandPrintln("Version: " + model.CurrentVersion)
cmd.CommandPrintln("Build Number: " + model.BuildNumber)
cmd.CommandPrintln("Build Date: " + model.BuildDate)
cmd.CommandPrintln("Build Hash: " + model.BuildHash)
cmd.CommandPrintln("Build Enterprise Ready: " + model.BuildEnterpriseReady)
CommandPrintln("Version: " + model.CurrentVersion)
CommandPrintln("Build Number: " + model.BuildNumber)
CommandPrintln("Build Date: " + model.BuildDate)
CommandPrintln("Build Hash: " + model.BuildHash)
CommandPrintln("Build Enterprise Ready: " + model.BuildEnterpriseReady)
if supplier, ok := a.Srv.Store.(*store.LayeredStore).DatabaseLayer.(*sqlstore.SqlSupplier); ok {
cmd.CommandPrintln("DB Version: " + supplier.GetCurrentSchemaVersion())
CommandPrintln("DB Version: " + supplier.GetCurrentSchemaVersion())
}
}

Просмотреть файл

@@ -5,10 +5,8 @@ package commands
import (
"testing"
"github.com/mattermost/mattermost-server/cmd"
)
func TestVersion(t *testing.T) {
cmd.CheckCommand(t, "version")
CheckCommand(t, "version")
}

33
cmd/mattermost/main.go Обычный файл
Просмотреть файл

@@ -0,0 +1,33 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package main
import (
"os"
"github.com/mattermost/mattermost-server/cmd/mattermost/commands"
// Plugins
_ "github.com/mattermost/mattermost-server/model/gitlab"
// Enterprise Imports
_ "github.com/mattermost/mattermost-server/imports"
// Enterprise Deps
_ "github.com/dgryski/dgoogauth"
_ "github.com/go-ldap/ldap"
_ "github.com/hako/durafmt"
_ "github.com/hashicorp/memberlist"
_ "github.com/mattermost/rsc/qr"
_ "github.com/prometheus/client_golang/prometheus"
_ "github.com/prometheus/client_golang/prometheus/promhttp"
_ "github.com/tylerb/graceful"
_ "gopkg.in/olivere/elastic.v5"
)
func main() {
if err := commands.Run(os.Args[1:]); err != nil {
os.Exit(1)
}
}

39
cmd/platform/main.go Обычный файл
Просмотреть файл

@@ -0,0 +1,39 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package main
import (
"fmt"
"os"
"path/filepath"
"syscall"
)
func findMattermostBinary() string {
for _, file := range []string{"./mattermost", "../mattermost", "./bin/mattermost"} {
path, _ := filepath.Abs(file)
if stat, err := os.Stat(path); err == nil && !stat.IsDir() {
return path
}
}
return "./mattermost"
}
func main() {
// Print angry message to use mattermost command directly
fmt.Println(`
------------------------------------ ERROR ------------------------------------------------
The platform binary has been deprecated, please switch to using the new mattermost binary.
The platform binary will be removed in a future version.
-------------------------------------------------------------------------------------------
`)
// Execve the real MM binary
args := os.Args
args[0] = "mattermost"
args = append(args, "--platform")
if err := syscall.Exec(findMattermostBinary(), args, nil); err != nil {
fmt.Println("Could not start Mattermost, use the mattermost command directly.")
}
}