Skip to content

Commit

Permalink
CLOUDP-222791: expose "include total" on paginated commands - Part 2 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaangiolillo authored Mar 12, 2024
1 parent 53f3f6b commit 45109b4
Show file tree
Hide file tree
Showing 52 changed files with 207 additions and 35 deletions.
4 changes: 4 additions & 0 deletions docs/command/atlas-organizations-apiKeys-accessLists-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - --orgId
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-organizations-apiKeys-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - --orgId
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-organizations-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Options
- string
- false
- Organization name to perform a case-insensitive search for.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - -o, --output
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-organizations-users-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - --orgId
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-processes-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - -o, --output
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-projects-apiKeys-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - -o, --output
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-projects-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - --orgId
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-projects-teams-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - -o, --output
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-projects-users-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - -o, --output
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-serverless-backups-restores-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - -o, --output
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-serverless-backups-snapshots-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - -o, --output
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-serverless-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - -o, --output
- string
- false
Expand Down
4 changes: 4 additions & 0 deletions docs/command/atlas-teams-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Options
- int
- false
- Number of items per results page, up to a maximum of 500. If you have more than 500 results, specify the --page option to change the results page. This value defaults to 100.
* - --omitCount
-
- false
- Flag that indicates whether the JSON response returns the total number of items (totalCount) in the JSON response.
* - --orgId
- string
- false
Expand Down
2 changes: 2 additions & 0 deletions internal/cli/atlas/organizations/apikeys/accesslists/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (opts *ListOpts) Run() error {
ApiUserId: opts.id,
PageNum: pointer.Get(listOpts.PageNum),
ItemsPerPage: pointer.Get(listOpts.ItemsPerPage),
IncludeCount: pointer.Get(listOpts.IncludeCount),
}
result, err := opts.store.OrganizationAPIKeyAccessLists(params)
if err != nil {
Expand Down Expand Up @@ -95,6 +96,7 @@ func ListBuilder() *cobra.Command {

cmd.Flags().IntVar(&opts.PageNum, flag.Page, cli.DefaultPage, usage.Page)
cmd.Flags().IntVar(&opts.ItemsPerPage, flag.Limit, cli.DefaultPageLimit, usage.Limit)
cmd.Flags().BoolVar(&opts.OmitCount, flag.OmitCount, false, usage.OmitCount)

cmd.Flags().StringVar(&opts.OrgID, flag.OrgID, "", usage.OrgID)
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestListOpts_Run(t *testing.T) {
ApiUserId: opts.id,
PageNum: pointer.Get(listOpts.PageNum),
ItemsPerPage: pointer.Get(listOpts.ItemsPerPage),
IncludeCount: pointer.Get(listOpts.IncludeCount),
}
expected := admin.PaginatedApiUserAccessList{
Results: &[]admin.UserAccessList{},
Expand All @@ -62,6 +63,6 @@ func TestListBuilder(t *testing.T) {
t,
ListBuilder(),
0,
[]string{flag.OrgID, flag.Output, flag.Page, flag.Limit},
[]string{flag.OrgID, flag.Output, flag.Page, flag.Limit, flag.OmitCount},
)
}
1 change: 1 addition & 0 deletions internal/cli/atlas/organizations/apikeys/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func ListBuilder() *cobra.Command {

cmd.Flags().IntVar(&opts.PageNum, flag.Page, cli.DefaultPage, usage.Page)
cmd.Flags().IntVar(&opts.ItemsPerPage, flag.Limit, cli.DefaultPageLimit, usage.Limit)
cmd.Flags().BoolVar(&opts.OmitCount, flag.OmitCount, false, usage.OmitCount)

cmd.Flags().StringVar(&opts.OrgID, flag.OrgID, "", usage.OrgID)
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)
Expand Down
10 changes: 10 additions & 0 deletions internal/cli/atlas/organizations/apikeys/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/test"
atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin"
Expand All @@ -46,3 +47,12 @@ func TestListOpts_Run(t *testing.T) {
}
test.VerifyOutputTemplate(t, listTemplate, expected)
}

func TestListBuilder(t *testing.T) {
test.CmdValidator(
t,
ListBuilder(),
0,
[]string{flag.Page, flag.Limit, flag.OmitCount, flag.OrgID, flag.Output, flag.CompactResponse},
)
}
8 changes: 5 additions & 3 deletions internal/cli/atlas/organizations/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (opts *ListOpts) newOrganizationListOptions() *atlasv2.ListOrganizationsApi
if listOpt := opts.NewListOptions(); listOpt != nil {
params.PageNum = &listOpt.PageNum
params.ItemsPerPage = &listOpt.ItemsPerPage
params.IncludeCount = &listOpt.IncludeCount
}
return params
}
Expand Down Expand Up @@ -96,11 +97,12 @@ func ListBuilder() *cobra.Command {
},
}

