diff --git a/Makefile b/Makefile index 2c8ccf926d..a7d6c3e820 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ GO_LINKER_FLAGS ?= -ldflags \ # GOOS/GOARCH of the build host, used to determine whether we're cross-compiling or not BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)" -PLATFORM_FILES="./main.go" +PLATFORM_FILES="./cmd/mattermost/main.go" # Output paths DIST_ROOT=dist @@ -504,6 +504,7 @@ clean: stop-docker ## Clean up everything except persistant server data. rm -f *.test rm -f imports/imports.go rm -f cmd/platform/cprofile*.out + rm -f cmd/mattermost/cprofile*.out nuke: clean clean-docker ## Clean plus removes persistant server data. @echo BOOM diff --git a/build/release.mk b/build/release.mk index e634b2dd48..238343e82d 100644 --- a/build/release.mk +++ b/build/release.mk @@ -4,25 +4,25 @@ dist: | check-style test package build-linux: @echo Build Linux amd64 ifeq ($(BUILDER_GOOS_GOARCH),"linux_amd64") - env GOOS=linux GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/platform $(GOFLAGS) $(GO_LINKER_FLAGS) ./ + env GOOS=linux GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./... else - env GOOS=linux GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/linux_amd64/platform $(GOFLAGS) $(GO_LINKER_FLAGS) ./ + env GOOS=linux GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./... endif build-osx: @echo Build OSX amd64 ifeq ($(BUILDER_GOOS_GOARCH),"darwin_amd64") - env GOOS=darwin GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/platform $(GOFLAGS) $(GO_LINKER_FLAGS) ./ + env GOOS=darwin GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./... else - env GOOS=darwin GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/darwin_amd64/platform $(GOFLAGS) $(GO_LINKER_FLAGS) ./ + env GOOS=darwin GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./... endif build-windows: @echo Build Windows amd64 ifeq ($(BUILDER_GOOS_GOARCH),"windows_amd64") - env GOOS=windows GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/platform.exe $(GOFLAGS) $(GO_LINKER_FLAGS) ./ + env GOOS=windows GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./... else - env GOOS=windows GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/windows_amd64/platform.exe $(GOFLAGS) $(GO_LINKER_FLAGS) ./ + env GOOS=windows GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./... endif build: build-linux build-windows build-osx @@ -76,35 +76,43 @@ endif @# Make osx package @# Copy binary ifeq ($(BUILDER_GOOS_GOARCH),"darwin_amd64") + cp $(GOPATH)/bin/mattermost $(DIST_PATH)/bin # from native bin dir, not cross-compiled cp $(GOPATH)/bin/platform $(DIST_PATH)/bin # from native bin dir, not cross-compiled else + cp $(GOPATH)/bin/darwin_amd64/mattermost $(DIST_PATH)/bin # from cross-compiled bin dir cp $(GOPATH)/bin/darwin_amd64/platform $(DIST_PATH)/bin # from cross-compiled bin dir endif @# Package tar -C dist -czf $(DIST_PATH)-$(BUILD_TYPE_NAME)-osx-amd64.tar.gz mattermost @# Cleanup + rm -f $(DIST_PATH)/bin/mattermost rm -f $(DIST_PATH)/bin/platform @# Make windows package @# Copy binary ifeq ($(BUILDER_GOOS_GOARCH),"windows_amd64") + cp $(GOPATH)/bin/mattermost.exe $(DIST_PATH)/bin # from native bin dir, not cross-compiled cp $(GOPATH)/bin/platform.exe $(DIST_PATH)/bin # from native bin dir, not cross-compiled else + cp $(GOPATH)/bin/windows_amd64/mattermost.exe $(DIST_PATH)/bin # from cross-compiled bin dir cp $(GOPATH)/bin/windows_amd64/platform.exe $(DIST_PATH)/bin # from cross-compiled bin dir endif @# Package cd $(DIST_ROOT) && zip -9 -r -q -l mattermost-$(BUILD_TYPE_NAME)-windows-amd64.zip mattermost && cd .. @# Cleanup + rm -f $(DIST_PATH)/bin/mattermost.exe rm -f $(DIST_PATH)/bin/platform.exe @# Make linux package @# Copy binary ifeq ($(BUILDER_GOOS_GOARCH),"linux_amd64") + cp $(GOPATH)/bin/mattermost $(DIST_PATH)/bin # from native bin dir, not cross-compiled cp $(GOPATH)/bin/platform $(DIST_PATH)/bin # from native bin dir, not cross-compiled else + cp $(GOPATH)/bin/linux_amd64/mattermost $(DIST_PATH)/bin # from cross-compiled bin dir cp $(GOPATH)/bin/linux_amd64/platform $(DIST_PATH)/bin # from cross-compiled bin dir endif @# Package tar -C dist -czf $(DIST_PATH)-$(BUILD_TYPE_NAME)-linux-amd64.tar.gz mattermost @# Don't clean up native package so dev machines will have an unzipped package available - @#rm -f $(DIST_PATH)/bin/platform + @#rm -f $(DIST_PATH)/bin/mattermost diff --git a/cmd/commands/channel.go b/cmd/mattermost/commands/channel.go similarity index 84% rename from cmd/commands/channel.go rename to cmd/mattermost/commands/channel.go index 30d4e53ecc..80740d85e4 100644 --- a/cmd/commands/channel.go +++ b/cmd/mattermost/commands/channel.go @@ -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 } diff --git a/cmd/commands/channel_test.go b/cmd/mattermost/commands/channel_test.go similarity index 57% rename from cmd/commands/channel_test.go rename to cmd/mattermost/commands/channel_test.go index 09747b10bb..8fec971ca2 100644 --- a/cmd/commands/channel_test.go +++ b/cmd/mattermost/commands/channel_test.go @@ -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) } diff --git a/cmd/commands/channelargs.go b/cmd/mattermost/commands/channelargs.go similarity index 100% rename from cmd/commands/channelargs.go rename to cmd/mattermost/commands/channelargs.go diff --git a/cmd/cmdtestlib.go b/cmd/mattermost/commands/cmdtestlib.go similarity index 98% rename from cmd/cmdtestlib.go rename to cmd/mattermost/commands/cmdtestlib.go index db97b1a41b..93dcc95660 100644 --- a/cmd/cmdtestlib.go +++ b/cmd/mattermost/commands/cmdtestlib.go @@ -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" diff --git a/cmd/commands/command.go b/cmd/mattermost/commands/command.go similarity index 78% rename from cmd/commands/command.go rename to cmd/mattermost/commands/command.go index e7b7e0a0d0..147cd823c7 100644 --- a/cmd/commands/command.go +++ b/cmd/mattermost/commands/command.go @@ -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 + "'") } } diff --git a/cmd/commands/commandargs.go b/cmd/mattermost/commands/commandargs.go similarity index 100% rename from cmd/commands/commandargs.go rename to cmd/mattermost/commands/commandargs.go diff --git a/cmd/commands/config.go b/cmd/mattermost/commands/config.go similarity index 91% rename from cmd/commands/config.go rename to cmd/mattermost/commands/config.go index ef3b0f75e9..81ac765ecd 100644 --- a/cmd/commands/config.go +++ b/cmd/mattermost/commands/config.go @@ -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 } diff --git a/cmd/commands/config_flag_test.go b/cmd/mattermost/commands/config_flag_test.go similarity index 80% rename from cmd/commands/config_flag_test.go rename to cmd/mattermost/commands/config_flag_test.go index 59178b6207..00a817448d 100644 --- a/cmd/commands/config_flag_test.go +++ b/cmd/mattermost/commands/config_flag_test.go @@ -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") } diff --git a/cmd/commands/config_test.go b/cmd/mattermost/commands/config_test.go similarity index 76% rename from cmd/commands/config_test.go rename to cmd/mattermost/commands/config_test.go index 54ddfcb614..fcc35bd02d 100644 --- a/cmd/commands/config_test.go +++ b/cmd/mattermost/commands/config_test.go @@ -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")) } diff --git a/cmd/commands/exec_command_test.go b/cmd/mattermost/commands/exec_command_test.go similarity index 76% rename from cmd/commands/exec_command_test.go rename to cmd/mattermost/commands/exec_command_test.go index 79e65fe833..c1c61f3828 100644 --- a/cmd/commands/exec_command_test.go +++ b/cmd/mattermost/commands/exec_command_test.go @@ -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()) } diff --git a/cmd/commands/import.go b/cmd/mattermost/commands/import.go similarity index 69% rename from cmd/commands/import.go rename to cmd/mattermost/commands/import.go index 51fbb8d701..91cfaf9979 100644 --- a/cmd/commands/import.go +++ b/cmd/mattermost/commands/import.go @@ -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.") } } diff --git a/cmd/init.go b/cmd/mattermost/commands/init.go similarity index 86% rename from cmd/init.go rename to cmd/mattermost/commands/init.go index e3b4e97e13..aea2b12307 100644 --- a/cmd/init.go +++ b/cmd/mattermost/commands/init.go @@ -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 } diff --git a/cmd/commands/jobserver.go b/cmd/mattermost/commands/jobserver.go similarity index 90% rename from cmd/commands/jobserver.go rename to cmd/mattermost/commands/jobserver.go index a7671e1904..43a21d61f0 100644 --- a/cmd/commands/jobserver.go +++ b/cmd/mattermost/commands/jobserver.go @@ -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()) } diff --git a/cmd/commands/ldap.go b/cmd/mattermost/commands/ldap.go similarity index 72% rename from cmd/commands/ldap.go rename to cmd/mattermost/commands/ldap.go index 03c366213d..7283df0f2d 100644 --- a/cmd/commands/ldap.go +++ b/cmd/mattermost/commands/ldap.go @@ -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) } } diff --git a/cmd/commands/license.go b/cmd/mattermost/commands/license.go similarity index 84% rename from cmd/commands/license.go rename to cmd/mattermost/commands/license.go index 61c8e30602..1e08814d3a 100644 --- a/cmd/commands/license.go +++ b/cmd/mattermost/commands/license.go @@ -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 } diff --git a/cmd/commands/message_export.go b/cmd/mattermost/commands/message_export.go similarity index 88% rename from cmd/commands/message_export.go rename to cmd/mattermost/commands/message_export.go index 30d9cb1228..41b4fd289c 100644 --- a/cmd/commands/message_export.go +++ b/cmd/mattermost/commands/message_export.go @@ -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") } } diff --git a/cmd/commands/message_export_test.go b/cmd/mattermost/commands/message_export_test.go similarity index 80% rename from cmd/commands/message_export_test.go rename to cmd/mattermost/commands/message_export_test.go index bd0e049d66..7572d8b486 100644 --- a/cmd/commands/message_export_test.go +++ b/cmd/mattermost/commands/message_export_test.go @@ -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 { diff --git a/cmd/output.go b/cmd/mattermost/commands/output.go similarity index 96% rename from cmd/output.go rename to cmd/mattermost/commands/output.go index 630e831dee..e4182b4368 100644 --- a/cmd/output.go +++ b/cmd/mattermost/commands/output.go @@ -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" diff --git a/cmd/commands/permissions.go b/cmd/mattermost/commands/permissions.go similarity index 82% rename from cmd/commands/permissions.go rename to cmd/mattermost/commands/permissions.go index e8f862547a..e1bb34963f 100644 --- a/cmd/commands/permissions.go +++ b/cmd/mattermost/commands/permissions.go @@ -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 } diff --git a/cmd/commands/reset.go b/cmd/mattermost/commands/reset.go similarity index 73% rename from cmd/commands/reset.go rename to cmd/mattermost/commands/reset.go index 15222acae2..9b81ec2164 100644 --- a/cmd/commands/reset.go +++ b/cmd/mattermost/commands/reset.go @@ -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 } diff --git a/cmd/commands/roles.go b/cmd/mattermost/commands/roles.go similarity index 93% rename from cmd/commands/roles.go rename to cmd/mattermost/commands/roles.go index 72192c9251..f1c9d34c8f 100644 --- a/cmd/commands/roles.go +++ b/cmd/mattermost/commands/roles.go @@ -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 } diff --git a/cmd/commands/roles_test.go b/cmd/mattermost/commands/roles_test.go similarity index 82% rename from cmd/commands/roles_test.go rename to cmd/mattermost/commands/roles_test.go index 4e00aeac88..4f11ce7ed9 100644 --- a/cmd/commands/roles_test.go +++ b/cmd/mattermost/commands/roles_test.go @@ -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() diff --git a/cmd/cmd.go b/cmd/mattermost/commands/root.go similarity index 78% rename from cmd/cmd.go rename to cmd/mattermost/commands/root.go index 5a1a25bd9e..7ae439161c 100644 --- a/cmd/cmd.go +++ b/cmd/mattermost/commands/root.go @@ -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") } diff --git a/cmd/commands/sampledata.go b/cmd/mattermost/commands/sampledata.go similarity index 99% rename from cmd/commands/sampledata.go rename to cmd/mattermost/commands/sampledata.go index 9f4db86166..0051679ebd 100644 --- a/cmd/commands/sampledata.go +++ b/cmd/mattermost/commands/sampledata.go @@ -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 } diff --git a/cmd/commands/sampledata_test.go b/cmd/mattermost/commands/sampledata_test.go similarity index 62% rename from cmd/commands/sampledata_test.go rename to cmd/mattermost/commands/sampledata_test.go index 183392f116..e447fe4924 100644 --- a/cmd/commands/sampledata_test.go +++ b/cmd/mattermost/commands/sampledata_test.go @@ -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")) } diff --git a/cmd/commands/server.go b/cmd/mattermost/commands/server.go similarity index 94% rename from cmd/commands/server.go rename to cmd/mattermost/commands/server.go index 0d354f08e8..9d0e5a9170 100644 --- a/cmd/commands/server.go +++ b/cmd/mattermost/commands/server.go @@ -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)) diff --git a/cmd/commands/server_test.go b/cmd/mattermost/commands/server_test.go similarity index 92% rename from cmd/commands/server_test.go rename to cmd/mattermost/commands/server_test.go index fb7dfdef26..0f825e316c 100644 --- a/cmd/commands/server_test.go +++ b/cmd/mattermost/commands/server_test.go @@ -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) } diff --git a/cmd/commands/team.go b/cmd/mattermost/commands/team.go similarity index 82% rename from cmd/commands/team.go rename to cmd/mattermost/commands/team.go index 7dcf488477..59570d5e7f 100644 --- a/cmd/commands/team.go +++ b/cmd/mattermost/commands/team.go @@ -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 diff --git a/cmd/commands/team_test.go b/cmd/mattermost/commands/team_test.go similarity index 79% rename from cmd/commands/team_test.go rename to cmd/mattermost/commands/team_test.go index e6bc47a092..20e04bdc99 100644 --- a/cmd/commands/team_test.go +++ b/cmd/mattermost/commands/team_test.go @@ -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") diff --git a/cmd/commands/teamargs.go b/cmd/mattermost/commands/teamargs.go similarity index 100% rename from cmd/commands/teamargs.go rename to cmd/mattermost/commands/teamargs.go diff --git a/cmd/commands/test.go b/cmd/mattermost/commands/test.go similarity index 90% rename from cmd/commands/test.go rename to cmd/mattermost/commands/test.go index 837b988cc4..b5ab37af8b 100644 --- a/cmd/commands/test.go +++ b/cmd/mattermost/commands/test.go @@ -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 } diff --git a/cmd/commands/user.go b/cmd/mattermost/commands/user.go similarity index 86% rename from cmd/commands/user.go rename to cmd/mattermost/commands/user.go index 7397cfb2ec..ebcebcce82 100644 --- a/cmd/commands/user.go +++ b/cmd/mattermost/commands/user.go @@ -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 diff --git a/cmd/commands/user_test.go b/cmd/mattermost/commands/user_test.go similarity index 67% rename from cmd/commands/user_test.go rename to cmd/mattermost/commands/user_test.go index e51a6150b8..69ca9ecb82 100644 --- a/cmd/commands/user_test.go +++ b/cmd/mattermost/commands/user_test.go @@ -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)) } diff --git a/cmd/commands/userargs.go b/cmd/mattermost/commands/userargs.go similarity index 100% rename from cmd/commands/userargs.go rename to cmd/mattermost/commands/userargs.go diff --git a/cmd/commands/version.go b/cmd/mattermost/commands/version.go similarity index 60% rename from cmd/commands/version.go rename to cmd/mattermost/commands/version.go index eaf6a1a683..e26d5e09ce 100644 --- a/cmd/commands/version.go +++ b/cmd/mattermost/commands/version.go @@ -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()) } } diff --git a/cmd/commands/version_test.go b/cmd/mattermost/commands/version_test.go similarity index 70% rename from cmd/commands/version_test.go rename to cmd/mattermost/commands/version_test.go index 24a1389b16..0ed2c8ec59 100644 --- a/cmd/commands/version_test.go +++ b/cmd/mattermost/commands/version_test.go @@ -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") } diff --git a/main.go b/cmd/mattermost/main.go similarity index 82% rename from main.go rename to cmd/mattermost/main.go index 9edd026f73..c74ca8763d 100644 --- a/main.go +++ b/cmd/mattermost/main.go @@ -6,8 +6,7 @@ package main import ( "os" - "github.com/mattermost/mattermost-server/cmd" - _ "github.com/mattermost/mattermost-server/cmd/commands" + "github.com/mattermost/mattermost-server/cmd/mattermost/commands" // Plugins _ "github.com/mattermost/mattermost-server/model/gitlab" @@ -28,7 +27,7 @@ import ( ) func main() { - if err := cmd.Run(os.Args[1:]); err != nil { + if err := commands.Run(os.Args[1:]); err != nil { os.Exit(1) } } diff --git a/cmd/platform/main.go b/cmd/platform/main.go new file mode 100644 index 0000000000..b5ea51920d --- /dev/null +++ b/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.") + } +} diff --git a/utils/config.go b/utils/config.go index 1b5fc76744..1a68b80d7c 100644 --- a/utils/config.go +++ b/utils/config.go @@ -41,7 +41,7 @@ func FindConfigFile(fileName string) (path string) { return fileName } } else { - for _, dir := range []string{"./config", "../config", "../../config", "."} { + for _, dir := range []string{"./config", "../config", "../../config", "../../../config", "."} { path, _ := filepath.Abs(filepath.Join(dir, fileName)) if _, err := os.Stat(path); err == nil { return path @@ -53,7 +53,7 @@ func FindConfigFile(fileName string) (path string) { // FindDir looks for the given directory in nearby ancestors, falling back to `./` if not found. func FindDir(dir string) (string, bool) { - for _, parent := range []string{".", "..", "../.."} { + for _, parent := range []string{".", "..", "../..", "../../.."} { foundDir, err := filepath.Abs(filepath.Join(parent, dir)) if err != nil { continue