From fee303699aeea4829078f4f463fed8bfe854fd85 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 5 Dec 2019 12:01:05 -0800 Subject: [PATCH 1/5] Show message when there are no PRs --- command/pr.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/command/pr.go b/command/pr.go index ccb5f13a7..d124c5e4f 100644 --- a/command/pr.go +++ b/command/pr.go @@ -180,6 +180,12 @@ func prList(cmd *cobra.Command, args []string) error { return err } + if len(prs) == 0 { + colorOut := colorableOut(cmd) + printMessage(colorOut, "There are no open pull requests") + return nil + } + table := utils.NewTablePrinter(cmd.OutOrStdout()) for _, pr := range prs { prNum := strconv.Itoa(pr.Number) From f1eb29b79189a2675db39922fa1b276fa20889eb Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 6 Dec 2019 13:32:36 -0800 Subject: [PATCH 2/5] Add colorableErr --- command/root.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/command/root.go b/command/root.go index 33a8c4aa5..8c2c892be 100644 --- a/command/root.go +++ b/command/root.go @@ -117,3 +117,11 @@ func colorableOut(cmd *cobra.Command) io.Writer { } return out } + +func colorableErr(cmd *cobra.Command) io.Writer { + out := cmd.ErrOrStderr() + if outFile, isFile := out.(*os.File); isFile { + return utils.NewColorable(outFile) + } + return out +} From 387b9d954464e2cca4320ffa36749f2b3cfa2fa0 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 6 Dec 2019 13:33:23 -0800 Subject: [PATCH 3/5] better name? --- command/root.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/command/root.go b/command/root.go index 8c2c892be..c925285ed 100644 --- a/command/root.go +++ b/command/root.go @@ -119,9 +119,9 @@ func colorableOut(cmd *cobra.Command) io.Writer { } func colorableErr(cmd *cobra.Command) io.Writer { - out := cmd.ErrOrStderr() - if outFile, isFile := out.(*os.File); isFile { + err := cmd.ErrOrStderr() + if outFile, isFile := err.(*os.File); isFile { return utils.NewColorable(outFile) } - return out + return err } From 9aa3f35f8a1265811797ea58a7159bd8e50c3619 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 6 Dec 2019 13:33:57 -0800 Subject: [PATCH 4/5] Better language in the "no pr" state --- command/pr.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/command/pr.go b/command/pr.go index d124c5e4f..16695798f 100644 --- a/command/pr.go +++ b/command/pr.go @@ -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() { @@ -181,8 +182,17 @@ func prList(cmd *cobra.Command, args []string) error { } if len(prs) == 0 { - colorOut := colorableOut(cmd) - printMessage(colorOut, "There are no open pull requests") + colorErr := colorableErr(cmd) // If the user is piping this command we don't want them to process this message as if it were a PR entry + 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 matched your search" + } + printMessage(colorErr, msg) return nil } From 00b38bb11c74ed64a3ce92b33078d8f85fd124fd Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 6 Dec 2019 14:10:01 -0800 Subject: [PATCH 5/5] Add better message to empty `gh issue list` --- command/issue.go | 17 +++++++++++++---- command/pr.go | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/command/issue.go b/command/issue.go index 0dd35ca4f..10ecf8a08 100644 --- a/command/issue.go +++ b/command/issue.go @@ -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() { @@ -98,14 +99,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) diff --git a/command/pr.go b/command/pr.go index 16695798f..d3bd8dece 100644 --- a/command/pr.go +++ b/command/pr.go @@ -182,7 +182,7 @@ func prList(cmd *cobra.Command, args []string) error { } if len(prs) == 0 { - colorErr := colorableErr(cmd) // If the user is piping this command we don't want them to process this message as if it were a PR entry + 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 @@ -190,7 +190,7 @@ func prList(cmd *cobra.Command, args []string) error { userSetFlags = f.Changed || userSetFlags }) if userSetFlags { - msg = "No pull requests matched your search" + msg = "No pull requests match your search" } printMessage(colorErr, msg) return nil