Add PAGER support to the api command

This commit is contained in:
Mislav Marohnić 2020-09-15 11:43:49 +02:00
parent 76181156ba
commit 50291aa6de

View file

@ -13,6 +13,7 @@ import (
"sort"
"strconv"
"strings"
"syscall"
"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/internal/ghinstance"
@ -196,6 +197,12 @@ func apiRun(opts *ApiOptions) error {
headersOutputStream := opts.IO.Out
if opts.Silent {
opts.IO.Out = ioutil.Discard
} else {
err := opts.IO.StartPager()
if err != nil {
return err
}
defer opts.IO.StopPager()
}
host := ghinstance.OverridableDefault()
@ -265,12 +272,13 @@ func processResponse(resp *http.Response, opts *ApiOptions, headersOutputStream
if isJSON && opts.IO.ColorEnabled() {
err = jsoncolor.Write(opts.IO.Out, responseBody, " ")
if err != nil {
return
}
} else {
_, err = io.Copy(opts.IO.Out, responseBody)
if err != nil {
}
if err != nil {
if errors.Is(err, syscall.EPIPE) {
err = nil
} else {
return
}
}