Unverified Commit 11cbb597 authored by Christopher Speller's avatar Christopher Speller Committed by GitHub

Renaming platform binary to mattermost. (#8801)

parent 1f6c271b
......@@ -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/"
# Output paths
DIST_ROOT=dist
......
......@@ -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
......@@ -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)
}
// 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.")
}
}
......
// 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")