fix
This commit is contained in:
parent
29bcdc1519
commit
6e37c7e91d
3 changed files with 162 additions and 151 deletions
80
summary.go
Normal file
80
summary.go
Normal file
|
@ -0,0 +1,80 @@
|
|||
package binfo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SummaryMode uint
|
||||
|
||||
const (
|
||||
ModeModule SummaryMode = 1 << iota
|
||||
ModeBuild
|
||||
ModeCGO
|
||||
ModeVCS
|
||||
ModeMultiline
|
||||
)
|
||||
|
||||
func (b Binfo) Summarize(name string, version string, mode SummaryMode) string {
|
||||
wants := func(test SummaryMode) bool {
|
||||
return mode&test == test
|
||||
}
|
||||
|
||||
var (
|
||||
brk string
|
||||
sep string
|
||||
)
|
||||
|
||||
if wants(ModeMultiline) {
|
||||
brk = "\n"
|
||||
sep = "\n"
|
||||
} else {
|
||||
brk = " "
|
||||
sep = ", "
|
||||
}
|
||||
|
||||
lines := make([]string, 4)
|
||||
|
||||
if wants(ModeModule) {
|
||||
lines = append(
|
||||
lines,
|
||||
fmt.Sprintf("module %s (%s) (sum %s)", b.Module.Path, b.Module.Version, b.Module.Sum),
|
||||
)
|
||||
}
|
||||
|
||||
if wants(ModeBuild) {
|
||||
lines = append(
|
||||
lines,
|
||||
fmt.Sprintf("built with %s (%s) (mode %s)", b.Build.Compiler, b.Build.GoVersion, b.Build.Mode),
|
||||
)
|
||||
}
|
||||
|
||||
if wants(ModeCGO) {
|
||||
if b.CGO.Enabled {
|
||||
lines = append(
|
||||
lines,
|
||||
fmt.Sprintf("with cgo (c %q) (cpp %q) (cxx %q) (ld %q)", b.CGO.Flags.C, b.CGO.Flags.CPP, b.CGO.Flags.CXX, b.CGO.Flags.LD),
|
||||
)
|
||||
} else {
|
||||
lines = append(
|
||||
lines,
|
||||
"without cgo",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if wants(ModeVCS) {
|
||||
lines = append(
|
||||
lines,
|
||||
fmt.Sprintf("via %s (rev %s) (at %s)", b.VCS.Name, b.VCS.Revision, b.VCS.Time.Format("2006-01-02 15:04:05")),
|
||||
)
|
||||
}
|
||||
|
||||
j := strings.Join(lines, sep)
|
||||
|
||||
if name == "" {
|
||||
return j
|
||||
} else {
|
||||
return fmt.Sprintf("%s %s:%s%s", name, version, brk, j)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue