Skip to content

Commit

Permalink
fix(cmd): listing page 2 starts numbering at the offset
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed May 23, 2019
1 parent 32b8793 commit b37d186
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (o *ListOptions) Run() (err error) {
for i, r := range refs {
items[i] = refStringer(r)
}
printItems(o.Out, items)
printItems(o.Out, items, page.Offset())
return nil
case dataset.JSONDataFormat.String():
data, err := json.MarshalIndent(refs, "", " ")
Expand Down
2 changes: 1 addition & 1 deletion cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ func (o *LogOptions) Run() error {
items[i] = logStringer(r)
}

printItems(o.Out, items)
printItems(o.Out, items, page.Offset())
return nil
}
2 changes: 1 addition & 1 deletion cmd/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (o *PeersOptions) List() (err error) {
}
}

printItems(o.Out, items)
printItems(o.Out, items, page.Offset())
return
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ func printErr(w io.Writer, err error, params ...interface{}) {
fmt.Fprintln(w, color.New(color.FgRed).Sprintf(err.Error(), params...))
}

func printItems(w io.Writer, items []fmt.Stringer) (err error) {
// print a slice of stringer items to io.Writer as an indented & numbered list
// offset specifies the number of items that have been skipped, index is 1-based
func printItems(w io.Writer, items []fmt.Stringer, offset int) (err error) {
buf := &bytes.Buffer{}
prefix := []byte(" ")
for i, item := range items {
buf.WriteString(fmtItem(i+1, item.String(), prefix))
buf.WriteString(fmtItem(i+1+offset, item.String(), prefix))
}
return printToPager(w, buf)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (o *SearchOptions) Run() (err error) {
items[i] = refStringer(*ref)
}
o.StopSpinner()
printItems(o.Out, items)
printItems(o.Out, items, page.Offset())
return nil

case dataset.JSONDataFormat.String():
Expand Down
4 changes: 2 additions & 2 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (o *UpdateOptions) List() (err error) {
for i, r := range res {
items[i] = jobStringer(*r)
}
printItems(o.Out, items)
printItems(o.Out, items, page.Offset())
return
}

Expand All @@ -380,7 +380,7 @@ func (o *UpdateOptions) Logs(args []string) (err error) {
for i, r := range res {
items[i] = jobStringer(*r)
}
printItems(o.Out, items)
printItems(o.Out, items, page.Offset())
return
}

Expand Down

0 comments on commit b37d186

Please sign in to comment.