From 5f79f884dc079192e5c2aff0bed6f41d3bf085de Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Fri, 29 Nov 2024 15:52:53 -0500 Subject: [PATCH 1/6] all: rename module to `github.com/asdf-vm/asdf-core-go` --- cmd/cmd.go | 25 ++++++++++++------------ go.mod | 2 +- internal/execenv/execenv.go | 4 ++-- internal/execenv/execenv_test.go | 7 +++---- internal/git/git_test.go | 3 +-- internal/help/help.go | 6 +++--- internal/help/help_test.go | 7 +++---- internal/hook/hook.go | 4 ++-- internal/hook/hook_test.go | 3 +-- internal/info/info.go | 6 +++--- internal/info/info_test.go | 3 +-- internal/installs/installs.go | 8 ++++---- internal/installs/installs_test.go | 11 +++++------ internal/installtest/installtest.go | 4 ++-- internal/pluginindex/pluginindex.go | 3 +-- internal/pluginindex/pluginindex_test.go | 5 ++--- internal/plugins/plugins.go | 12 ++++++------ internal/plugins/plugins_test.go | 7 +++---- internal/resolve/resolve.go | 6 +++--- internal/resolve/resolve_test.go | 7 +++---- internal/shims/shims.go | 15 +++++++------- internal/shims/shims_test.go | 13 ++++++------ internal/versions/versions.go | 14 ++++++------- internal/versions/versions_test.go | 7 +++---- main.go | 4 +--- 25 files changed, 85 insertions(+), 101 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 5dd036c5..4719eae9 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -12,19 +12,18 @@ import ( "strings" "text/tabwriter" - "asdf/internal/config" - "asdf/internal/exec" - "asdf/internal/execenv" - "asdf/internal/execute" - "asdf/internal/help" - "asdf/internal/info" - "asdf/internal/installs" - "asdf/internal/plugins" - "asdf/internal/resolve" - "asdf/internal/shims" - "asdf/internal/toolversions" - "asdf/internal/versions" - + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/exec" + "github.com/asdf-vm/asdf-core-go/internal/execenv" + "github.com/asdf-vm/asdf-core-go/internal/execute" + "github.com/asdf-vm/asdf-core-go/internal/help" + "github.com/asdf-vm/asdf-core-go/internal/info" + "github.com/asdf-vm/asdf-core-go/internal/installs" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/internal/resolve" + "github.com/asdf-vm/asdf-core-go/internal/shims" + "github.com/asdf-vm/asdf-core-go/internal/toolversions" + "github.com/asdf-vm/asdf-core-go/internal/versions" "github.com/urfave/cli/v2" ) diff --git a/go.mod b/go.mod index 56b60633..a3dd3143 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module asdf +module github.com/asdf-vm/asdf-core-go go 1.21.5 diff --git a/internal/execenv/execenv.go b/internal/execenv/execenv.go index 28015895..85f45a50 100644 --- a/internal/execenv/execenv.go +++ b/internal/execenv/execenv.go @@ -7,8 +7,8 @@ import ( "os" "strings" - "asdf/internal/execute" - "asdf/internal/plugins" + "github.com/asdf-vm/asdf-core-go/internal/execute" + "github.com/asdf-vm/asdf-core-go/internal/plugins" ) const execEnvCallbackName = "exec-env" diff --git a/internal/execenv/execenv_test.go b/internal/execenv/execenv_test.go index efda54aa..9bfee092 100644 --- a/internal/execenv/execenv_test.go +++ b/internal/execenv/execenv_test.go @@ -3,10 +3,9 @@ package execenv import ( "testing" - "asdf/internal/config" - "asdf/internal/plugins" - "asdf/repotest" - + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/repotest" "github.com/stretchr/testify/assert" ) diff --git a/internal/git/git_test.go b/internal/git/git_test.go index dfd4b945..e049d09c 100644 --- a/internal/git/git_test.go +++ b/internal/git/git_test.go @@ -5,8 +5,7 @@ import ( "path/filepath" "testing" - "asdf/repotest" - + "github.com/asdf-vm/asdf-core-go/repotest" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/stretchr/testify/assert" diff --git a/internal/help/help.go b/internal/help/help.go index 3fc718f3..981bbd56 100644 --- a/internal/help/help.go +++ b/internal/help/help.go @@ -8,9 +8,9 @@ import ( "io" "os" - "asdf/internal/config" - "asdf/internal/plugins" - "asdf/internal/toolversions" + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/internal/toolversions" ) //go:embed help.txt diff --git a/internal/help/help_test.go b/internal/help/help_test.go index 735aec0f..94c58226 100644 --- a/internal/help/help_test.go +++ b/internal/help/help_test.go @@ -6,10 +6,9 @@ import ( "strings" "testing" - "asdf/internal/config" - "asdf/internal/plugins" - "asdf/repotest" - + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/repotest" "github.com/stretchr/testify/assert" ) diff --git a/internal/hook/hook.go b/internal/hook/hook.go index ff7b2e19..18302cb6 100644 --- a/internal/hook/hook.go +++ b/internal/hook/hook.go @@ -6,8 +6,8 @@ import ( "io" "os" - "asdf/internal/config" - "asdf/internal/execute" + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/execute" ) // Run gets a hook command from config and runs it with the provided arguments. diff --git a/internal/hook/hook_test.go b/internal/hook/hook_test.go index e1e93ebd..d80ec8c3 100644 --- a/internal/hook/hook_test.go +++ b/internal/hook/hook_test.go @@ -4,8 +4,7 @@ import ( "os/exec" "testing" - "asdf/internal/config" - + "github.com/asdf-vm/asdf-core-go/internal/config" "github.com/stretchr/testify/assert" ) diff --git a/internal/info/info.go b/internal/info/info.go index bc1b2e21..cdf6ebc0 100644 --- a/internal/info/info.go +++ b/internal/info/info.go @@ -7,9 +7,9 @@ import ( "os" "text/tabwriter" - "asdf/internal/config" - "asdf/internal/execute" - "asdf/internal/plugins" + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/execute" + "github.com/asdf-vm/asdf-core-go/internal/plugins" ) // Print info output to STDOUT diff --git a/internal/info/info_test.go b/internal/info/info_test.go index dc915830..a25b0a10 100644 --- a/internal/info/info_test.go +++ b/internal/info/info_test.go @@ -6,8 +6,7 @@ import ( "strings" "testing" - "asdf/internal/config" - + "github.com/asdf-vm/asdf-core-go/internal/config" "github.com/stretchr/testify/assert" ) diff --git a/internal/installs/installs.go b/internal/installs/installs.go index c0604614..b0c1e848 100644 --- a/internal/installs/installs.go +++ b/internal/installs/installs.go @@ -8,10 +8,10 @@ import ( "os" "path/filepath" - "asdf/internal/config" - "asdf/internal/data" - "asdf/internal/plugins" - "asdf/internal/toolversions" + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/data" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/internal/toolversions" ) // Installed returns a slice of all installed versions for a given plugin diff --git a/internal/installs/installs_test.go b/internal/installs/installs_test.go index b41883f1..dded2eaf 100644 --- a/internal/installs/installs_test.go +++ b/internal/installs/installs_test.go @@ -5,12 +5,11 @@ import ( "path/filepath" "testing" - "asdf/internal/config" - "asdf/internal/installtest" - "asdf/internal/plugins" - "asdf/internal/toolversions" - "asdf/repotest" - + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/installtest" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/internal/toolversions" + "github.com/asdf-vm/asdf-core-go/repotest" "github.com/stretchr/testify/assert" ) diff --git a/internal/installtest/installtest.go b/internal/installtest/installtest.go index e1e64c19..4e903786 100644 --- a/internal/installtest/installtest.go +++ b/internal/installtest/installtest.go @@ -9,8 +9,8 @@ import ( "path/filepath" "strings" - "asdf/internal/config" - "asdf/internal/plugins" + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/plugins" ) const ( diff --git a/internal/pluginindex/pluginindex.go b/internal/pluginindex/pluginindex.go index d826bf9f..0285b0f7 100644 --- a/internal/pluginindex/pluginindex.go +++ b/internal/pluginindex/pluginindex.go @@ -8,8 +8,7 @@ import ( "path/filepath" "time" - "asdf/internal/git" - + "github.com/asdf-vm/asdf-core-go/internal/git" "gopkg.in/ini.v1" ) diff --git a/internal/pluginindex/pluginindex_test.go b/internal/pluginindex/pluginindex_test.go index 5b4d45e6..1c8a5026 100644 --- a/internal/pluginindex/pluginindex_test.go +++ b/internal/pluginindex/pluginindex_test.go @@ -8,9 +8,8 @@ import ( "testing" "time" - "asdf/internal/git" - "asdf/repotest" - + "github.com/asdf-vm/asdf-core-go/internal/git" + "github.com/asdf-vm/asdf-core-go/repotest" "github.com/stretchr/testify/assert" ) diff --git a/internal/plugins/plugins.go b/internal/plugins/plugins.go index 12ab3a97..3b19df60 100644 --- a/internal/plugins/plugins.go +++ b/internal/plugins/plugins.go @@ -11,12 +11,12 @@ import ( "regexp" "strings" - "asdf/internal/config" - "asdf/internal/data" - "asdf/internal/execute" - "asdf/internal/git" - "asdf/internal/hook" - "asdf/internal/pluginindex" + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/data" + "github.com/asdf-vm/asdf-core-go/internal/execute" + "github.com/asdf-vm/asdf-core-go/internal/git" + "github.com/asdf-vm/asdf-core-go/internal/hook" + "github.com/asdf-vm/asdf-core-go/internal/pluginindex" ) // NewPluginAlreadyExists generates a new PluginAlreadyExists error instance for diff --git a/internal/plugins/plugins_test.go b/internal/plugins/plugins_test.go index 98c5622e..380074b3 100644 --- a/internal/plugins/plugins_test.go +++ b/internal/plugins/plugins_test.go @@ -6,10 +6,9 @@ import ( "strings" "testing" - "asdf/internal/config" - "asdf/internal/data" - "asdf/repotest" - + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/data" + "github.com/asdf-vm/asdf-core-go/repotest" "github.com/stretchr/testify/assert" ) diff --git a/internal/resolve/resolve.go b/internal/resolve/resolve.go index e76c55a9..20044957 100644 --- a/internal/resolve/resolve.go +++ b/internal/resolve/resolve.go @@ -9,9 +9,9 @@ import ( "path" "strings" - "asdf/internal/config" - "asdf/internal/plugins" - "asdf/internal/toolversions" + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/internal/toolversions" ) // ToolVersions represents a tool along with versions specified for it diff --git a/internal/resolve/resolve_test.go b/internal/resolve/resolve_test.go index fe3159b6..4730f58c 100644 --- a/internal/resolve/resolve_test.go +++ b/internal/resolve/resolve_test.go @@ -6,10 +6,9 @@ import ( "path/filepath" "testing" - "asdf/internal/config" - "asdf/internal/plugins" - "asdf/repotest" - + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/repotest" "github.com/stretchr/testify/assert" ) diff --git a/internal/shims/shims.go b/internal/shims/shims.go index 2ec80745..b70e08ac 100644 --- a/internal/shims/shims.go +++ b/internal/shims/shims.go @@ -11,14 +11,13 @@ import ( "slices" "strings" - "asdf/internal/config" - "asdf/internal/hook" - "asdf/internal/installs" - "asdf/internal/paths" - "asdf/internal/plugins" - "asdf/internal/resolve" - "asdf/internal/toolversions" - + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/hook" + "github.com/asdf-vm/asdf-core-go/internal/installs" + "github.com/asdf-vm/asdf-core-go/internal/paths" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/internal/resolve" + "github.com/asdf-vm/asdf-core-go/internal/toolversions" "golang.org/x/sys/unix" ) diff --git a/internal/shims/shims_test.go b/internal/shims/shims_test.go index ed5afbc9..50e29f7f 100644 --- a/internal/shims/shims_test.go +++ b/internal/shims/shims_test.go @@ -8,13 +8,12 @@ import ( "strings" "testing" - "asdf/internal/config" - "asdf/internal/installs" - "asdf/internal/installtest" - "asdf/internal/plugins" - "asdf/internal/toolversions" - "asdf/repotest" - + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/installs" + "github.com/asdf-vm/asdf-core-go/internal/installtest" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/internal/toolversions" + "github.com/asdf-vm/asdf-core-go/repotest" "github.com/stretchr/testify/assert" "golang.org/x/sys/unix" ) diff --git a/internal/versions/versions.go b/internal/versions/versions.go index 7e589ced..0805ced0 100644 --- a/internal/versions/versions.go +++ b/internal/versions/versions.go @@ -10,13 +10,13 @@ import ( "regexp" "strings" - "asdf/internal/config" - "asdf/internal/hook" - "asdf/internal/installs" - "asdf/internal/plugins" - "asdf/internal/resolve" - "asdf/internal/shims" - "asdf/internal/toolversions" + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/hook" + "github.com/asdf-vm/asdf-core-go/internal/installs" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/internal/resolve" + "github.com/asdf-vm/asdf-core-go/internal/shims" + "github.com/asdf-vm/asdf-core-go/internal/toolversions" ) const ( diff --git a/internal/versions/versions_test.go b/internal/versions/versions_test.go index c9a41d48..f11ea6e8 100644 --- a/internal/versions/versions_test.go +++ b/internal/versions/versions_test.go @@ -7,10 +7,9 @@ import ( "strings" "testing" - "asdf/internal/config" - "asdf/internal/plugins" - "asdf/repotest" - + "github.com/asdf-vm/asdf-core-go/internal/config" + "github.com/asdf-vm/asdf-core-go/internal/plugins" + "github.com/asdf-vm/asdf-core-go/repotest" "github.com/stretchr/testify/assert" ) diff --git a/main.go b/main.go index df7ec11f..5d545be8 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,7 @@ // Main entrypoint for the CLI app package main -import ( - "asdf/cmd" -) +import "github.com/asdf-vm/asdf-core-go/cmd" // Replaced with the real version during a typical build var version = "v-dev" From be8ca381947182feda631d22b94631bbf1007932 Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Fri, 29 Nov 2024 15:57:12 -0500 Subject: [PATCH 2/6] asdf: replace direct `fmt.Println()` usage in a test with `t.Log()` --- internal/exec/exec_test.go | 1 + main_test.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/exec/exec_test.go b/internal/exec/exec_test.go index 50ba550f..ebe32229 100644 --- a/internal/exec/exec_test.go +++ b/internal/exec/exec_test.go @@ -14,6 +14,7 @@ func execit() int { cmdPath, _ := exec.LookPath(os.Args[1]) err := Exec(cmdPath, os.Args[2:], os.Environ()) if err != nil { + // TODO: Use testing logging system instead of direct printing. fmt.Printf("Err: %#+v\n", err.Error()) } diff --git a/main_test.go b/main_test.go index d13b798d..7bf20ec9 100644 --- a/main_test.go +++ b/main_test.go @@ -123,8 +123,8 @@ func runBatsFile(t *testing.T, dir, filename string) { err := cmd.Run() if err != nil { // If command fails print both stderr and stdout - fmt.Println("stdout:", stdout.String()) - fmt.Println("stderr:", stderr.String()) + t.Log("stdout:", stdout.String()) + t.Log("stderr:", stderr.String()) t.Fatal("bats command failed to run test file successfully") return From 9169040d3ddd16b4625c98b86b8f99f9eb921722 Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Fri, 29 Nov 2024 15:59:35 -0500 Subject: [PATCH 3/6] cli: move from `cmd` --- cmd/cmd.go => cli/cli.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename cmd/cmd.go => cli/cli.go (99%) diff --git a/cmd/cmd.go b/cli/cli.go similarity index 99% rename from cmd/cmd.go rename to cli/cli.go index 4719eae9..4e3bd09e 100644 --- a/cmd/cmd.go +++ b/cli/cli.go @@ -1,5 +1,5 @@ -// Package cmd contains the asdf CLI command code -package cmd +// Package cli contains the asdf CLI command code +package cli import ( "errors" From 241cecaf02f5be2e95c1624956a32c17d5a9239f Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Fri, 29 Nov 2024 15:59:45 -0500 Subject: [PATCH 4/6] cmd/asdf: move from module root --- main.go => cmd/asdf/main.go | 4 ++-- main_test.go => cmd/asdf/main_test.go | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename main.go => cmd/asdf/main.go (72%) rename main_test.go => cmd/asdf/main_test.go (100%) diff --git a/main.go b/cmd/asdf/main.go similarity index 72% rename from main.go rename to cmd/asdf/main.go index 5d545be8..4324dbe3 100644 --- a/main.go +++ b/cmd/asdf/main.go @@ -1,12 +1,12 @@ // Main entrypoint for the CLI app package main -import "github.com/asdf-vm/asdf-core-go/cmd" +import "github.com/asdf-vm/asdf-core-go/cli" // Replaced with the real version during a typical build var version = "v-dev" // Placeholder for the real code func main() { - cmd.Execute(version) + cli.Execute(version) } diff --git a/main_test.go b/cmd/asdf/main_test.go similarity index 100% rename from main_test.go rename to cmd/asdf/main_test.go From fef6e46d3c8d7a7143f5c1e225f413b620d36188 Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Fri, 29 Nov 2024 16:01:11 -0500 Subject: [PATCH 5/6] internal/toolversions: fix some linter warnings, thus enabling some tests that were being skipped --- internal/toolversions/toolversions_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/toolversions/toolversions_test.go b/internal/toolversions/toolversions_test.go index 5de32b49..dbb0f741 100644 --- a/internal/toolversions/toolversions_test.go +++ b/internal/toolversions/toolversions_test.go @@ -104,7 +104,7 @@ func TestUnique(t *testing.T) { }) } -func TestfindToolVersionsInContent(t *testing.T) { +func TestFindToolVersionsInContent(t *testing.T) { t.Run("returns empty list with found false when empty content", func(t *testing.T) { versions, found := findToolVersionsInContent("", "ruby") assert.False(t, found) @@ -124,7 +124,7 @@ func TestfindToolVersionsInContent(t *testing.T) { }) } -func TestgetAllToolsAndVersionsInContent(t *testing.T) { +func TestGetAllToolsAndVersionsInContent(t *testing.T) { tests := []struct { desc string input string From 3bcdf75967a03084cbb524b9f115f9d25207a14b Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Fri, 29 Nov 2024 16:06:34 -0500 Subject: [PATCH 6/6] meta: fix `Makefile` --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bf1e5fe1..4b8ce38c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -MAIN_PACKAGE_PATH := . +MAIN_PACKAGE_PATH := ./cmd/asdf TARGET_DIR := . TARGET := asdf FULL_VERSION = $(shell ./scripts/asdf-version ) @@ -31,7 +31,7 @@ lint: fmt revive -set_exit_status ./... vet: fmt - go vet . + go vet ./... run: build ${TARGET_DIR}/${TARGET}