Skip to content

Commit

Permalink
list-remote: use utils.IsInstalledVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
ekalinin committed Jul 21, 2020
1 parent 9f0cf7a commit b8b7364
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cmd/listRemote.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"strconv"

"github.com/ekalinin/pbvm/utils"
"github.com/google/go-github/v32/github"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
Expand All @@ -28,13 +29,18 @@ var listRemoteCmd = &cobra.Command{
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Version", "Pre-release", "Date"})
table.SetHeader([]string{"Version", "Pre-release", "Date", "Installed"})

for _, r := range releases {
installed, _, err := utils.IsInstalledVersion(pbName, *r.TagName)
if err != nil {
panic(err)
}
table.Append([]string{
*r.TagName,
strconv.FormatBool(*r.Prerelease),
(*r.PublishedAt).Format("2006.01.02"),
strconv.FormatBool(installed),
})
}
table.SetBorder(false)
Expand Down
18 changes: 16 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ func DownloadVersion(app, version string, asset *github.ReleaseAsset) (bool, err
return false, err
}

versionDir, err := GetHomeVersionDir(app, version)
installed, versionDir, err := IsInstalledVersion(app, version)
if err != nil {
return false, err
}

if _, err := os.Stat(versionDir); os.IsNotExist(err) {
if !installed {
tmp, err := GetHomeTmpDir(app)
if err != nil {
return false, err
Expand All @@ -214,6 +214,20 @@ func DownloadVersion(app, version string, asset *github.ReleaseAsset) (bool, err
return false, nil
}

// IsInstalledVersion returns true (first result) if version is installed
func IsInstalledVersion(app, version string) (bool, string, error) {
versionDir, err := GetHomeVersionDir(app, version)
if err != nil {
return false, versionDir, err
}

if _, err := os.Stat(versionDir); os.IsNotExist(err) {
return false, versionDir, nil
}

return true, versionDir, nil
}

// ActivateVersion activates certain version
func ActivateVersion(app, version string) error {

Expand Down

0 comments on commit b8b7364

Please sign in to comment.