X Tutup
Skip to content

Commit 50291aa

Browse files
committed
Add PAGER support to the api command
1 parent 7618115 commit 50291aa

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pkg/cmd/api/api.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"sort"
1414
"strconv"
1515
"strings"
16+
"syscall"
1617

1718
"github.com/MakeNowJust/heredoc"
1819
"github.com/cli/cli/internal/ghinstance"
@@ -196,6 +197,12 @@ func apiRun(opts *ApiOptions) error {
196197
headersOutputStream := opts.IO.Out
197198
if opts.Silent {
198199
opts.IO.Out = ioutil.Discard
200+
} else {
201+
err := opts.IO.StartPager()
202+
if err != nil {
203+
return err
204+
}
205+
defer opts.IO.StopPager()
199206
}
200207

201208
host := ghinstance.OverridableDefault()
@@ -265,12 +272,13 @@ func processResponse(resp *http.Response, opts *ApiOptions, headersOutputStream
265272

266273
if isJSON && opts.IO.ColorEnabled() {
267274
err = jsoncolor.Write(opts.IO.Out, responseBody, " ")
268-
if err != nil {
269-
return
270-
}
271275
} else {
272276
_, err = io.Copy(opts.IO.Out, responseBody)
273-
if err != nil {
277+
}
278+
if err != nil {
279+
if errors.Is(err, syscall.EPIPE) {
280+
err = nil
281+
} else {
274282
return
275283
}
276284
}

0 commit comments

Comments
 (0)
X Tutup