fix
This commit is contained in:
parent
4545f636ab
commit
111c621643
3 changed files with 78 additions and 78 deletions
37
summary.go
37
summary.go
|
@ -2,7 +2,6 @@ package binfo
|
|||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
@ -10,11 +9,11 @@ import (
|
|||
type SummaryMode uint
|
||||
|
||||
const (
|
||||
ModeModule SummaryMode = 1 << iota
|
||||
ModeBuild
|
||||
ModeCGO
|
||||
ModeVCS
|
||||
ModeMultiline
|
||||
Module SummaryMode = 1 << iota
|
||||
Build
|
||||
CGO
|
||||
VCS
|
||||
Multiline
|
||||
)
|
||||
|
||||
type params struct {
|
||||
|
@ -35,7 +34,7 @@ type params struct {
|
|||
//go:embed summary.tmpl
|
||||
var st string
|
||||
|
||||
func (b Binfo) Summarize(name string, version string, mode SummaryMode) (string, error) {
|
||||
func (b Binfo) Summarize(name string, version string, mode SummaryMode) string {
|
||||
wants := func(test SummaryMode) bool {
|
||||
return mode&test == test
|
||||
}
|
||||
|
@ -45,7 +44,7 @@ func (b Binfo) Summarize(name string, version string, mode SummaryMode) (string,
|
|||
sep string
|
||||
)
|
||||
|
||||
if wants(ModeMultiline) {
|
||||
if wants(Multiline) {
|
||||
brk = "\n"
|
||||
sep = "\n"
|
||||
} else {
|
||||
|
@ -55,29 +54,21 @@ func (b Binfo) Summarize(name string, version string, mode SummaryMode) (string,
|
|||
|
||||
t, err := template.New("").Parse(st)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot parse summary template: %w", err)
|
||||
return ""
|
||||
}
|
||||
sb := new(strings.Builder)
|
||||
err = t.Execute(sb, params{
|
||||
Module: wants(ModeModule),
|
||||
Build: wants(ModeBuild),
|
||||
CGO: wants(ModeCGO),
|
||||
VCS: wants(ModeVCS),
|
||||
Module: wants(Module),
|
||||
Build: wants(Build),
|
||||
CGO: wants(CGO),
|
||||
VCS: wants(VCS),
|
||||
Brk: brk,
|
||||
Sep: sep,
|
||||
I: b,
|
||||
})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot execute summary template: %w", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
return sb.String(), nil
|
||||
}
|
||||
|
||||
func (b Binfo) MustSummarize(name string, version string, mode SummaryMode) string {
|
||||
s, err := b.Summarize(name, version, mode)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return s
|
||||
return sb.String()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue