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>
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
939ee15013
Коммит
cba33137d2
@@ -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
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user