github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/cmd/platform/command.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 package main 4 5 import ( 6 "errors" 7 "github.com/mattermost/mattermost-server/app" 8 "github.com/mattermost/mattermost-server/model" 9 "github.com/spf13/cobra" 10 ) 11 12 var commandCmd = &cobra.Command{ 13 Use: "command", 14 Short: "Management of slash commands", 15 } 16 17 var commandMoveCmd = &cobra.Command{ 18 Use: "move", 19 Short: "Move a slash command to a different team", 20 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.`, 21 Example: ` command move newteam oldteam:command`, 22 RunE: moveCommandCmdF, 23 } 24 25 func init() { 26 commandCmd.AddCommand( 27 commandMoveCmd, 28 ) 29 } 30 31 func moveCommandCmdF(cmd *cobra.Command, args []string) error { 32 a, err := initDBCommandContextCobra(cmd) 33 if err != nil { 34 return err 35 } 36 37 if len(args) < 2 { 38 return errors.New("Enter the destination team and at least one comamnd to move.") 39 } 40 41 team := getTeamFromTeamArg(a, args[0]) 42 if team == nil { 43 return errors.New("Unable to find destination team '" + args[0] + "'") 44 } 45 46 commands := getCommandsFromCommandArgs(a, args[1:]) 47 CommandPrintErrorln(commands) 48 for i, command := range commands { 49 if command == nil { 50 CommandPrintErrorln("Unable to find command '" + args[i+1] + "'") 51 continue 52 } 53 if err := moveCommand(a, team, command); err != nil { 54 CommandPrintErrorln("Unable to move command '" + command.Trigger + "' error: " + err.Error()) 55 } else { 56 CommandPrettyPrintln("Moved command '" + command.Trigger + "'") 57 } 58 } 59 60 return nil 61 } 62 63 func moveCommand(a *app.App, team *model.Team, command *model.Command) *model.AppError { 64 return a.MoveCommand(team, command) 65 }