Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-222791: expose "include total" on paginated commands - Part 1 #2749

Merged
merged 5 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/command/atlas-accessLists-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-alerts-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-backups-exports-buckets-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-backups-exports-jobs-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-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-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-clusters-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-clusters-onlineArchives-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
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-dbusers-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-metrics-databases-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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-metrics-disks-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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-networking-containers-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-networking-peering-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
1 change: 1 addition & 0 deletions internal/cli/atlas/accesslists/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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
2 changes: 1 addition & 1 deletion internal/cli/atlas/accesslists/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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},
)
}
8 changes: 8 additions & 0 deletions internal/cli/atlas/alerts/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/pointer"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -54,6 +55,11 @@ func (opts *ListOpts) Run() error {
ItemsPerPage: &opts.ItemsPerPage,
PageNum: &opts.PageNum,
}

if opts.OmitCount {
params.IncludeCount = pointer.Get(false)
}

if opts.status != "" {
params.Status = &opts.status
}
Expand Down Expand Up @@ -94,6 +100,8 @@ 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.status, flag.Status, "", usage.Status)
cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID)
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)
Expand Down
12 changes: 11 additions & 1 deletion internal/cli/atlas/alerts/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -22,6 +22,7 @@ import (

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
"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 @@ -75,3 +76,12 @@ func TestList_Run(t *testing.T) {
t.Log(buf.String())
test.VerifyOutputTemplate(t, listTemplate, expected)
}

func TestListBuilder(t *testing.T) {
test.CmdValidator(
t,
ListBuilder(),
0,
[]string{flag.ProjectID, flag.Output, flag.Page, flag.Limit, flag.OmitCount, flag.Status},
)
}
1 change: 1 addition & 0 deletions internal/cli/atlas/backup/exports/buckets/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,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
1 change: 1 addition & 0 deletions internal/cli/atlas/backup/exports/buckets/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func TestListBuilder(t *testing.T) {
flag.Limit,
flag.ProjectID,
flag.Output,
flag.OmitCount,
},
)
}
1 change: 1 addition & 0 deletions internal/cli/atlas/backup/exports/jobs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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
1 change: 1 addition & 0 deletions internal/cli/atlas/backup/exports/jobs/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestListBuilder(t *testing.T) {
flag.Limit,
flag.ProjectID,
flag.Output,
flag.OmitCount,
},
)
}
1 change: 1 addition & 0 deletions internal/cli/atlas/backup/restores/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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
1 change: 1 addition & 0 deletions internal/cli/atlas/backup/restores/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestListBuilder(t *testing.T) {
flag.Limit,
flag.ProjectID,
flag.Output,
flag.OmitCount,
},
)
}
1 change: 1 addition & 0 deletions internal/cli/atlas/backup/snapshots/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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
16 changes: 16 additions & 0 deletions internal/cli/atlas/backup/snapshots/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
"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 @@ -63,3 +64,18 @@ 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,
},
)
}
1 change: 1 addition & 0 deletions internal/cli/atlas/clusters/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,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
2 changes: 1 addition & 1 deletion internal/cli/atlas/clusters/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ func TestListBuilder(t *testing.T) {
t,
ListBuilder(),
0,
[]string{flag.Limit, flag.Page, flag.Output, flag.ProjectID},
[]string{flag.Limit, flag.Page, flag.Output, flag.ProjectID, flag.OmitCount},
)
}
3 changes: 2 additions & 1 deletion internal/cli/atlas/clusters/onlinearchive/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ func ListBuilder() *cobra.Command {
},
}

cmd.Flags().StringVar(&opts.clusterName, flag.ClusterName, "", usage.ClusterName)
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.clusterName, flag.ClusterName, "", usage.ClusterName)
cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID)
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/clusters/onlinearchive/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestListBuilder(t *testing.T) {
flag.Limit,
flag.Output,
flag.ProjectID,
flag.OmitCount,
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,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 @@ -88,6 +88,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, flag.CompletedAfter, flag.Pipeline},
)
}
1 change: 1 addition & 0 deletions internal/cli/atlas/dbusers/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.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/dbusers/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 Down Expand Up @@ -52,3 +53,12 @@ func TestDBUserList_Run(t *testing.T) {
}
test.VerifyOutputTemplate(t, listTemplate, expected)
}

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