Skip to content

Commit 62d5da8

Browse files
committed
refactor(cmd): change limit and offset flags to page and page-size
BREAKING CHANGE: On the cli, all `limit` and `offset` flags have been changed to `page` and `page-size`.
1 parent 2e623db commit 62d5da8

File tree

5 files changed

+51
-38
lines changed

5 files changed

+51
-38
lines changed

cmd/cmd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func TestCommandsIntegration(t *testing.T) {
181181
// "qri registry unpublish me/movies",
182182
// "qri registry publish me/movies",
183183
"qri rename me/movies me/movie",
184-
"qri get body --limit=1 --format=cbor me/movie",
184+
"qri get body --page-size=1 --format=cbor me/movie",
185185
"qri validate me/movie",
186186
"qri remove me/movie --revisions=all",
187187
fmt.Sprintf("qri export --blank -o=%s/blank_dataset.yaml", path),

cmd/get.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ dataset and its fields.`,
4949

5050
cmd.Flags().StringVarP(&o.Format, "format", "f", "", "set output format [json, yaml]")
5151
cmd.Flags().BoolVar(&o.Concise, "concise", false, "print output without indentation, only applies to json format")
52-
cmd.Flags().IntVarP(&o.Limit, "limit", "l", -1, "for body, limit how many entries to get")
53-
cmd.Flags().IntVarP(&o.Offset, "offset", "s", -1, "for body, offset at which to get entries")
52+
cmd.Flags().IntVar(&o.PageSize, "page-size", -1, "for body, limit how many entries to get per page")
53+
cmd.Flags().IntVar(&o.Page, "page", -1, "for body, page at which to get entries")
5454
cmd.Flags().BoolVarP(&o.All, "all", "a", true, "for body, whether to get all entries")
5555

5656
return cmd
@@ -65,9 +65,9 @@ type GetOptions struct {
6565
Format string
6666
Concise bool
6767

68-
Limit int
69-
Offset int
70-
All bool
68+
Page int
69+
PageSize int
70+
All bool
7171

7272
DatasetRequests *lib.DatasetRequests
7373
}
@@ -89,20 +89,20 @@ func (o *GetOptions) Complete(f Factory, args []string) (err error) {
8989
}
9090

9191
if o.Selector == "body" {
92-
// if we have a limit, but not offset, assume an offset of 0
93-
if o.Limit != -1 && o.Offset == -1 {
94-
o.Offset = 0
92+
// if we have a PageSize, but not Page, assume an Page of 1
93+
if o.PageSize != -1 && o.Page == -1 {
94+
o.Page = 1
9595
}
96-
// set all to false if limit or offset values are provided
97-
if o.Limit != -1 || o.Offset != -1 {
96+
// set all to false if PageSize or Page values are provided
97+
if o.PageSize != -1 || o.Page != -1 {
9898
o.All = false
9999
}
100100
} else {
101-
if o.Limit != -1 {
102-
return fmt.Errorf("can only use --limit flag when getting body")
101+
if o.PageSize != -1 {
102+
return fmt.Errorf("can only use --page-size flag when getting body")
103103
}
104-
if o.Offset != -1 {
105-
return fmt.Errorf("can only use --offset flag when getting body")
104+
if o.Page != -1 {
105+
return fmt.Errorf("can only use --page flag when getting body")
106106
}
107107
if !o.All {
108108
return fmt.Errorf("can only use --all flag when getting body")
@@ -122,13 +122,16 @@ func (o *GetOptions) Run() (err error) {
122122
}
123123
}
124124

125+
// convert Page and PageSize to Limit and Offset
126+
listParams := lib.NewListParams("", o.Page, o.PageSize)
127+
125128
p := lib.GetParams{
126129
Path: path,
127130
Selector: o.Selector,
128131
Format: o.Format,
129132
Concise: o.Concise,
130-
Offset: o.Offset,
131-
Limit: o.Limit,
133+
Offset: listParams.Offset,
134+
Limit: listParams.Limit,
132135
All: o.All,
133136
}
134137
res := lib.GetResult{}

cmd/list.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ must have ` + "`qri connect`" + ` running in a separate terminal window.`,
5151
}
5252

