summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorAshutosh Kumar <sonasingh46@gmail.com>2018-10-05 11:42:03 +0530
committerJesús Espino <jespinog@gmail.com>2018-10-05 08:12:03 +0200
commitcba33137d25336cd5a5bcfd1d68695b584714f56 (patch)
treee06f40245dc9c6cf41bd1b488dccf6df2068ad39 /cmd
parent939ee15013bcb0eeed27f57cf1d7b7192d387976 (diff)
downloadchat-cba33137d25336cd5a5bcfd1d68695b584714f56.tar.gz
chat-cba33137d25336cd5a5bcfd1d68695b584714f56.tar.bz2
chat-cba33137d25336cd5a5bcfd1d68695b584714f56.zip
MM-12357: Add CLI command "team list" (#9531)
* (feat:command list)add command list for teams Signed-off-by: sonasingh46 <sonasingh46@gmail.com> * address review comments Signed-off-by: sonasingh46 <sonasingh46@gmail.com> * address review comments Signed-off-by: sonasingh46 <sonasingh46@gmail.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mattermost/commands/command.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/cmd/mattermost/commands/command.go b/cmd/mattermost/commands/command.go
index 147cd823c..aee2eb290 100644
--- a/cmd/mattermost/commands/command.go
+++ b/cmd/mattermost/commands/command.go
@@ -6,6 +6,7 @@ package commands
import (
"errors"
+ "fmt"
"github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/model"
"github.com/spf13/cobra"
@@ -24,9 +25,18 @@ var CommandMoveCmd = &cobra.Command{
RunE: moveCommandCmdF,
}
+var CommandListCmd = &cobra.Command{
+ Use: "list",
+ Short: "List all commands on specified teams.",
+ Long: `List all commands on specified teams.`,
+ Example: ` command list myteam`,
+ RunE: listCommandCmdF,
+}
+
func init() {
CommandCmd.AddCommand(
CommandMoveCmd,
+ CommandListCmd,
)
RootCmd.AddCommand(CommandCmd)
}
@@ -67,3 +77,40 @@ func moveCommandCmdF(command *cobra.Command, args []string) error {
func moveCommand(a *app.App, team *model.Team, command *model.Command) *model.AppError {
return a.MoveCommand(team, command)
}
+
+func listCommandCmdF(command *cobra.Command, args []string) error {
+ a, err := InitDBCommandContextCobra(command)
+ if err != nil {
+ return err
+ }
+ defer a.Shutdown()
+
+ var teams []*model.Team
+ if len(args) < 1 {
+ teamList, err := a.GetAllTeams()
+ if err != nil {
+ return err
+ }
+ teams = teamList
+ } else {
+ teams = getTeamsFromTeamArgs(a, args)
+ }
+
+ for i, team := range teams {
+ if team == nil {
+ CommandPrintErrorln("Unable to find team '" + args[i] + "'")
+ continue
+ }
+ result := <-a.Srv.Store.Command().GetByTeam(team.Id)
+ if result.Err != nil {
+ CommandPrintErrorln("Unable to list commands for '" + args[i] + "'")
+ continue
+ }
+ commands := result.Data.([]*model.Command)
+ for _, command := range commands {
+ commandListItem := fmt.Sprintf("%s: %s (team: %s)", command.Id, command.DisplayName, team.Name)
+ CommandPrettyPrintln(commandListItem)
+ }
+ }
+ return nil
+}