mirror of
https://github.com/jimeh/build-emacs-for-macos.git
synced 2026-02-19 06:06:40 +00:00
feat(cask): make cask template helpers more flexible
Helpers available in cask templates can now accept one or more strings as input, and first asset filename that matches all given strings is returned.
This commit is contained in:
@@ -11,9 +11,11 @@ type ReleaseInfo struct {
|
||||
Assets map[string]*ReleaseAsset
|
||||
}
|
||||
|
||||
func (s *ReleaseInfo) Asset(nameMatch string) *ReleaseAsset {
|
||||
if a, ok := s.Assets[nameMatch]; ok {
|
||||
return a
|
||||
func (s *ReleaseInfo) Asset(needles ...string) *ReleaseAsset {
|
||||
if len(needles) == 1 {
|
||||
if a, ok := s.Assets[needles[0]]; ok {
|
||||
return a
|
||||
}
|
||||
}
|
||||
|
||||
// Dirty and inefficient way to ensure assets are searched in a predictable
|
||||
@@ -27,16 +29,20 @@ func (s *ReleaseInfo) Asset(nameMatch string) *ReleaseAsset {
|
||||
})
|
||||
|
||||
for _, a := range assets {
|
||||
if strings.Contains(a.Filename, nameMatch) {
|
||||
return a
|
||||
for _, needle := range needles {
|
||||
if !strings.Contains(a.Filename, needle) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ReleaseInfo) DownloadURL(nameMatch string) string {
|
||||
a := s.Asset(nameMatch)
|
||||
func (s *ReleaseInfo) DownloadURL(needles ...string) string {
|
||||
a := s.Asset(needles...)
|
||||
if a == nil {
|
||||
return ""
|
||||
}
|
||||
@@ -44,8 +50,8 @@ func (s *ReleaseInfo) DownloadURL(nameMatch string) string {
|
||||
return a.DownloadURL
|
||||
}
|
||||
|
||||
func (s *ReleaseInfo) SHA256(nameMatch string) string {
|
||||
a := s.Asset(nameMatch)
|
||||
func (s *ReleaseInfo) SHA256(needles ...string) string {
|
||||
a := s.Asset(needles...)
|
||||
if a == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user