cmd.Flags().StringVar(&opts.name, flag.Name, "", usage.OrgNameFilter)
cmd.Flags().BoolVar(&opts.includeDeletedOrgs, flag.IncludeDeleted, false, usage.OrgIncludeDeleted)

cmd.Flags().IntVar(&opts.PageNum, flag.Page, cli.DefaultPage, usage.Page)
cmd.Flags().IntVar(&opts.ItemsPerPage, flag.Limit, cli.DefaultPageLimit, usage.Limit)
cmd.Flags().BoolVar(&opts.OmitCount, flag.OmitCount, false, usage.OmitCount)

cmd.Flags().StringVar(&opts.name, flag.Name, "", usage.OrgNameFilter)
cmd.Flags().BoolVar(&opts.includeDeletedOrgs, flag.IncludeDeleted, false, usage.OrgIncludeDeleted)

cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)
_ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag())
Expand Down
10 changes: 10 additions & 0 deletions internal/cli/atlas/organizations/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/test"
atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin"
Expand All @@ -44,3 +45,12 @@ func TestList_Run(t *testing.T) {
}
test.VerifyOutputTemplate(t, listTemplate, expected)
}

func TestListBuilder(t *testing.T) {
test.CmdValidator(
t,
ListBuilder(),
0,
[]string{flag.Page, flag.Limit, flag.OmitCount, flag.IncludeDeleted, flag.Output, flag.Name},
)
}
1 change: 1 addition & 0 deletions internal/cli/atlas/organizations/users/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func ListBuilder() *cobra.Command {

cmd.Flags().IntVar(&opts.PageNum, flag.Page, cli.DefaultPage, usage.Page)
cmd.Flags().IntVar(&opts.ItemsPerPage, flag.Limit, cli.DefaultPageLimit, usage.Limit)
cmd.Flags().BoolVar(&opts.OmitCount, flag.OmitCount, false, usage.OmitCount)

cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)
_ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag())
Expand Down
1 change: 1 addition & 0 deletions internal/cli/atlas/organizations/users/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func TestListBuilder(t *testing.T) {
flag.Limit,
flag.Output,
flag.OrgID,
flag.OmitCount,
},
)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/cli/atlas/privateendpoints/datalake/aws/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (opts *ListOpts) newDatalakePrivateEndpointsListOpts() *atlasv2.ListDataFed
GroupId: opts.ConfigProjectID(),
PageNum: pointer.Get(opts.PageNum),
ItemsPerPage: pointer.Get(opts.ItemsPerPage),
IncludeCount: pointer.Get(!opts.OmitCount),
}
}

Expand Down Expand Up @@ -93,6 +94,7 @@ func ListBuilder() *cobra.Command {

cmd.Flags().IntVar(&opts.PageNum, flag.Page, cli.DefaultPage, usage.Page)
cmd.Flags().IntVar(&opts.ItemsPerPage, flag.Limit, cli.DefaultPageLimit, usage.Limit)
cmd.Flags().BoolVar(&opts.OmitCount, flag.OmitCount, false, usage.OmitCount)

cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID)
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ func TestListBuilder(t *testing.T) {
t,
ListBuilder(),
0,
[]string{flag.ProjectID, flag.Output},
[]string{flag.ProjectID, flag.Output, flag.OmitCount, flag.Page, flag.Limit},
)
}
5 changes: 5 additions & 0 deletions internal/cli/atlas/processes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (opts *ListOpts) newProcessesListParams() *atlasv2.ListAtlasProcessesApiPar
if listOpts.ItemsPerPage > 0 {
processesList.ItemsPerPage = &listOpts.ItemsPerPage
}

