Skip to content

Commit

Permalink
cmd/use: Ignore numTagsToDisplay with useVersionInDotFile flag
Browse files Browse the repository at this point in the history
Fixes #44
  • Loading branch information
jmooring authored Sep 25, 2023
1 parent ebe534d commit 5b58bf0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
19 changes: 19 additions & 0 deletions cmd/testscripts/use/use_use_dot_file_pass_2.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# User cache and config dirs (we use os.UserCacheDir and os.UserCongfigDir)
[darwin] env HOME=home
[darwin] mkdir "$HOME/Library/Caches"
[darwin] mkdir "$HOME/Library/Application Support"
[linux] env XDG_CACHE_HOME=cache
[linux] env XDG_CONFIG_HOME=config
[windows] env LocalAppData=cache
[windows] env AppData=config

# Test
exec hvm use --useVersionInDotFile
stdout 'Downloading v0\.54\.0\.\.\. done\.\n'
[darwin] exists 'home/Library/Caches/hvm/v0.54.0/hugo'
[linux] exists 'cache/hvm/v0.54.0/hugo'
[windows] exists 'cache\\hvm\\v0.54.0\\hugo.exe'

# Files
-- .hvm --
v0.54.0
37 changes: 19 additions & 18 deletions cmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,6 @@ func (r *repository) fetchTags() error {
if Config.SortAscending {
semver.Sort(tagNames)
}

n := Config.NumTagsToDisplay
if n < 0 {
n = 9999
}
if n <= len(tagNames) {
if Config.SortAscending {
tagNames = tagNames[len(tagNames)-n:]
} else {
tagNames = tagNames[:n]
}
}

r.tags = tagNames

return nil
Expand All @@ -263,7 +250,21 @@ func (r *repository) selectTag(a *asset, msg string) error {
// List tags.
fmt.Println()

for i, tag := range r.tags {
n := Config.NumTagsToDisplay
if n < 0 {
n = 9999
}

tags := r.tags
if n <= len(r.tags) {
if Config.SortAscending {
tags = tags[len(tags)-n:]
} else {
tags = tags[:n]
}
}

for i, tag := range tags {
exists, err := helpers.Exists(filepath.Join(App.CacheDirPath, tag))
if err != nil {
return err
Expand All @@ -277,7 +278,7 @@ func (r *repository) selectTag(a *asset, msg string) error {
if (i+1)%3 == 0 {
fmt.Print("\n")

} else if i == len(r.tags)-1 {
} else if i == len(tags)-1 {
fmt.Print("\n")
}
}
Expand All @@ -298,10 +299,10 @@ func (r *repository) selectTag(a *asset, msg string) error {
}

ri, err := strconv.Atoi(strings.TrimSpace(rs))
if err != nil || ri < 1 || ri > len(r.tags) {
fmt.Printf("Please enter a number between 1 and %d, or press Enter to cancel: ", len(r.tags))
if err != nil || ri < 1 || ri > len(tags) {
fmt.Printf("Please enter a number between 1 and %d, or press Enter to cancel: ", len(tags))
} else {
a.tag = r.tags[ri-1]
a.tag = tags[ri-1]
}
}

Expand Down

0 comments on commit 5b58bf0

Please sign in to comment.