Skip to content

Commit

Permalink
util: unexport the Pager structure
Browse files Browse the repository at this point in the history
Pager was being declared as an exported struct (capital letter), which
isn't correct, since it's only used within the "cmd" package. This patch
unexport it and corrects any occurrence of "pager" variable vs "pager"
structure conflicts.

Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
  • Loading branch information
bmeneg committed Jun 15, 2021
1 parent ec7ed8e commit 93c4938
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/ci_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var ciStatusCmd = &cobra.Command{

pid := rn

pager := NewPager(cmd.Flags())
pager := newPager(cmd.Flags())
defer pager.Close()

w := tabwriter.NewWriter(os.Stdout, 2, 4, 1, byte(' '), 0)
Expand Down
2 changes: 1 addition & 1 deletion cmd/ci_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var ciTraceCmd = &cobra.Command{
}
projectID = project.ID

pager := NewPager(cmd.Flags())
pager := newPager(cmd.Flags())
defer pager.Close()

err = doTrace(context.Background(), os.Stdout, projectID, pipelineID, jobName)
Expand Down
2 changes: 1 addition & 1 deletion cmd/issue_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var issueListCmd = &cobra.Command{
log.Fatal(err)
}

pager := NewPager(cmd.Flags())
pager := newPager(cmd.Flags())
defer pager.Close()

for _, issue := range issues {
Expand Down
2 changes: 1 addition & 1 deletion cmd/issue_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var issueShowCmd = &cobra.Command{
renderMarkdown = !noMarkdown
}

pager := NewPager(cmd.Flags())
pager := newPager(cmd.Flags())
defer pager.Close()

printIssue(issue, rn, renderMarkdown)
Expand Down
2 changes: 1 addition & 1 deletion cmd/label_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var labelListCmd = &cobra.Command{
log.Fatal(err)
}

pager := NewPager(cmd.Flags())
pager := newPager(cmd.Flags())
defer pager.Close()

for _, label := range labels {
Expand Down
2 changes: 1 addition & 1 deletion cmd/mr_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var listCmd = &cobra.Command{
log.Fatal(err)
}

pager := NewPager(cmd.Flags())
pager := newPager(cmd.Flags())
defer pager.Close()

for _, mr := range mrs {
Expand Down
2 changes: 1 addition & 1 deletion cmd/mr_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var mrShowCmd = &cobra.Command{
}
git.Show(remote+"/"+mr.TargetBranch, mr.SHA, mrShowPatchReverse)
} else {
pager := NewPager(cmd.Flags())
pager := newPager(cmd.Flags())
defer pager.Close()

printMR(mr, rn, renderMarkdown)
Expand Down
2 changes: 1 addition & 1 deletion cmd/project_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var projectListCmd = &cobra.Command{
log.Fatal(err)
}

pager := NewPager(cmd.Flags())
pager := newPager(cmd.Flags())
defer pager.Close()

for _, p := range projects {
Expand Down
2 changes: 1 addition & 1 deletion cmd/snippet_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var snippetListCmd = &cobra.Command{
if err != nil {
log.Fatal(err)
}
pager := NewPager(cmd.Flags())
pager := newPager(cmd.Flags())
defer pager.Close()
for _, snip := range snips {
fmt.Printf("#%d %s\n", snip.ID, snip.Title)
Expand Down
2 changes: 1 addition & 1 deletion cmd/todo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var todoListCmd = &cobra.Command{
log.Fatal(err)
}

pager := NewPager(cmd.Flags())
pager := newPager(cmd.Flags())
defer pager.Close()

red := color.New(color.FgRed).SprintFunc()
Expand Down
21 changes: 11 additions & 10 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,20 +418,20 @@ func isOutputTerminal() bool {
return true
}

type Pager struct {
type pager struct {
proc *os.Process
stdout int
}

// If standard output is a terminal, redirect output to an external
// pager until the returned object's Close() method is called
func NewPager(fs *flag.FlagSet) *Pager {
func newPager(fs *flag.FlagSet) *pager {
cmdLine, env := git.PagerCommand()
args := strings.Split(cmdLine, " ")

noPager, _ := fs.GetBool("no-pager")
if !isOutputTerminal() || noPager || args[0] == "cat" {
return &Pager{}
return &pager{}
}

pr, pw, _ := os.Pipe()
Expand All @@ -446,19 +446,20 @@ func NewPager(fs *flag.FlagSet) *Pager {
savedStdout, _ := dupFD(sysStdout)
_ = dupFD2(int(pw.Fd()), sysStdout)

return &Pager{
return &pager{
proc: proc,
stdout: savedStdout,
}
}

func (pager *Pager) Close() {
if pager.stdout > 0 {
_ = dupFD2(pager.stdout, sysStdout)
_ = closeFD(pager.stdout)
// Close closes the pager
func (p *pager) Close() {
if p.stdout > 0 {
_ = dupFD2(p.stdout, sysStdout)
_ = closeFD(p.stdout)
}
if pager.proc != nil {
pager.proc.Wait()
if p.proc != nil {
p.proc.Wait()
}
}

Expand Down

0 comments on commit 93c4938

Please sign in to comment.