Skip to content

Commit

Permalink
install: use utils.FilterAsset
Browse files Browse the repository at this point in the history
ekalinin committed Jul 20, 2020
1 parent 6a391f1 commit 9f0cf7a
Showing 2 changed files with 17 additions and 16 deletions.
21 changes: 5 additions & 16 deletions cmd/install.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package cmd

import (
"context"
"runtime"

"github.com/ekalinin/pbvm/utils"
"github.com/google/go-github/v32/github"
@@ -32,31 +31,21 @@ To get all available versions use "list-remote" command.`,
if err != nil {
panic(err)
}
d(" ... found: ", release.URL)

d("Searching asset: ...")
arch := utils.GetArch()
var asset *github.ReleaseAsset
for _, a := range release.Assets {
if !utils.IsSuitableAsset(*a.Name, arch, runtime.GOOS) {
d(" ... skip:", *a.Name)
continue
}
d(" ... found:", *a.BrowserDownloadURL)
asset = a
break
}
d(" ... found:", *release.HTMLURL)

d("Searching asset in release: ...")
asset := utils.FilterAsset(release)
if asset == nil {
panic("Could not found asset.")
}
d(" ... found:", *asset.BrowserDownloadURL)

d("Downloading version: ", tag, " ...")
downloaded, err := utils.DownloadVersion(pbName, tag, asset)
if err != nil {
panic(err)
}
d(" ... is realy downloaded: ", downloaded)
d(" ... is realy downloaded:", downloaded)

d("Activating version: ", tag, " ...")
if err := utils.ActivateVersion(pbName, tag); err != nil {
12 changes: 12 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -240,3 +240,15 @@ func ActivateVersion(app, version string) error {
}
return nil
}

// FilterAsset finds an asset which is need to be downloaded
func FilterAsset(release *github.RepositoryRelease) *github.ReleaseAsset {
arch := GetArch()
for _, a := range release.Assets {
if !IsSuitableAsset(*a.Name, arch, runtime.GOOS) {
continue
}
return a
}
return nil
}

0 comments on commit 9f0cf7a

Please sign in to comment.