Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/asdf-vm/asdf-core-go into…
Browse files Browse the repository at this point in the history
… rename-module-and-use-cmd-dir
  • Loading branch information
DeedleFake committed Dec 15, 2024
2 parents 70c2b52 + 5349a06 commit b80ca3e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.5'
go-version: '1.23.4'
- name: Install dependencies
run: go get .
run: go get ./...
- name: Install gofumpt for formatting
run: go install mvdan.cc/gofumpt@latest
- name: Run 'gofumpt'
Expand All @@ -42,7 +42,7 @@ jobs:
- name: Run 'revive'
run: revive -set_exit_status ./...
- name: Vet
run: go vet
run: go vet ./...
- name: Install staticcheck for linting
run: go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Lint
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "1.21.5"
goversion: "1.23.4"
binary_name: "asdf"
project_path: ./cmd/asdf
release_tag: ${{ needs.generate-release-tag.outputs.tag }}
release_name: ${{ needs.generate-release-tag.outputs.tag }}
ldflags: -s -X main.version=${{ steps.asdf-version.outputs.version }}
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.5'
go-version: '1.23.4'
- run: scripts/install_dependencies.bash
- name: Install dependencies
run: go get .
run: go get ./...
- name: Run Go tests
run: go test -coverprofile=/tmp/coverage.out -bench= -race ./...

Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
golang 1.21.5
golang 1.23.4
bats 1.8.2
shellcheck 0.9.0
shfmt 3.6.0
43 changes: 37 additions & 6 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ func currentCommand(logger *log.Logger, tool string) error {

// show single tool
plugin := plugins.New(conf, tool)

err = plugin.Exists()
_, ok := err.(plugins.PluginMissing)
pluginExists := !ok
Expand Down Expand Up @@ -841,7 +840,7 @@ func pluginUpdateCommand(cCtx *cli.Context, logger *log.Logger, pluginName, ref
return err
}

func pluginTestCommand(l *log.Logger, args []string, _, _ string) {
func pluginTestCommand(l *log.Logger, args []string, toolVersion, _ string) {
conf, err := config.LoadConfig()
if err != nil {
l.Printf("error loading config: %s", err)
Expand Down Expand Up @@ -922,9 +921,21 @@ func pluginTestCommand(l *log.Logger, args []string, _, _ string) {
failTest(l, "Unable to list available versions")
}

if len(strings.Split(output.String(), " ")) < 1 {
allVersions := strings.Fields(output.String())
if len(allVersions) < 1 {
failTest(l, "list-all did not return any version")
}

// grab first version returned by list-all callback if no version provided as
// a CLI argument
if toolVersion == "" {
toolVersion = allVersions[0]
}

err = versions.InstallOneVersion(conf, plugin, toolVersion, false, os.Stdout, os.Stderr)
if err != nil {
failTest(l, "install exited with an error")
}
}

func failTest(logger *log.Logger, msg string) {
Expand Down Expand Up @@ -1079,11 +1090,16 @@ func listAllCommand(logger *log.Logger, conf config.Config, toolName, filter str
return nil
}

plugin := plugins.New(conf, toolName)
plugin, err := loadPlugin(logger, conf, toolName)
if err != nil {
os.Exit(1)
return err
}

var stdout strings.Builder
var stderr strings.Builder

err := plugin.RunCallback("list-all", []string{}, map[string]string{}, &stdout, &stderr)
err = plugin.RunCallback("list-all", []string{}, map[string]string{}, &stdout, &stderr)
if err != nil {
fmt.Printf("Plugin %s's list-all callback script failed with output:\n", plugin.Name)
// Print to stderr
Expand Down Expand Up @@ -1131,7 +1147,11 @@ func listLocalCommand(logger *log.Logger, conf config.Config, pluginName, filter
}

if pluginName != "" {
plugin := plugins.New(conf, pluginName)
plugin, err := loadPlugin(logger, conf, pluginName)
if err != nil {
os.Exit(1)
return err
}
versions, _ := installs.Installed(conf, plugin)

if filter != "" {
Expand Down Expand Up @@ -1372,6 +1392,17 @@ func whereCommand(logger *log.Logger, tool, versionStr string) error {
return nil
}

func loadPlugin(logger *log.Logger, conf config.Config, pluginName string) (plugins.Plugin, error) {
plugin := plugins.New(conf, pluginName)
err := plugin.Exists()
if err != nil {
logger.Printf("No such plugin: %s", pluginName)
return plugin, err
}

return plugin, err
}

func reshimToolVersion(conf config.Config, tool, versionStr string, out io.Writer, errOut io.Writer) error {
version := toolversions.Parse(versionStr)
return shims.GenerateForVersion(conf, plugins.New(conf, tool), version, out, errOut)
Expand Down
2 changes: 1 addition & 1 deletion cmd/asdf/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestBatsTests(t *testing.T) {
func runBatsFile(t *testing.T, dir, filename string) {
t.Helper()

cmd := exec.Command("bats", "--verbose-run", fmt.Sprintf("test/%s", filename))
cmd := exec.Command("bats", "--verbose-run", fmt.Sprintf("../../test/%s", filename))

// Capture stdout and stderr
var stdout strings.Builder
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/asdf-vm/asdf

go 1.21.5
go 1.23.4

require (
github.com/go-git/go-git/v5 v5.11.0
Expand Down
3 changes: 3 additions & 0 deletions internal/versions/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/asdf-vm/asdf/internal/config"
"github.com/asdf-vm/asdf/internal/execenv"
"github.com/asdf-vm/asdf/internal/hook"
"github.com/asdf-vm/asdf/internal/installs"
"github.com/asdf-vm/asdf/internal/plugins"
Expand Down Expand Up @@ -153,6 +154,8 @@ func InstallOneVersion(conf config.Config, plugin plugins.Plugin, versionStr str
"ASDF_CONCURRENCY": asdfConcurrency(conf),
}

env = execenv.MergeEnv(execenv.SliceToMap(os.Environ()), env)

err = os.MkdirAll(downloadDir, 0o777)
if err != nil {
return fmt.Errorf("unable to create download dir: %w", err)
Expand Down

0 comments on commit b80ca3e

Please sign in to comment.