Add list command to teams command in CLI (#8612)
* Add list command to teams command in CLI * Using App instead of Store to get the teams
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
191e1ad556
Коммит
8df6d5cc30
@@ -52,6 +52,14 @@ Permanently deletes a team along with all related information including posts fr
|
|||||||
RunE: deleteTeamsCmdF,
|
RunE: deleteTeamsCmdF,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ListTeamsCmd = &cobra.Command{
|
||||||
|
Use: "list",
|
||||||
|
Short: "List all teams.",
|
||||||
|
Long: `List all teams on the server.`,
|
||||||
|
Example: " team list",
|
||||||
|
RunE: listTeamsCmdF,
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
TeamCreateCmd.Flags().String("name", "", "Team Name")
|
TeamCreateCmd.Flags().String("name", "", "Team Name")
|
||||||
TeamCreateCmd.Flags().String("display_name", "", "Team Display Name")
|
TeamCreateCmd.Flags().String("display_name", "", "Team Display Name")
|
||||||
@@ -65,6 +73,7 @@ func init() {
|
|||||||
RemoveUsersCmd,
|
RemoveUsersCmd,
|
||||||
AddUsersCmd,
|
AddUsersCmd,
|
||||||
DeleteTeamsCmd,
|
DeleteTeamsCmd,
|
||||||
|
ListTeamsCmd,
|
||||||
)
|
)
|
||||||
cmd.RootCmd.AddCommand(TeamCmd)
|
cmd.RootCmd.AddCommand(TeamCmd)
|
||||||
}
|
}
|
||||||
@@ -216,3 +225,21 @@ func deleteTeamsCmdF(command *cobra.Command, args []string) error {
|
|||||||
func deleteTeam(a *app.App, team *model.Team) *model.AppError {
|
func deleteTeam(a *app.App, team *model.Team) *model.AppError {
|
||||||
return a.PermanentDeleteTeam(team)
|
return a.PermanentDeleteTeam(team)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func listTeamsCmdF(command *cobra.Command, args []string) error {
|
||||||
|
a, err := cmd.InitDBCommandContextCobra(command)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
teams, err2 := a.GetAllTeams()
|
||||||
|
if err2 != nil {
|
||||||
|
return err2
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, team := range teams {
|
||||||
|
cmd.CommandPrettyPrintln(team.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/api"
|
"github.com/mattermost/mattermost-server/api"
|
||||||
@@ -78,3 +79,20 @@ func TestLeaveTeam(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestListTeams(t *testing.T) {
|
||||||
|
th := api.Setup().InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
id := model.NewId()
|
||||||
|
name := "name" + id
|
||||||
|
displayName := "Name " + id
|
||||||
|
|
||||||
|
cmd.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
|
||||||
|
|
||||||
|
output := cmd.CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email)
|
||||||
|
|
||||||
|
if !strings.Contains(string(output), name) {
|
||||||
|
t.Fatal("should have the created team")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user