Files
mostlymatter/server/cmd/mmctl/commands/commandargs.go
Miguel de la Cruz 951456c780 Includes mmctl into the mono-repo (#23091)
* Includes mmctl into the mono-repo

* Update to use the new public module paths

* Adds docs check to the mmctl CI

* Fix public utils import path

* Tidy up modules

* Fix linter

* Update CI tasks to use the new file structure

* Update CI references
2023-06-05 12:42:55 +02:00

56 строки
1.1 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package commands
import (
"strings"
"github.com/mattermost/mattermost-server/server/v8/cmd/mmctl/client"
"github.com/mattermost/mattermost-server/server/public/model"
)
// getCommandFromCommandArg retrieves a Command by command id or team:trigger.
func getCommandFromCommandArg(c client.Client, commandArg string) *model.Command {
if checkSlash(commandArg) {
return nil
}
cmd := getCommandFromTeamTrigger(c, commandArg)
if cmd == nil {
cmd, _, _ = c.GetCommandById(commandArg)
}
return cmd
}
// getCommandFromTeamTrigger retrieves a Command via team:trigger syntax.
func getCommandFromTeamTrigger(c client.Client, teamTrigger string) *model.Command {
arr := strings.Split(teamTrigger, ":")
if len(arr) != 2 {
return nil
}
team, _, _ := c.GetTeamByName(arr[0], "")
if team == nil {
return nil
}
trigger := arr[1]
if trigger == "" {
return nil
}
list, _, _ := c.ListCommands(team.Id, false)
if list == nil {
return nil
}
for _, cmd := range list {
if cmd.Trigger == trigger {
return cmd
}
}
return nil
}