5353
cmd.Flags().StringVarP(&o.Format, "format", "f", "", "set output format [json]")
54-
cmd.Flags().IntVarP(&o.Limit, "limit", "l", 25, "limit results, default 25")
55-
cmd.Flags().IntVarP(&o.Offset, "offset", "o", 0, "offset results, default 0")
54+
cmd.Flags().IntVar(&o.PageSize, "page-size", 25, "page size of results, default 25")
55+
cmd.Flags().IntVar(&o.Page, "page", 1, "page number results, default 1")
5656
cmd.Flags().BoolVarP(&o.Published, "published", "p", false, "list only published datasets")
5757
cmd.Flags().BoolVarP(&o.ShowNumVersions, "num-versions", "n", false, "show number of versions")
5858
cmd.Flags().StringVar(&o.Peername, "peer", "", "peer whose datasets to list")
@@ -65,8 +65,8 @@ type ListOptions struct {
6565
ioes.IOStreams
6666

6767
Format string
68-
Limit int
69-
Offset int
68+
PageSize int
69+
Page int
7070
Term string
7171
Peername string
7272
Published bool
@@ -87,12 +87,15 @@ func (o *ListOptions) Complete(f Factory, args []string) (err error) {
8787
// Run executes the list command
8888
func (o *ListOptions) Run() (err error) {
8989

90+
// convert Page and PageSize to Limit and Offset
91+
listParams := lib.NewListParams("", o.Page, o.PageSize)
92+
9093
refs := []repo.DatasetRef{}
9194
p := &lib.ListParams{
9295
Term: o.Term,
9396
Peername: o.Peername,
94-
Limit: o.Limit,
95-
Offset: o.Offset,
97+
Limit: listParams.Limit,
98+
Offset: listParams.Offset,
9699
Published: o.Published,
97100
ShowNumVersions: o.ShowNumVersions,
98101
}

cmd/peers.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ You must have ` + "`qri connect`" + ` running in another terminal.`,
141141

142142
list.Flags().BoolVarP(&o.Cached, "cached", "c", false, "show peers that aren't online, but previously seen")
143143
list.Flags().StringVarP(&o.Network, "network", "n", "", "specify network to show peers from [ipfs]")
144-
list.Flags().IntVarP(&o.Limit, "limit", "l", 200, "limit max number of peers to show")
145-
list.Flags().IntVarP(&o.Offset, "offset", "s", 0, "number of peers to skip during listing")
144+
// TODO (ramfox): when we determine the best way to order and paginate peers, restore!
145+
// list.Flags().IntVar(&o.PageSize, "page-size", 200, "max page size number of peers to show, default 200")
146+
// list.Flags().IntVar(&o.Page, "page", 1, "page number of peers, default 1")
146147

147148
cmd.AddCommand(info, list, connect, disconnect)
148149

@@ -158,8 +159,8 @@ type PeersOptions struct {
158159
Format string
159160
Cached bool
160161
Network string
161-
Limit int
162-
Offset int
162+
PageSize int
163+
Page int
163164

164165
UsingRPC bool
165166
PeerRequests *lib.PeerRequests
@@ -210,9 +211,13 @@ func (o *PeersOptions) Info() (err error) {
210211

211212
// List shows a list of peers
212213
func (o *PeersOptions) List() (err error) {
214+
215+
// convert Page and PageSize to Limit and Offset
216+
listParams := lib.NewListParams("", o.Page, o.PageSize)
217+
213218
if o.Network == "ipfs" {
214219
res := []string{}
215-
if err := o.PeerRequests.ConnectedIPFSPeers(&o.Limit, &res); err != nil {
220+
if err := o.PeerRequests.ConnectedIPFSPeers(&listParams.Limit, &res); err != nil {
216221
return err
217222
}
218223

@@ -227,8 +232,8 @@ func (o *PeersOptions) List() (err error) {
227232
}
228233

229234
p := &lib.PeerListParams{
230-
Limit: o.Limit,
231-
Offset: o.Offset,
235+
Limit: listParams.Limit,
236+
Offset: listParams.Offset,
232237
Cached: o.Cached,
233238
}
234239
res := []*config.ProfilePod{}
@@ -242,7 +247,7 @@ func (o *PeersOptions) List() (err error) {
242247
// it make sense to try out printing to less here
243248
// where limit and offset don't mean as much
244249
buf := bytes.Buffer{}
245-
fmt.Fprintln(&buf, "Cached Qri Peers List:\n")
250+
fmt.Fprintln(&buf, "Cached Qri Peers List:")
246251
for i, peer := range res {
247252
printPeerInfoNoColor(&buf, i, peer)
248253
}

cmd/search.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Any dataset that has been published to the registry is available for search.`,
3838
}
3939

4040
cmd.Flags().StringVarP(&o.Format, "format", "f", "", "set output format [json]")
41-
cmd.Flags().IntVarP(&o.Limit, "limit", "l", 25, "limit results, default 25")
42-
cmd.Flags().IntVarP(&o.Offset, "offset", "o", 0, "offset results, default 0")
41+
cmd.Flags().IntVar(&o.PageSize, "page-size", 25, "page size of results, default 25")
42+
cmd.Flags().IntVar(&o.Page, "page", 1, "page number of results, default 1")
4343

4444
return cmd
4545
}
@@ -51,9 +51,8 @@ type SearchOptions struct {
5151
Query string
5252
SearchRequests *lib.SearchRequests
5353
Format string
54-
// TODO: add support for specifying limit and offset
55-
Limit int
56-
Offset int
54+
PageSize int
55+
Page int
5756
// Reindex bool
5857
}
5958

@@ -81,10 +80,13 @@ func (o *SearchOptions) Run() (err error) {
8180

8281
// TODO: add reindex option back in
8382

83+
// convert Page and PageSize to Limit and Offset
84+
listParams := lib.NewListParams("", o.Page, o.PageSize)
85+
8486
p := &lib.SearchParams{
8587
QueryString: o.Query,
86-
Limit: o.Limit,
87-
Offset: o.Offset,
88+
Limit: listParams.Limit,
89+
Offset: listParams.Offset,
8890
}
8991

9092
results := []lib.SearchResult{}

0 commit comments

Comments
 (0)