Skip to content

Commit 5949ca4

Browse files
Merge pull request cli#142 from github/empty-pr-list
Add empty state for `gh pr list`
2 parents 71add1b + 00b38bb commit 5949ca4

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

command/issue.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/github/gh-cli/utils"
1414
"github.com/pkg/errors"
1515
"github.com/spf13/cobra"
16+
"github.com/spf13/pflag"
1617
)
1718

1819
func init() {
@@ -102,14 +103,22 @@ func issueList(cmd *cobra.Command, args []string) error {
102103
return err
103104
}
104105

105-
out := cmd.OutOrStdout()
106-
colorOut := colorableOut(cmd)
107-
108106
if len(issues) == 0 {
109-
printMessage(colorOut, "There are no open issues")
107+
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
108+
msg := "There are no open issues"
109+
110+
userSetFlags := false
111+
cmd.Flags().VisitAll(func(f *pflag.Flag) {
112+
userSetFlags = f.Changed || userSetFlags
113+
})
114+
if userSetFlags {
115+
msg = "No issues match your search"
116+
}
117+
printMessage(colorErr, msg)
110118
return nil
111119
}
112120

121+
out := cmd.OutOrStdout()
113122
table := utils.NewTablePrinter(out)
114123
for _, issue := range issues {
115124
issueNum := strconv.Itoa(issue.Number)

command/pr.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/github/gh-cli/git"
1515
"github.com/github/gh-cli/utils"
1616
"github.com/spf13/cobra"
17+
"github.com/spf13/pflag"
1718
)
1819

1920
func init() {
@@ -185,6 +186,21 @@ func prList(cmd *cobra.Command, args []string) error {
185186
return err
186187
}
187188

189+
if len(prs) == 0 {
190+
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
191+
msg := "There are no open pull requests"
192+
193+
userSetFlags := false
194+
cmd.Flags().VisitAll(func(f *pflag.Flag) {
195+
userSetFlags = f.Changed || userSetFlags
196+
})
197+
if userSetFlags {
198+
msg = "No pull requests match your search"
199+
}
200+
printMessage(colorErr, msg)
201+
return nil
202+
}
203+
188204
table := utils.NewTablePrinter(cmd.OutOrStdout())
189205
for _, pr := range prs {
190206
prNum := strconv.Itoa(pr.Number)

command/root.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,11 @@ func colorableOut(cmd *cobra.Command) io.Writer {
117117
}
118118
return out
119119
}
120+
121+
func colorableErr(cmd *cobra.Command) io.Writer {
122+
err := cmd.ErrOrStderr()
123+
if outFile, isFile := err.(*os.File); isFile {
124+
return utils.NewColorable(outFile)
125+
}
126+
return err
127+
}

0 commit comments

Comments
 (0)