mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Simplify page size in mmctl (#26664)
This commit is contained in:
parent
9fee0393c3
commit
b56c65ec2d
@ -160,7 +160,7 @@ func botListCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
|||||||
all, _ := cmd.Flags().GetBool("all")
|
all, _ := cmd.Flags().GetBool("all")
|
||||||
|
|
||||||
page := 0
|
page := 0
|
||||||
perPage := 200
|
perPage := DefaultPageSize
|
||||||
tpl := `{{.UserId}}: {{.Username}}`
|
tpl := `{{.UserId}}: {{.Username}}`
|
||||||
for {
|
for {
|
||||||
var bots []*model.Bot
|
var bots []*model.Bot
|
||||||
@ -206,7 +206,7 @@ func botListCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
|||||||
printer.PrintT(tpl+tplExtraText, bot)
|
printer.PrintT(tpl+tplExtraText, bot)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(bots) < 200 {
|
if len(bots) < perPage {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
|
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost/server/public/model"
|
"github.com/mattermost/mattermost/server/public/model"
|
||||||
"github.com/mattermost/mattermost/server/v8/channels/web"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -284,7 +283,7 @@ func getAllPublicChannelsForTeam(c client.Client, teamID string) ([]*model.Chann
|
|||||||
page := 0
|
page := 0
|
||||||
|
|
||||||
for {
|
for {
|
||||||
channelsPage, _, err := c.GetPublicChannelsForTeam(context.TODO(), teamID, page, web.PerPageMaximum, "")
|
channelsPage, _, err := c.GetPublicChannelsForTeam(context.TODO(), teamID, page, DefaultPageSize, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -305,7 +304,7 @@ func getAllDeletedChannelsForTeam(c client.Client, teamID string) ([]*model.Chan
|
|||||||
page := 0
|
page := 0
|
||||||
|
|
||||||
for {
|
for {
|
||||||
channelsPage, _, err := c.GetDeletedChannelsForTeam(context.TODO(), teamID, page, web.PerPageMaximum, "")
|
channelsPage, _, err := c.GetDeletedChannelsForTeam(context.TODO(), teamID, page, DefaultPageSize, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -561,7 +560,7 @@ func getPrivateChannels(c client.Client, teamID string) ([]*model.Channel, error
|
|||||||
withoutError := true
|
withoutError := true
|
||||||
|
|
||||||
for {
|
for {
|
||||||
channelsPage, _, err := c.GetPrivateChannelsForTeam(context.TODO(), teamID, page, web.PerPageMaximum, "")
|
channelsPage, _, err := c.GetPrivateChannelsForTeam(context.TODO(), teamID, page, DefaultPageSize, "")
|
||||||
if err != nil && viper.GetBool("local") {
|
if err != nil && viper.GetBool("local") {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
@ -240,7 +240,7 @@ func fetchAndComplete[T any](f fetcher[T], m matcher[T]) validateArgsFn {
|
|||||||
|
|
||||||
var page int
|
var page int
|
||||||
for {
|
for {
|
||||||
entities, _, err := f(ctx, c, page, perPage)
|
entities, _, err := f(ctx, c, page, DefaultPageSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Return what we got so far
|
// Return what we got so far
|
||||||
return res, cobra.ShellCompDirectiveNoFileComp
|
return res, cobra.ShellCompDirectiveNoFileComp
|
||||||
@ -262,7 +262,7 @@ func fetchAndComplete[T any](f fetcher[T], m matcher[T]) validateArgsFn {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(entities) < perPage {
|
if len(entities) < DefaultPageSize {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ func init() {
|
|||||||
ExportDownloadCmd.Flags().Int("num-retries", 5, "Number of retries to do to resume a download.")
|
ExportDownloadCmd.Flags().Int("num-retries", 5, "Number of retries to do to resume a download.")
|
||||||
|
|
||||||
ExportJobListCmd.Flags().Int("page", 0, "Page number to fetch for the list of export jobs")
|
ExportJobListCmd.Flags().Int("page", 0, "Page number to fetch for the list of export jobs")
|
||||||
ExportJobListCmd.Flags().Int("per-page", 200, "Number of export jobs to be fetched")
|
ExportJobListCmd.Flags().Int("per-page", DefaultPageSize, "Number of export jobs to be fetched")
|
||||||
ExportJobListCmd.Flags().Bool("all", false, "Fetch all export jobs. --page flag will be ignore if provided")
|
ExportJobListCmd.Flags().Bool("all", false, "Fetch all export jobs. --page flag will be ignore if provided")
|
||||||
|
|
||||||
ExportJobCmd.AddCommand(
|
ExportJobCmd.AddCommand(
|
||||||
|
@ -55,7 +55,7 @@ func init() {
|
|||||||
ExtractRunCmd.Flags().Int64("from", 0, "The timestamp of the earliest file to extract, expressed in seconds since the unix epoch.")
|
ExtractRunCmd.Flags().Int64("from", 0, "The timestamp of the earliest file to extract, expressed in seconds since the unix epoch.")
|
||||||
ExtractRunCmd.Flags().Int64("to", 0, "The timestamp of the latest file to extract, expressed in seconds since the unix epoch. Defaults to the current time.")
|
ExtractRunCmd.Flags().Int64("to", 0, "The timestamp of the latest file to extract, expressed in seconds since the unix epoch. Defaults to the current time.")
|
||||||
ExtractJobListCmd.Flags().Int("page", 0, "Page number to fetch for the list of extract jobs")
|
ExtractJobListCmd.Flags().Int("page", 0, "Page number to fetch for the list of extract jobs")
|
||||||
ExtractJobListCmd.Flags().Int("per-page", 200, "Number of extract jobs to be fetched")
|
ExtractJobListCmd.Flags().Int("per-page", DefaultPageSize, "Number of extract jobs to be fetched")
|
||||||
ExtractJobListCmd.Flags().Bool("all", false, "Fetch all extract jobs. --page flag will be ignore if provided")
|
ExtractJobListCmd.Flags().Bool("all", false, "Fetch all extract jobs. --page flag will be ignore if provided")
|
||||||
ExtractJobCmd.AddCommand(
|
ExtractJobCmd.AddCommand(
|
||||||
ExtractJobListCmd,
|
ExtractJobListCmd,
|
||||||
|
@ -103,7 +103,7 @@ func init() {
|
|||||||
ImportUploadCmd.Flags().String("upload", "", "The ID of the import upload to resume.")
|
ImportUploadCmd.Flags().String("upload", "", "The ID of the import upload to resume.")
|
||||||
|
|
||||||
ImportJobListCmd.Flags().Int("page", 0, "Page number to fetch for the list of import jobs")
|
ImportJobListCmd.Flags().Int("page", 0, "Page number to fetch for the list of import jobs")
|
||||||
ImportJobListCmd.Flags().Int("per-page", 200, "Number of import jobs to be fetched")
|
ImportJobListCmd.Flags().Int("per-page", DefaultPageSize, "Number of import jobs to be fetched")
|
||||||
ImportJobListCmd.Flags().Bool("all", false, "Fetch all import jobs. --page flag will be ignore if provided")
|
ImportJobListCmd.Flags().Bool("all", false, "Fetch all import jobs. --page flag will be ignore if provided")
|
||||||
|
|
||||||
ImportValidateCmd.Flags().StringArray("team", nil, "Predefined team[s] to assume as already present on the destination server. Implies --check-missing-teams. The flag can be repeated")
|
ImportValidateCmd.Flags().StringArray("team", nil, "Predefined team[s] to assume as already present on the destination server. Implies --check-missing-teams. The flag can be repeated")
|
||||||
|
@ -26,8 +26,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
perPage = 200
|
|
||||||
|
|
||||||
shellCompletionMaxItems = 50 // Maximum number of items that will be loaded and shown in shell completion.
|
shellCompletionMaxItems = 50 // Maximum number of items that will be loaded and shown in shell completion.
|
||||||
shellCompleteTimeout = 5 * time.Second
|
shellCompleteTimeout = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
@ -27,7 +27,7 @@ var LogsCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
LogsCmd.Flags().IntP("number", "n", 200, "Number of log lines to retrieve.")
|
LogsCmd.Flags().IntP("number", "n", DefaultPageSize, "Number of log lines to retrieve.")
|
||||||
LogsCmd.Flags().BoolP("logrus", "l", false, "Use logrus for formatting.")
|
LogsCmd.Flags().BoolP("logrus", "l", false, "Use logrus for formatting.")
|
||||||
RootCmd.AddCommand(LogsCmd)
|
RootCmd.AddCommand(LogsCmd)
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ func listOAuthAppsCmdF(c client.Client, command *cobra.Command, args []string) e
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ListOAuthAppsCmd.Flags().Int("page", 0, "Page number to fetch for the list of OAuth2 apps")
|
ListOAuthAppsCmd.Flags().Int("page", 0, "Page number to fetch for the list of OAuth2 apps")
|
||||||
ListOAuthAppsCmd.Flags().Int("per-page", 200, "Number of OAuth2 apps to be fetched")
|
ListOAuthAppsCmd.Flags().Int("per-page", DefaultPageSize, "Number of OAuth2 apps to be fetched")
|
||||||
|
|
||||||
OAuthCmd.AddCommand(
|
OAuthCmd.AddCommand(
|
||||||
ListOAuthAppsCmd,
|
ListOAuthAppsCmd,
|
||||||
|
@ -50,7 +50,7 @@ var PluginMarketplaceListCmd = &cobra.Command{
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
PluginMarketplaceListCmd.Flags().Int("page", 0, "Page number to fetch for the list of users")
|
PluginMarketplaceListCmd.Flags().Int("page", 0, "Page number to fetch for the list of users")
|
||||||
PluginMarketplaceListCmd.Flags().Int("per-page", 200, "Number of users to be fetched")
|
PluginMarketplaceListCmd.Flags().Int("per-page", DefaultPageSize, "Number of users to be fetched")
|
||||||
PluginMarketplaceListCmd.Flags().Bool("all", false, "Fetch all plugins. --page flag will be ignore if provided")
|
PluginMarketplaceListCmd.Flags().Bool("all", false, "Fetch all plugins. --page flag will be ignore if provided")
|
||||||
PluginMarketplaceListCmd.Flags().String("filter", "", "Filter plugins by ID, name or description")
|
PluginMarketplaceListCmd.Flags().String("filter", "", "Filter plugins by ID, name or description")
|
||||||
PluginMarketplaceListCmd.Flags().Bool("local-only", false, "Only retrieve local plugins")
|
PluginMarketplaceListCmd.Flags().Bool("local-only", false, "Only retrieve local plugins")
|
||||||
|
@ -18,8 +18,6 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APILimitMaximum = 200
|
|
||||||
|
|
||||||
var TeamCmd = &cobra.Command{
|
var TeamCmd = &cobra.Command{
|
||||||
Use: "team",
|
Use: "team",
|
||||||
Short: "Management of teams",
|
Short: "Management of teams",
|
||||||
@ -206,7 +204,7 @@ func archiveTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
|||||||
func listTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
func listTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||||
page := 0
|
page := 0
|
||||||
for {
|
for {
|
||||||
teams, _, err := c.GetAllTeams(context.TODO(), "", page, APILimitMaximum)
|
teams, _, err := c.GetAllTeams(context.TODO(), "", page, DefaultPageSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -219,7 +217,7 @@ func listTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(teams) < APILimitMaximum {
|
if len(teams) < DefaultPageSize {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ func (s *MmctlUnitTestSuite) TestListTeamsCmdF() {
|
|||||||
|
|
||||||
s.client.
|
s.client.
|
||||||
EXPECT().
|
EXPECT().
|
||||||
GetAllTeams(context.TODO(), "", 0, APILimitMaximum).
|
GetAllTeams(context.TODO(), "", 0, DefaultPageSize).
|
||||||
Return(nil, &model.Response{}, mockError).
|
Return(nil, &model.Response{}, mockError).
|
||||||
Times(1)
|
Times(1)
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ func (s *MmctlUnitTestSuite) TestListTeamsCmdF() {
|
|||||||
|
|
||||||
s.client.
|
s.client.
|
||||||
EXPECT().
|
EXPECT().
|
||||||
GetAllTeams(context.TODO(), "", 0, APILimitMaximum).
|
GetAllTeams(context.TODO(), "", 0, DefaultPageSize).
|
||||||
Return([]*model.Team{&mockTeam}, &model.Response{}, nil).
|
Return([]*model.Team{&mockTeam}, &model.Response{}, nil).
|
||||||
Times(2)
|
Times(2)
|
||||||
|
|
||||||
@ -300,7 +300,7 @@ func (s *MmctlUnitTestSuite) TestListTeamsCmdF() {
|
|||||||
|
|
||||||
s.client.
|
s.client.
|
||||||
EXPECT().
|
EXPECT().
|
||||||
GetAllTeams(context.TODO(), "", 0, APILimitMaximum).
|
GetAllTeams(context.TODO(), "", 0, DefaultPageSize).
|
||||||
Return([]*model.Team{&mockTeam}, &model.Response{}, nil).
|
Return([]*model.Team{&mockTeam}, &model.Response{}, nil).
|
||||||
Times(2)
|
Times(2)
|
||||||
|
|
||||||
@ -347,7 +347,7 @@ func (s *MmctlUnitTestSuite) TestListTeamsCmdF() {
|
|||||||
|
|
||||||
s.client.
|
s.client.
|
||||||
EXPECT().
|
EXPECT().
|
||||||
GetAllTeams(context.TODO(), "", 0, APILimitMaximum).
|
GetAllTeams(context.TODO(), "", 0, DefaultPageSize).
|
||||||
Return(mockTeams, &model.Response{}, nil).
|
Return(mockTeams, &model.Response{}, nil).
|
||||||
Times(2)
|
Times(2)
|
||||||
|
|
||||||
@ -383,28 +383,28 @@ func (s *MmctlUnitTestSuite) TestListTeamsCmdF() {
|
|||||||
s.Run("Multiple team pages", func() {
|
s.Run("Multiple team pages", func() {
|
||||||
printer.Clean()
|
printer.Clean()
|
||||||
|
|
||||||
mockTeamsPage1 := make([]*model.Team, APILimitMaximum)
|
mockTeamsPage1 := make([]*model.Team, DefaultPageSize)
|
||||||
for i := 0; i < APILimitMaximum; i++ {
|
for i := 0; i < DefaultPageSize; i++ {
|
||||||
mockTeamsPage1[i] = &model.Team{Name: fmt.Sprintf("Team%d", i)}
|
mockTeamsPage1[i] = &model.Team{Name: fmt.Sprintf("Team%d", i)}
|
||||||
}
|
}
|
||||||
mockTeamsPage2 := []*model.Team{{Name: fmt.Sprintf("Team%d", APILimitMaximum)}}
|
mockTeamsPage2 := []*model.Team{{Name: fmt.Sprintf("Team%d", DefaultPageSize)}}
|
||||||
|
|
||||||
s.client.
|
s.client.
|
||||||
EXPECT().
|
EXPECT().
|
||||||
GetAllTeams(context.TODO(), "", 0, APILimitMaximum).
|
GetAllTeams(context.TODO(), "", 0, DefaultPageSize).
|
||||||
Return(mockTeamsPage1, &model.Response{}, nil).
|
Return(mockTeamsPage1, &model.Response{}, nil).
|
||||||
Times(1)
|
Times(1)
|
||||||
|
|
||||||
s.client.
|
s.client.
|
||||||
EXPECT().
|
EXPECT().
|
||||||
GetAllTeams(context.TODO(), "", 1, APILimitMaximum).
|
GetAllTeams(context.TODO(), "", 1, DefaultPageSize).
|
||||||
Return(mockTeamsPage2, &model.Response{}, nil).
|
Return(mockTeamsPage2, &model.Response{}, nil).
|
||||||
Times(1)
|
Times(1)
|
||||||
|
|
||||||
err := listTeamsCmdF(s.client, &cobra.Command{}, []string{})
|
err := listTeamsCmdF(s.client, &cobra.Command{}, []string{})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Len(printer.GetLines(), APILimitMaximum+1)
|
s.Require().Len(printer.GetLines(), DefaultPageSize+1)
|
||||||
for i := 0; i < APILimitMaximum+1; i++ {
|
for i := 0; i < DefaultPageSize+1; i++ {
|
||||||
s.Require().Equal(printer.GetLines()[i].(*model.Team).Name, fmt.Sprintf("Team%d", i))
|
s.Require().Equal(printer.GetLines()[i].(*model.Team).Name, fmt.Sprintf("Team%d", i))
|
||||||
}
|
}
|
||||||
s.Require().Len(printer.GetErrorLines(), 0)
|
s.Require().Len(printer.GetErrorLines(), 0)
|
||||||
|
@ -48,7 +48,7 @@ var ListUserTokensCmd = &cobra.Command{
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ListUserTokensCmd.Flags().Int("page", 0, "Page number to fetch for the list of users")
|
ListUserTokensCmd.Flags().Int("page", 0, "Page number to fetch for the list of users")
|
||||||
ListUserTokensCmd.Flags().Int("per-page", 200, "Number of users to be fetched")
|
ListUserTokensCmd.Flags().Int("per-page", DefaultPageSize, "Number of users to be fetched")
|
||||||
ListUserTokensCmd.Flags().Bool("all", false, "Fetch all tokens. --page flag will be ignore if provided")
|
ListUserTokensCmd.Flags().Bool("all", false, "Fetch all tokens. --page flag will be ignore if provided")
|
||||||
ListUserTokensCmd.Flags().Bool("active", true, "List only active tokens")
|
ListUserTokensCmd.Flags().Bool("active", true, "List only active tokens")
|
||||||
ListUserTokensCmd.Flags().Bool("inactive", false, "List only inactive tokens")
|
ListUserTokensCmd.Flags().Bool("inactive", false, "List only inactive tokens")
|
||||||
|
@ -315,7 +315,7 @@ func init() {
|
|||||||
DeleteAllUsersCmd.Flags().Bool("confirm", false, "Confirm you really want to delete the user and a DB backup has been performed")
|
DeleteAllUsersCmd.Flags().Bool("confirm", false, "Confirm you really want to delete the user and a DB backup has been performed")
|
||||||
|
|
||||||
ListUsersCmd.Flags().Int("page", 0, "Page number to fetch for the list of users")
|
ListUsersCmd.Flags().Int("page", 0, "Page number to fetch for the list of users")
|
||||||
ListUsersCmd.Flags().Int("per-page", 200, "Number of users to be fetched")
|
ListUsersCmd.Flags().Int("per-page", DefaultPageSize, "Number of users to be fetched")
|
||||||
ListUsersCmd.Flags().Bool("all", false, "Fetch all users. --page flag will be ignore if provided")
|
ListUsersCmd.Flags().Bool("all", false, "Fetch all users. --page flag will be ignore if provided")
|
||||||
ListUsersCmd.Flags().String("team", "", "If supplied, only users belonging to this team will be listed")
|
ListUsersCmd.Flags().String("team", "", "If supplied, only users belonging to this team will be listed")
|
||||||
|
|
||||||
|
@ -14,7 +14,9 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultPageSize = 200
|
const (
|
||||||
|
DefaultPageSize = 200
|
||||||
|
)
|
||||||
|
|
||||||
func checkInteractiveTerminal() error {
|
func checkInteractiveTerminal() error {
|
||||||
fileInfo, err := os.Stdout.Stat()
|
fileInfo, err := os.Stdout.Stat()
|
||||||
|
Loading…
Reference in New Issue
Block a user