Merge pull request #142 from github/empty-pr-list

Add empty state for `gh pr list`
This commit is contained in:
Corey Johnson 2019-12-10 12:04:41 -08:00 committed by GitHub
commit 5949ca4b56
3 changed files with 37 additions and 4 deletions

View file

@ -13,6 +13,7 @@ import (
"github.com/github/gh-cli/utils"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
func init() {
@ -102,14 +103,22 @@ func issueList(cmd *cobra.Command, args []string) error {
return err
}
out := cmd.OutOrStdout()
colorOut := colorableOut(cmd)
if len(issues) == 0 {
printMessage(colorOut, "There are no open issues")
colorErr := colorableErr(cmd) // Send to stderr because otherwise when piping this command it would seem like the "no open issues" message is acually an issue
msg := "There are no open issues"
userSetFlags := false
cmd.Flags().VisitAll(func(f *pflag.Flag) {
userSetFlags = f.Changed || userSetFlags
})
if userSetFlags {
msg = "No issues match your search"
}
printMessage(colorErr, msg)
return nil
}
out := cmd.OutOrStdout()
table := utils.NewTablePrinter(out)
for _, issue := range issues {
issueNum := strconv.Itoa(issue.Number)

View file

@ -14,6 +14,7 @@ import (
"github.com/github/gh-cli/git"
"github.com/github/gh-cli/utils"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
func init() {
@ -185,6 +186,21 @@ func prList(cmd *cobra.Command, args []string) error {
return err
}
if len(prs) == 0 {
colorErr := colorableErr(cmd) // Send to stderr because otherwise when piping this command it would seem like the "no open prs" message is acually a pr
msg := "There are no open pull requests"
userSetFlags := false
cmd.Flags().VisitAll(func(f *pflag.Flag) {
userSetFlags = f.Changed || userSetFlags
})
if userSetFlags {
msg = "No pull requests match your search"
}
printMessage(colorErr, msg)
return nil
}
table := utils.NewTablePrinter(cmd.OutOrStdout())
for _, pr := range prs {
prNum := strconv.Itoa(pr.Number)

View file

@ -117,3 +117,11 @@ func colorableOut(cmd *cobra.Command) io.Writer {
}
return out
}
func colorableErr(cmd *cobra.Command) io.Writer {
err := cmd.ErrOrStderr()
if outFile, isFile := err.(*os.File); isFile {
return utils.NewColorable(outFile)
}
return err
}