Compare commits

...

9 Commits

Author SHA1 Message Date
Bruno Sales Cardoso
a48e448526
Merge 36fd9f8a4b into 753c0b7265 2024-12-19 16:49:38 +09:00
dependabot[bot]
753c0b7265
chore(deps): bump golang.org/x/crypto from 0.16.0 to 0.31.0 (#1813)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Trevor Brown <Stratus3D@users.noreply.github.com>
2024-12-18 20:19:16 -05:00
Trevor Brown
54d15e3fa6
chore: add deps scope to semantic-pr workflow (#1817) 2024-12-18 20:17:04 -05:00
Trevor Brown
d5f021482d Merge branch 'DeedleFake-completions-fs' 2024-12-18 20:03:24 -05:00
DeedleFake
518a0fa442 feat(golang-rewrite): refactor completion code and move all packages except cmd into internal
* Refactor and move `completion` package to `internal/completions`
* Move `cli` and `repotest` packages to `internal/cli`
* Use passed version information for `--version` flag
* Add simple test for completions package
2024-12-18 20:01:10 -05:00
Bruno Sales Cardoso
36fd9f8a4b
Merge branch 'master' into master 2024-10-23 18:34:45 +01:00
Bruno Sales Cardoso
437453110c
Merge branch 'master' into master 2024-08-30 18:24:09 +01:00
Bruno Sales Cardoso
5c30032f44
Update test/version_commands.bats 2024-07-22 09:10:09 +01:00
Bruno Cardoso
5c69d8d852 Allowing find the closest version if the exact version is not found 2024-07-20 11:06:57 +01:00
26 changed files with 147 additions and 67 deletions

View File

@ -28,3 +28,4 @@ jobs:
website website
plugin plugin
completions completions
deps

View File

@ -1,7 +1,7 @@
// Main entrypoint for the CLI app // Main entrypoint for the CLI app
package main package main
import "github.com/asdf-vm/asdf/cli" import "github.com/asdf-vm/asdf/internal/cli"
// Replaced with the real version during a typical build // Replaced with the real version during a typical build
var version = "v-dev" var version = "v-dev"

6
go.mod
View File

@ -10,7 +10,7 @@ require (
github.com/sethvargo/go-envconfig v1.0.0 github.com/sethvargo/go-envconfig v1.0.0
github.com/stretchr/testify v1.8.4 github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.27.1 github.com/urfave/cli/v2 v2.27.1
golang.org/x/sys v0.15.0 golang.org/x/sys v0.28.0
gopkg.in/ini.v1 v1.67.0 gopkg.in/ini.v1 v1.67.0
) )
@ -35,9 +35,9 @@ require (
github.com/skeema/knownhosts v1.2.1 // indirect github.com/skeema/knownhosts v1.2.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.16.0 // indirect golang.org/x/crypto v0.31.0 // indirect
golang.org/x/mod v0.12.0 // indirect golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.19.0 // indirect golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.3.0 // indirect golang.org/x/sync v0.3.0 // indirect
golang.org/x/tools v0.13.0 // indirect golang.org/x/tools v0.13.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect

20
go.sum
View File

@ -90,8 +90,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
@ -103,8 +103,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -123,15 +123,15 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@ -139,8 +139,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

View File

@ -2,7 +2,6 @@
package cli package cli
import ( import (
_ "embed"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -14,6 +13,7 @@ import (
"strings" "strings"
"text/tabwriter" "text/tabwriter"
"github.com/asdf-vm/asdf/internal/completions"
"github.com/asdf-vm/asdf/internal/config" "github.com/asdf-vm/asdf/internal/config"
"github.com/asdf-vm/asdf/internal/exec" "github.com/asdf-vm/asdf/internal/exec"
"github.com/asdf-vm/asdf/internal/execenv" "github.com/asdf-vm/asdf/internal/execenv"
@ -52,7 +52,7 @@ func Execute(version string) {
app := &cli.App{ app := &cli.App{
Name: "asdf", Name: "asdf",
Version: "0.1.0", Version: version,
// Not really sure what I should put here, but all the new Golang code will // Not really sure what I should put here, but all the new Golang code will
// likely be written by me. // likely be written by me.
Copyright: "(c) 2024 Trevor Brown", Copyright: "(c) 2024 Trevor Brown",
@ -315,45 +315,18 @@ func Execute(version string) {
} }
} }
//go:embed completions/asdf.bash
var bashCompletions string
//go:embed completions/asdf.zsh
var zshCompletions string
//go:embed completions/asdf.fish
var fishCompletions string
//go:embed completions/asdf.nu
var nuCompletions string
//go:embed completions/asdf.elv
var elvishCompletions string
func completionCommand(l *log.Logger, shell string) error { func completionCommand(l *log.Logger, shell string) error {
switch shell { file, ok := completions.Get(shell)
case "bash": if !ok {
fmt.Print(bashCompletions) l.Printf(`No completions available for shell with name %q
return nil Completions are available for: %v`, shell, strings.Join(completions.Names(), ", "))
case "zsh": return errors.New("bad shell name")
fmt.Print(zshCompletions)
return nil
case "fish":
fmt.Print(fishCompletions)
return nil
case "nushell":
fmt.Print(nuCompletions)
return nil
case "elvish":
fmt.Print(elvishCompletions)
return nil
default:
fmtString := `No completions available for shell with name %s
Completions are available for: bash, zsh, fish, nushell, elvish`
msg := fmt.Sprintf(fmtString, shell)
l.Print(msg)
return errors.New(msg)
} }
defer file.Close()
io.Copy(os.Stdout, file)
return nil
} }
// This function is a whole mess and needs to be refactored // This function is a whole mess and needs to be refactored

View File

@ -0,0 +1,40 @@
// Package completions handles shell completion files.
//
// To add completion support for a shell, simply add a file named
// "asdf.<shell>" to this directory, replacing "<shell>" with the name
// of the shell.
package completions
import (
"embed"
"errors"
"io/fs"
"slices"
"strings"
)
//go:embed asdf.*
var completions embed.FS
// Get returns a file containing completion code for the given shell if it is
// found.
func Get(name string) (fs.File, bool) {
file, err := completions.Open("asdf." + name)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return nil, false
}
panic(err) // This should never happen.
}
return file, true
}
// Names returns a slice of shell names that completion is available for.
func Names() []string {
files, _ := fs.Glob(completions, "asdf.*")
for i, file := range files {
files[i] = strings.TrimPrefix(file, "asdf.")
}
slices.Sort(files)
return files
}

View File

@ -0,0 +1,30 @@
package completions
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGet(t *testing.T) {
t.Run("returns file when completion file found with matching name", func(t *testing.T) {
file, found := Get("bash")
info, err := file.Stat()
assert.Nil(t, err)
assert.Equal(t, "asdf.bash", info.Name())
assert.True(t, found)
})
t.Run("returns false when completion file not found", func(t *testing.T) {
_, found := Get("non-existent")
assert.False(t, found)
})
}
func TestNames(t *testing.T) {
t.Run("returns slice of shell names for which completion is available", func(t *testing.T) {
assert.Equal(t, []string{"bash", "elvish", "fish", "nushell", "zsh"}, Names())
})
}

View File

@ -5,7 +5,7 @@ import (
"github.com/asdf-vm/asdf/internal/config" "github.com/asdf-vm/asdf/internal/config"
"github.com/asdf-vm/asdf/internal/plugins" "github.com/asdf-vm/asdf/internal/plugins"
"github.com/asdf-vm/asdf/repotest" "github.com/asdf-vm/asdf/internal/repotest"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -5,7 +5,7 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/asdf-vm/asdf/repotest" "github.com/asdf-vm/asdf/internal/repotest"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"

View File

@ -9,7 +9,7 @@ import (
"github.com/asdf-vm/asdf/internal/config" "github.com/asdf-vm/asdf/internal/config"
"github.com/asdf-vm/asdf/internal/plugins" "github.com/asdf-vm/asdf/internal/plugins"
"github.com/asdf-vm/asdf/repotest" "github.com/asdf-vm/asdf/internal/repotest"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -8,8 +8,8 @@ import (
"github.com/asdf-vm/asdf/internal/config" "github.com/asdf-vm/asdf/internal/config"
"github.com/asdf-vm/asdf/internal/installtest" "github.com/asdf-vm/asdf/internal/installtest"
"github.com/asdf-vm/asdf/internal/plugins" "github.com/asdf-vm/asdf/internal/plugins"
"github.com/asdf-vm/asdf/internal/repotest"
"github.com/asdf-vm/asdf/internal/toolversions" "github.com/asdf-vm/asdf/internal/toolversions"
"github.com/asdf-vm/asdf/repotest"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -9,7 +9,7 @@ import (
"time" "time"
"github.com/asdf-vm/asdf/internal/git" "github.com/asdf-vm/asdf/internal/git"
"github.com/asdf-vm/asdf/repotest" "github.com/asdf-vm/asdf/internal/repotest"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -9,7 +9,7 @@ import (
"github.com/asdf-vm/asdf/internal/config" "github.com/asdf-vm/asdf/internal/config"
"github.com/asdf-vm/asdf/internal/data" "github.com/asdf-vm/asdf/internal/data"
"github.com/asdf-vm/asdf/repotest" "github.com/asdf-vm/asdf/internal/repotest"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -8,7 +8,7 @@ import (
"github.com/asdf-vm/asdf/internal/config" "github.com/asdf-vm/asdf/internal/config"
"github.com/asdf-vm/asdf/internal/plugins" "github.com/asdf-vm/asdf/internal/plugins"
"github.com/asdf-vm/asdf/repotest" "github.com/asdf-vm/asdf/internal/repotest"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -12,8 +12,8 @@ import (
"github.com/asdf-vm/asdf/internal/installs" "github.com/asdf-vm/asdf/internal/installs"
"github.com/asdf-vm/asdf/internal/installtest" "github.com/asdf-vm/asdf/internal/installtest"
"github.com/asdf-vm/asdf/internal/plugins" "github.com/asdf-vm/asdf/internal/plugins"
"github.com/asdf-vm/asdf/internal/repotest"
"github.com/asdf-vm/asdf/internal/toolversions" "github.com/asdf-vm/asdf/internal/toolversions"
"github.com/asdf-vm/asdf/repotest"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )

View File

@ -9,8 +9,8 @@ import (
"github.com/asdf-vm/asdf/internal/config" "github.com/asdf-vm/asdf/internal/config"
"github.com/asdf-vm/asdf/internal/plugins" "github.com/asdf-vm/asdf/internal/plugins"
"github.com/asdf-vm/asdf/internal/repotest"
"github.com/asdf-vm/asdf/internal/toolversions" "github.com/asdf-vm/asdf/internal/toolversions"
"github.com/asdf-vm/asdf/repotest"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@ -53,9 +53,13 @@ version_command() {
fi fi
if ! (check_if_version_exists "$plugin_name" "$version"); then if ! (check_if_version_exists "$plugin_name" "$version"); then
closest_version=$(try_get_closest_version "$plugin_name" "$version")
if [[ ! $closest_version ]]; then
version_not_installed_text "$plugin_name" "$version" 1>&2 version_not_installed_text "$plugin_name" "$version" 1>&2
exit 1 exit 1
fi fi
version="$closest_version"
fi
resolved_versions+=("$version") resolved_versions+=("$version")
done done

View File

@ -137,6 +137,26 @@ check_if_version_exists() {
fi fi
} }
try_get_closest_version() {
local plugin_name=$1
local partial_version=$2
local versions
versions=$(list_installed_versions "$plugin_name")
if [ -n "${versions}" ]; then
for version in $versions; do
if [[ $version == $partial_version* ]]; then
matched_versions+=("$version")
fi
done
fi
if [ ${#matched_versions[@]} -eq 1 ]; then
printf "%s" "${matched_versions[0]}"
fi
}
version_not_installed_text() { version_not_installed_text() {
local plugin_name=$1 local plugin_name=$1
local version=$2 local version=$2

View File

@ -31,7 +31,7 @@ run_shfmt_stylecheck() {
print.info "Checking .bash with shfmt" print.info "Checking .bash with shfmt"
shfmt --language-dialect bash --indent 2 "${shfmt_flag}" \ shfmt --language-dialect bash --indent 2 "${shfmt_flag}" \
cli/completions/*.bash \ internal/completions/*.bash \
bin/asdf \ bin/asdf \
bin/private/asdf-exec \ bin/private/asdf-exec \
lib/utils.bash \ lib/utils.bash \
@ -55,7 +55,7 @@ run_shellcheck_linter() {
print.info "Checking .bash files with Shellcheck" print.info "Checking .bash files with Shellcheck"
shellcheck --shell bash --external-sources \ shellcheck --shell bash --external-sources \
cli/completions/*.bash \ internal/completions/*.bash \
bin/asdf \ bin/asdf \
bin/private/asdf-exec \ bin/private/asdf-exec \
lib/utils.bash \ lib/utils.bash \
@ -123,7 +123,7 @@ run_fish_linter() {
printf "%s\n" "[WARNING] fish_indent not found. Skipping .fish files." printf "%s\n" "[WARNING] fish_indent not found. Skipping .fish files."
else else
print.info "Checking .fish files with fish_indent" print.info "Checking .fish files with fish_indent"
fish_indent "${flag}" ./cli/completions/asdf.fish fish_indent "${flag}" ./internal/completions/asdf.fish
fi fi
} }

View File

@ -204,6 +204,18 @@ teardown() {
[ "$(cat "$HOME/.tool-versions")" = "dummy 1.1.0" ] [ "$(cat "$HOME/.tool-versions")" = "dummy 1.1.0" ]
} }
@test "global should create a global .tool-versions file when a close version is found" {
run asdf global "dummy" "1.1"
[ "$status" -eq 0 ]
[ "$(cat "$HOME/.tool-versions")" = "dummy 1.1.0" ]
}
@test "global should emit an error when a single close plugin version is not found" {
run asdf global "dummy" "1"
[ "$status" -eq 1 ]
[ "$output" = "version 1 is not installed for dummy" ]
}
@test "[global - dummy_plugin] with latest should use the latest installed version" { @test "[global - dummy_plugin] with latest should use the latest installed version" {
run asdf global "dummy" "latest" run asdf global "dummy" "latest"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]