summaryrefslogtreecommitdiffstats
path: root/cmd/platform/command.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-10-04 19:08:59 +0100
committerChris <ccbrown112@gmail.com>2017-10-04 11:08:59 -0700
commitf3fc6d11fa11c9b8c73554c79ca55470073bb098 (patch)
tree1c0fa5181315bf2da312f7c832ae16f360d43d16 /cmd/platform/command.go
parente16bdf8d1d4d2972be4e89cbc9c4dbef134895ba (diff)
downloadchat-f3fc6d11fa11c9b8c73554c79ca55470073bb098.tar.gz
chat-f3fc6d11fa11c9b8c73554c79ca55470073bb098.tar.bz2
chat-f3fc6d11fa11c9b8c73554c79ca55470073bb098.zip
PLT-7218: CLI to move slash commands between teams. (#7574)
Diffstat (limited to 'cmd/platform/command.go')
-rw-r--r--cmd/platform/command.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/cmd/platform/command.go b/cmd/platform/command.go
new file mode 100644
index 000000000..245fb7912
--- /dev/null
+++ b/cmd/platform/command.go
@@ -0,0 +1,69 @@
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+package main
+
+import (
+ "errors"
+ "github.com/mattermost/mattermost-server/app"
+ "github.com/mattermost/mattermost-server/model"
+ "github.com/spf13/cobra"
+)
+
+var commandCmd = &cobra.Command{
+ Use: "command",
+ Short: "Management of slash commands",
+}
+
+var commandMoveCmd = &cobra.Command{
+ Use: "move",
+ Short: "Move a slash command to a different team",
+ Long: `Move a slash command to a different team. Commands can be specified by [team]:[command-trigger-word]. ie. myteam:trigger or by command ID.`,
+ Example: ` command move newteam oldteam:command`,
+ RunE: moveCommandCmdF,
+}
+
+func init() {
+ commandCmd.AddCommand(
+ commandMoveCmd,
+ )
+}
+
+func moveCommandCmdF(cmd *cobra.Command, args []string) error {
+ a, err := initDBCommandContextCobra(cmd)
+ if err != nil {
+ return err
+ }
+
+ if len(args) < 2 {
+ return errors.New("Enter the destination team and at least one comamnd to move.")
+ }
+
+ team := getTeamFromTeamArg(a, args[0])
+ if team == nil {
+ return errors.New("Unable to find destination team '" + args[0] + "'")
+ }
+
+ commands := getCommandsFromCommandArgs(a, args[1:])
+ CommandPrintErrorln(commands)
+ for i, command := range commands {
+ if command == nil {
+ CommandPrintErrorln("Unable to find command '" + args[i+1] + "'")
+ continue
+ }
+ if err := moveCommand(a, team, command); err != nil {
+ CommandPrintErrorln("Unable to move command '" + command.Trigger + "' error: " + err.Error())
+ } else {
+ CommandPrettyPrintln("Moved command '" + command.Trigger + "'")
+ }
+ }
+
+ return nil
+}
+
+func moveCommand(a *app.App, team *model.Team, command *model.Command) *model.AppError {
+ if err := a.MoveCommand(team, command); err != nil {
+ return err
+ }
+
+ return nil
+}