if listOpts.IncludeCount {
processesList.IncludeCount = &listOpts.IncludeCount
}
return processesList
}

Expand Down Expand Up @@ -101,6 +105,7 @@ func ListBuilder() *cobra.Command {

cmd.Flags().IntVar(&opts.PageNum, flag.Page, cli.DefaultPage, usage.Page)
cmd.Flags().IntVar(&opts.ItemsPerPage, flag.Limit, cli.DefaultPageLimit, usage.Limit)
cmd.Flags().BoolVar(&opts.OmitCount, flag.OmitCount, false, usage.OmitCount)

cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID)
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)
Expand Down
6 changes: 4 additions & 2 deletions internal/cli/atlas/processes/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func TestList_Run(t *testing.T) {
listOpts := &ListOpts{
store: mockStore,
}
params := atlasv2.ListAtlasProcessesApiParams{}
params := atlasv2.ListAtlasProcessesApiParams{
IncludeCount: pointer.Get(true),
}

mockStore.
EXPECT().
Expand All @@ -61,6 +63,6 @@ func TestListBuilder(t *testing.T) {
t,
ListBuilder(),
0,
[]string{flag.ProjectID, flag.Output, flag.Page, flag.Limit},
[]string{flag.ProjectID, flag.Output, flag.Page, flag.Limit, flag.OmitCount},
)
}
1 change: 1 addition & 0 deletions internal/cli/atlas/projects/apikeys/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func ListBuilder() *cobra.Command {

cmd.Flags().IntVar(&opts.PageNum, flag.Page, cli.DefaultPage, usage.Page)
cmd.Flags().IntVar(&opts.ItemsPerPage, flag.Limit, cli.DefaultPageLimit, usage.Limit)
cmd.Flags().BoolVar(&opts.OmitCount, flag.OmitCount, false, usage.OmitCount)

cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID)
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)
Expand Down
10 changes: 10 additions & 0 deletions internal/cli/atlas/projects/apikeys/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/pointer"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/test"
Expand Down Expand Up @@ -53,3 +54,12 @@ func TestList_Run(t *testing.T) {
}
test.VerifyOutputTemplate(t, listTemplate, expected)
}

func TestListBuilder(t *testing.T) {
test.CmdValidator(
t,
ListBuilder(),
0,
[]string{flag.Page, flag.Limit, flag.OmitCount, flag.ProjectID, flag.Output, flag.CompactResponse},
)
}
1 change: 1 addition & 0 deletions internal/cli/atlas/projects/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func ListBuilder() *cobra.Command {

cmd.Flags().IntVar(&opts.PageNum, flag.Page, cli.DefaultPage, usage.Page)
cmd.Flags().IntVar(&opts.ItemsPerPage, flag.Limit, cli.DefaultPageLimit, usage.Limit)
cmd.Flags().BoolVar(&opts.OmitCount, flag.OmitCount, false, usage.OmitCount)

cmd.Flags().StringVar(&opts.OrgID, flag.OrgID, "", usage.OrgID)
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)
Expand Down
11 changes: 11 additions & 0 deletions internal/cli/atlas/projects/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/test"
"github.com/stretchr/testify/require"
atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin"
)
Expand Down Expand Up @@ -54,3 +56,12 @@ func TestList_Run(t *testing.T) {
require.NoError(t, listOpts.Run())
})
}

func TestListBuilder(t *testing.T) {
test.CmdValidator(
t,
ListBuilder(),
0,
[]string{flag.Page, flag.Limit, flag.OmitCount, flag.OrgID, flag.Output},
)
}
Loading

0 comments on commit 45109b4

Please sign in to comment.