diff --git a/cmd/testscripts/use/use_use_dot_file_pass.txtar b/cmd/testscripts/use/use_use_dot_file_pass_1.txtar similarity index 100% rename from cmd/testscripts/use/use_use_dot_file_pass.txtar rename to cmd/testscripts/use/use_use_dot_file_pass_1.txtar diff --git a/cmd/testscripts/use/use_use_dot_file_pass_2.txtar b/cmd/testscripts/use/use_use_dot_file_pass_2.txtar new file mode 100644 index 0000000..ce24066 --- /dev/null +++ b/cmd/testscripts/use/use_use_dot_file_pass_2.txtar @@ -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 diff --git a/cmd/use.go b/cmd/use.go index 32ab7c2..788c4c7 100644 --- a/cmd/use.go +++ b/cmd/use.go @@ -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 @@ -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 @@ -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") } } @@ -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] } }