Skip to content

Add empty state for gh pr list#142

Merged
probablycorey merged 5 commits intomasterfrom
empty-pr-list
Dec 10, 2019
Merged

Add empty state for gh pr list#142
probablycorey merged 5 commits intomasterfrom
empty-pr-list

Conversation

@probablycorey
Copy link
Copy Markdown
Contributor

@probablycorey probablycorey commented Dec 5, 2019

Where there are no PRs the output now looks like this...

Closes #134
Closes #138

@probablycorey probablycorey self-assigned this Dec 5, 2019
Copy link
Copy Markdown
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider existing with a nonzero status to indicate that the command "failed" (i.e. did not found any matching items)? I'm 50-50 on this one, and we can defer this decision until another time.

command/pr.go Outdated

if len(prs) == 0 {
colorOut := colorableOut(cmd)
printMessage(colorOut, "There are no open pull requests")
Copy link
Copy Markdown
Contributor

@mislav mislav Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of notes (more like a note avalanche):

  1. I think we should treat this message as a warning, and print it to stderr instead to stdout. This is because somebody might be piping pr list to a script, and they definitely don't want to process this message as if it were a PR entry.

  2. This message will be wrong if somebody invoked pr list --state closed. In this case, we should print “There are no closed pull requests”. Reword descriptive text if all issues are open #134

  3. How about indicating other filtering options? E.g. when --assignee was supplied, we might want to say “There are no open pull requests assigned to X”, or an equivalent for labels: Improve experience when no matches found for pr/issue list --label #89.

    On the other hand, generating English sentences for each permutation of filtering options can be a slippery slope towards code that's hard to maintain. Maybe we can circumvent all that just by always printing “There are no matching pull requests”.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what I'm leaning to, for simplicity:

  • No flags passed: “There are no open pull requests”
  • Some flags passed: “No pull requests matched your search” (to mirror “No results matched your search” shown by dotcom in the same scenario)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Piping this to stderr makes a lot of sense to me, also your suggestion of limiting the text to two messages is a good compromise. I'm going to go that direction.

@probablycorey
Copy link
Copy Markdown
Contributor Author

All right, after struggling with getting the flag values out of Cobra, this is what I've got. All that output is sent to stderr as well.

@nerdneha nerdneha added alpha and removed alpha labels Dec 10, 2019
msg := "There are no open issues"

userSetFlags := false
cmd.Flags().VisitAll(func(f *pflag.Flag) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: if you use Visit instead of VisitAll, it only visits "changed" flags

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮


userSetFlags := false
cmd.Flags().VisitAll(func(f *pflag.Flag) {
userSetFlags = f.Changed || userSetFlags
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to trigger on any flag that has a value set, including ones that don't change filtering options, such as -L 10 or -R owner/repo.

Perhaps we could put the names of filtering-related flags in a list and make sure we only iterate over those and no others?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the user the difference will be pretty small ("No pull requests match your search" vs "There are no open pull requests") and I think showing the "match your search" text still makes sense when the user supplies arguments. And adding that code is a little fragile because there would be no feedback when we add new commands, so I'm hesitant about relying on a list.

@probablycorey probablycorey merged commit d56e532 into master Dec 10, 2019
mislav pushed a commit that referenced this pull request Sep 28, 2021
ghcs delete: deprecate argument/subcommands & introduce flags
Stonre pushed a commit to Stonre/strands-fork that referenced this pull request Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No empty state for pr list Reword descriptive text if all issues are open

3 participants