1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-26 04:22:05 +02:00
Carlos Alexandro Becker d286dffd52
docs
2017-07-01 12:15:45 -03:00

48 lines
1.1 KiB
Go

// Package name provides name template logic for the final archive, formulae,
// etc.
package name
import (
"bytes"
"text/template"
"github.com/goreleaser/goreleaser/context"
)
type nameData struct {
Os string
Arch string
Arm string
Version string
Tag string
Binary string
}
// For returns the name for the given context, goos, goarch and goarm.
func For(ctx *context.Context, goos, goarch, goarm string) (string, error) {
var data = nameData{
Os: replace(ctx.Config.Archive.Replacements, goos),
Arch: replace(ctx.Config.Archive.Replacements, goarch),
Arm: replace(ctx.Config.Archive.Replacements, goarm),
Version: ctx.Version,
Tag: ctx.Git.CurrentTag,
Binary: ctx.Config.Name,
}
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
}