Skip to content

Commit 893fe09

Browse files
committed
try passing iostreams around instead of writer+colorscheme
1 parent 74fe97b commit 893fe09

File tree

4 files changed

+34
-31
lines changed

4 files changed

+34
-31
lines changed

internal/authflow/flow.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ var (
2222
oauthClientSecret = "34ddeff2b558a23d38fba8a6de74f086ede1cc0b"
2323
)
2424

25-
func AuthFlowWithConfig(cfg config.Config, io *iostreams.IOStreams, hostname, notice string, additionalScopes []string) (string, error) {
25+
func AuthFlowWithConfig(cfg config.Config, IO *iostreams.IOStreams, hostname, notice string, additionalScopes []string) (string, error) {
2626
// TODO this probably shouldn't live in this package. It should probably be in a new package that
2727
// depends on both iostreams and config.
28-
stderr := io.ErrOut
29-
cs := io.ColorScheme()
28+
stderr := IO.ErrOut
29+
cs := IO.ColorScheme()
3030

31-
token, userLogin, err := authFlow(hostname, stderr, cs, notice, additionalScopes)
31+
token, userLogin, err := authFlow(hostname, IO, notice, additionalScopes)
3232
if err != nil {
3333
return "", err
3434
}
@@ -49,12 +49,15 @@ func AuthFlowWithConfig(cfg config.Config, io *iostreams.IOStreams, hostname, no
4949

5050
fmt.Fprintf(stderr, "%s Authentication complete. %s to continue...\n",
5151
cs.SuccessIcon(), cs.Bold("Press Enter"))
52-
_ = waitForEnter(os.Stdin)
52+
_ = waitForEnter(IO.In)
5353

5454
return token, nil
5555
}
5656

57-
func authFlow(oauthHost string, w io.Writer, cs *iostreams.ColorScheme, notice string, additionalScopes []string) (string, string, error) {
57+
func authFlow(oauthHost string, IO *iostreams.IOStreams, notice string, additionalScopes []string) (string, string, error) {
58+
w := IO.ErrOut
59+
cs := IO.ColorScheme()
60+
5861
var verboseStream io.Writer
5962
if strings.Contains(os.Getenv("DEBUG"), "oauth") {
6063
verboseStream = w
@@ -78,7 +81,7 @@ func authFlow(oauthHost string, w io.Writer, cs *iostreams.ColorScheme, notice s
7881
fmt.Fprintf(w, "%s First copy your one-time code: %s\n", cs.Yellow("!"), cs.Bold(code))
7982
}
8083
fmt.Fprintf(w, "- %s to open %s in your browser... ", cs.Bold("Press Enter"), oauthHost)
81-
_ = waitForEnter(os.Stdin)
84+
_ = waitForEnter(IO.In)
8285

8386
browseCmd, err := browser.Command(url)
8487
if err != nil {

pkg/cmd/issue/status/status.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,33 @@ func statusRun(opts *StatusOptions) error {
7575
defer opts.IO.StopPager()
7676

7777
out := opts.IO.Out
78-
cs := opts.IO.ColorScheme()
7978

8079
fmt.Fprintln(out, "")
8180
fmt.Fprintf(out, "Relevant issues in %s\n", ghrepo.FullName(baseRepo))
8281
fmt.Fprintln(out, "")
8382

84-
prShared.PrintHeader(cs, out, "Issues assigned to you")
83+
prShared.PrintHeader(opts.IO, "Issues assigned to you")
8584
if issuePayload.Assigned.TotalCount > 0 {
8685
issueShared.PrintIssues(opts.IO, " ", issuePayload.Assigned.TotalCount, issuePayload.Assigned.Issues)
8786
} else {
8887
message := " There are no issues assigned to you"
89-
prShared.PrintMessage(cs, out, message)
88+
prShared.PrintMessage(opts.IO, message)
9089
}
9190
fmt.Fprintln(out)
9291

93-
prShared.PrintHeader(cs, out, "Issues mentioning you")
92+
prShared.PrintHeader(opts.IO, "Issues mentioning you")
9493
if issuePayload.Mentioned.TotalCount > 0 {
9594
issueShared.PrintIssues(opts.IO, " ", issuePayload.Mentioned.TotalCount, issuePayload.Mentioned.Issues)
9695
} else {
97-
prShared.PrintMessage(cs, out, " There are no issues mentioning you")
96+
prShared.PrintMessage(opts.IO, " There are no issues mentioning you")
9897
}
9998
fmt.Fprintln(out)
10099

101-
prShared.PrintHeader(cs, out, "Issues opened by you")
100+
prShared.PrintHeader(opts.IO, "Issues opened by you")
102101
if issuePayload.Authored.TotalCount > 0 {
103102
issueShared.PrintIssues(opts.IO, " ", issuePayload.Authored.TotalCount, issuePayload.Authored.Issues)
104103
} else {
105-
prShared.PrintMessage(cs, out, " There are no issues opened by you")
104+
prShared.PrintMessage(opts.IO, " There are no issues opened by you")
106105
}
107106
fmt.Fprintln(out)
108107

pkg/cmd/pr/shared/display.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package shared
22

33
import (
44
"fmt"
5-
"io"
65
"strings"
76

87
"github.com/cli/cli/api"
@@ -40,12 +39,12 @@ func ColorForState(state string) string {
4039
}
4140
}
4241

43-
func PrintHeader(cs *iostreams.ColorScheme, w io.Writer, s string) {
44-
fmt.Fprintln(w, cs.Bold(s))
42+
func PrintHeader(io *iostreams.IOStreams, s string) {
43+
fmt.Fprintln(io.Out, io.ColorScheme().Bold(s))
4544
}
4645

47-
func PrintMessage(cs *iostreams.ColorScheme, w io.Writer, s string) {
48-
fmt.Fprintln(w, cs.Gray(s))
46+
func PrintMessage(io *iostreams.IOStreams, s string) {
47+
fmt.Fprintln(io.Out, io.ColorScheme().Gray(s))
4948
}
5049

5150
func ListHeader(repoName string, itemName string, matchCount int, totalMatchCount int, hasFilters bool) string {

pkg/cmd/pr/status/status.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package status
33
import (
44
"errors"
55
"fmt"
6-
"io"
76
"net/http"
87
"regexp"
98
"strconv"
@@ -109,33 +108,33 @@ func statusRun(opts *StatusOptions) error {
109108
fmt.Fprintf(out, "Relevant pull requests in %s\n", ghrepo.FullName(baseRepo))
110109
fmt.Fprintln(out, "")
111110

112-
shared.PrintHeader(cs, out, "Current branch")
111+
shared.PrintHeader(opts.IO, "Current branch")
113112
currentPR := prPayload.CurrentPR
114113
if currentPR != nil && currentPR.State != "OPEN" && prPayload.DefaultBranch == currentBranch {
115114
currentPR = nil
116115
}
117116
if currentPR != nil {
118-
printPrs(cs, out, 1, *currentPR)
117+
printPrs(opts.IO, 1, *currentPR)
119118
} else if currentPRHeadRef == "" {
120-
shared.PrintMessage(cs, out, " There is no current branch")
119+
shared.PrintMessage(opts.IO, " There is no current branch")
121120
} else {
122-
shared.PrintMessage(cs, out, fmt.Sprintf(" There is no pull request associated with %s", cs.Cyan("["+currentPRHeadRef+"]")))
121+
shared.PrintMessage(opts.IO, fmt.Sprintf(" There is no pull request associated with %s", cs.Cyan("["+currentPRHeadRef+"]")))
123122
}
124123
fmt.Fprintln(out)
125124

126-
shared.PrintHeader(cs, out, "Created by you")
125+
shared.PrintHeader(opts.IO, "Created by you")
127126
if prPayload.ViewerCreated.TotalCount > 0 {
128-
printPrs(cs, out, prPayload.ViewerCreated.TotalCount, prPayload.ViewerCreated.PullRequests...)
127+
printPrs(opts.IO, prPayload.ViewerCreated.TotalCount, prPayload.ViewerCreated.PullRequests...)
129128
} else {
130-
shared.PrintMessage(cs, out, " You have no open pull requests")
129+
shared.PrintMessage(opts.IO, " You have no open pull requests")
131130
}
132131
fmt.Fprintln(out)
133132

134-
shared.PrintHeader(cs, out, "Requesting a code review from you")
133+
shared.PrintHeader(opts.IO, "Requesting a code review from you")
135134
if prPayload.ReviewRequested.TotalCount > 0 {
136-
printPrs(cs, out, prPayload.ReviewRequested.TotalCount, prPayload.ReviewRequested.PullRequests...)
135+
printPrs(opts.IO, prPayload.ReviewRequested.TotalCount, prPayload.ReviewRequested.PullRequests...)
137136
} else {
138-
shared.PrintMessage(cs, out, " You have no pull requests to review")
137+
shared.PrintMessage(opts.IO, " You have no pull requests to review")
139138
}
140139
fmt.Fprintln(out)
141140

@@ -179,7 +178,10 @@ func prSelectorForCurrentBranch(baseRepo ghrepo.Interface, prHeadRef string, rem
179178
return
180179
}
181180

182-
func printPrs(cs *iostreams.ColorScheme, w io.Writer, totalCount int, prs ...api.PullRequest) {
181+
func printPrs(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest) {
182+
w := io.Out
183+
cs := io.ColorScheme()
184+
183185
for _, pr := range prs {
184186
prNumber := fmt.Sprintf("#%d", pr.Number)
185187

0 commit comments

Comments
 (0)