1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-26 04:22:05 +02:00
2017-05-11 00:05:51 -03:00

45 lines
966 B
Go

package build
import (
"bytes"
"text/template"
"github.com/goreleaser/goreleaser/context"
)
type nameData struct {
Os string
Arch string
Arm string
Version string
Tag string
Binary string
}
func nameFor(ctx *context.Context, target buildTarget) (string, error) {
var data = nameData{
Os: replace(ctx.Config.Archive.Replacements, target.goos),
Arch: replace(ctx.Config.Archive.Replacements, target.goarch),
Arm: replace(ctx.Config.Archive.Replacements, target.goarm),
Version: ctx.Version,
Tag: ctx.Git.CurrentTag,
Binary: ctx.Config.Build.Binary,
}
var out bytes.Buffer
t, err := template.New(data.Binary).Parse(ctx.Config.Archive.NameTemplate)
if err != nil {
return "", err
}
err = t.Execute(&out, data)
return out.String(), err
}
func replace(replacements map[string]string, original string) string {
result := replacements[original]
if result == "" {
return original
}
return result
}