Skip to content

Commit

Permalink
cmd/use use latestTag field to fix when used with SortOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
irkode committed May 26, 2024
1 parent 95da294 commit f6a5094
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ you will be prompted to add it when installation is complete.`,
Run: func(cmd *cobra.Command, args []string) {
useLatest, err := cmd.Flags().GetBool("latest")
cobra.CheckErr(err)

err = install(useLatest)
cobra.CheckErr(err)
},
Expand Down
27 changes: 16 additions & 11 deletions cmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ tag to an .hvm file.`,
Run: func(cmd *cobra.Command, args []string) {
useVersionInDotFile, err := cmd.Flags().GetBool("useVersionInDotFile")
cobra.CheckErr(err)
err = use(useVersionInDotFile)

useLatest, err := cmd.Flags().GetBool("latest")
cobra.CheckErr(err)

err = use(useVersionInDotFile, useLatest)
cobra.CheckErr(err)
},
}

Expand All @@ -65,10 +67,11 @@ func init() {

// A repository is a GitHub repository.
type repository struct {
owner string // account owner of the GitHub repository
name string // name of the GitHub repository without the .git extension
tags []string // repository tags in semver ascending order
client *github.Client // a GitHub API client
owner string // account owner of the GitHub repository
name string // name of the GitHub repository without the .git extension
tags []string // repository tags in semver ascending order
latestTag string // only retrieve the latest tag
client *github.Client // a GitHub API client
}

// An asset is a GitHub asset for a given release, operating system, and architecture.
Expand Down Expand Up @@ -165,9 +168,10 @@ func newRepository() *repository {
}

r := repository{
client: client,
name: App.RepositoryName,
owner: App.RepositoryOwner,
client: client,
name: App.RepositoryName,
owner: App.RepositoryOwner,
latestTag: "",
}

err := r.fetchTags()
Expand Down Expand Up @@ -243,6 +247,8 @@ func (r *repository) fetchTags() error {
}
}

r.latestTag = tagNames[0]

if Config.SortAscending {
semver.Sort(tagNames)
}
Expand All @@ -253,11 +259,10 @@ func (r *repository) fetchTags() error {

// getLatestTag returns the most recent tag from repository.
func (r *repository) getLatestTag(a *asset) error {
if 1 > len(r.tags) {
if "" == r.latestTag {
return fmt.Errorf("no latest release found")
}
// relying on the sort order
a.tag = r.tags[0]
a.tag = r.latestTag
return nil
}

Expand Down

0 comments on commit f6a5094

Please sign in to comment.