Skip to content

Commit

Permalink
Split 'SetAsset()' into smaller methods
Browse files Browse the repository at this point in the history
  • Loading branch information
myhro committed Dec 29, 2021
1 parent 0fa1f7e commit 4a231ff
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 22 deletions.
50 changes: 50 additions & 0 deletions tools/asset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package tools

import (
"fmt"
"path"
"strings"
)

func (t *Tool) AssetBat() {
baseName := fmt.Sprintf("bat-%v-%v-%v", t.Version, t.Arch, t.OS)
t.Asset.Name = baseName + ".tar.gz"
t.Asset.WithinArchive = path.Join(baseName, t.Name)
}

func (t *Tool) AssetBottom() {
t.Asset.Name = fmt.Sprintf("bottom_%v-%v.tar.gz", t.Arch, t.OS)
}

func (t *Tool) AssetCloudflared() {
t.Asset.Name = fmt.Sprintf("cloudflared-%v-%v", t.OS, t.Arch)
t.Asset.IsBinary = true

if t.OS == "darwin" {
t.Asset.Name += ".tgz"
t.Asset.IsBinary = false
}
}

func (t *Tool) AssetDockerCompose() {
t.Asset.Name = fmt.Sprintf("docker-compose-%v-%v", t.OS, t.Arch)
t.Asset.Destination = path.Join("/usr/libexec/docker/cli-plugins/", t.Name)
t.Asset.IsBinary = true
}

func (t *Tool) AssetK9s() {
t.Asset.Name = fmt.Sprintf("k9s_%v_%v.tar.gz", t.OS, t.Arch)
}

func (t *Tool) AssetUPX() {
version := strings.TrimPrefix(t.Version, "v")
baseName := fmt.Sprintf("upx-%v-%v_%v", version, t.Arch, t.OS)
t.Asset.Name = baseName + ".tar.xz"
t.Asset.WithinArchive = path.Join(baseName, t.Name)
}

func (t *Tool) AssetXh() {
baseName := fmt.Sprintf("xh-%v-%v-%v", t.Version, t.Arch, t.OS)
t.Asset.Name = baseName + ".tar.gz"
t.Asset.WithinArchive = path.Join(baseName, t.Name)
}
29 changes: 7 additions & 22 deletions tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,34 +132,19 @@ func (t *Tool) SetAsset() error {

switch t.Name {
case Bat:
baseName := fmt.Sprintf("bat-%v-%v-%v", t.Version, t.Arch, t.OS)
t.Asset.Name = baseName + ".tar.gz"
t.Asset.WithinArchive = path.Join(baseName, t.Name)
t.AssetBat()
case Bottom:
t.Asset.Name = fmt.Sprintf("bottom_%v-%v.tar.gz", t.Arch, t.OS)
t.AssetBottom()
case Cloudflared:
t.Asset.Name = fmt.Sprintf("cloudflared-%v-%v", t.OS, t.Arch)
t.Asset.IsBinary = true

if t.OS == "darwin" {
t.Asset.Name += ".tgz"
t.Asset.IsBinary = false
}
t.AssetCloudflared()
case DockerCompose:
t.Asset.Name = fmt.Sprintf("docker-compose-%v-%v", t.OS, t.Arch)
t.Asset.Destination = path.Join("/usr/libexec/docker/cli-plugins/", t.Name)
t.Asset.IsBinary = true
t.AssetDockerCompose()
case K9s:
t.Asset.Name = fmt.Sprintf("k9s_%v_%v.tar.gz", t.OS, t.Arch)
t.AssetK9s()
case UPX:
version := strings.TrimPrefix(t.Version, "v")
baseName := fmt.Sprintf("upx-%v-%v_%v", version, t.Arch, t.OS)
t.Asset.Name = baseName + ".tar.xz"
t.Asset.WithinArchive = path.Join(baseName, t.Name)
t.AssetUPX()
case Xh:
baseName := fmt.Sprintf("xh-%v-%v-%v", t.Version, t.Arch, t.OS)
t.Asset.Name = baseName + ".tar.gz"
t.Asset.WithinArchive = path.Join(baseName, t.Name)
t.AssetXh()
}

if t.Asset.Name == "" {
Expand Down

0 comments on commit 4a231ff

Please sign in to comment.