mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-12-24 12:25:28 -07:00
Compare commits
9 Commits
90fccb06cb
...
a48e448526
Author | SHA1 | Date | |
---|---|---|---|
|
a48e448526 | ||
|
753c0b7265 | ||
|
54d15e3fa6 | ||
|
d5f021482d | ||
|
518a0fa442 | ||
|
36fd9f8a4b | ||
|
437453110c | ||
|
5c30032f44 | ||
|
5c69d8d852 |
1
.github/workflows/semantic-pr.yml
vendored
1
.github/workflows/semantic-pr.yml
vendored
@ -28,3 +28,4 @@ jobs:
|
|||||||
website
|
website
|
||||||
plugin
|
plugin
|
||||||
completions
|
completions
|
||||||
|
deps
|
||||||
|
@ -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
6
go.mod
@ -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
20
go.sum
@ -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=
|
||||||
|
@ -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
|
40
internal/completions/completions.go
Normal file
40
internal/completions/completions.go
Normal 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
|
||||||
|
}
|
30
internal/completions/completions_test.go
Normal file
30
internal/completions/completions_test.go
Normal 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())
|
||||||
|
})
|
||||||
|
}
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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"
|
||||||
)
|
)
|
||||||
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,8 +53,12 @@ version_command() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if ! (check_if_version_exists "$plugin_name" "$version"); then
|
if ! (check_if_version_exists "$plugin_name" "$version"); then
|
||||||
version_not_installed_text "$plugin_name" "$version" 1>&2
|
closest_version=$(try_get_closest_version "$plugin_name" "$version")
|
||||||
exit 1
|
if [[ ! $closest_version ]]; then
|
||||||
|
version_not_installed_text "$plugin_name" "$version" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
version="$closest_version"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
resolved_versions+=("$version")
|
resolved_versions+=("$version")
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 ]
|
||||||
|
Loading…
Reference in New Issue
Block a user