File: show_ref_grouper.go

package info (click to toggle)
git-sizer 1.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 616 kB
  • sloc: sh: 100; makefile: 61
file content (34 lines) | stat: -rw-r--r-- 771 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package refopts

import (
	"fmt"
	"io"

	"github.com/github/git-sizer/sizes"
)

// showRefFilter is a `git.ReferenceFilter` that logs its choices to
// an `io.Writer`.
type showRefGrouper struct {
	sizes.RefGrouper
	w io.Writer
}

// Return a `sizes.RefGrouper` that wraps its argument and behaves
// like it except that it also logs its decisions to an `io.Writer`.
func NewShowRefGrouper(rg sizes.RefGrouper, w io.Writer) sizes.RefGrouper {
	return showRefGrouper{
		RefGrouper: rg,
		w:          w,
	}
}

func (rg showRefGrouper) Categorize(refname string) (bool, []sizes.RefGroupSymbol) {
	walk, symbols := rg.RefGrouper.Categorize(refname)
	if walk {
		fmt.Fprintf(rg.w, "+ %s\n", refname)
	} else {
		fmt.Fprintf(rg.w, "  %s\n", refname)
	}
	return walk, symbols
}