From 3fc8ed8bf9849f84e67a5b2099ad13571ca8e4db Mon Sep 17 00:00:00 2001 From: Alexander Sharov Date: Wed, 12 Jun 2024 16:34:19 +0300 Subject: [PATCH 1/2] feat: improve logging for detect command add more logs Signed-off-by: Alexander Sharov --- .gitignore | 2 ++ Makefile | 29 +++++++++++++++++++---------- versionmanager/manager.go | 20 ++++++++++++++++---- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 58c72a22..31af01f0 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ terraform terragrunt tofu atmos + +./build/** \ No newline at end of file diff --git a/Makefile b/Makefile index 9343049d..a0cd945b 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,8 @@ # limitations under the License. # +.PHONY: build test clean + ##@ General help: ## Display this help. @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) @@ -29,18 +31,25 @@ vet: ## Run go vet against code. ##@ Build build: get fmt ## Build service binary. - go build -o tenv ./cmd/tenv - go build -o tofu ./cmd/tofu - go build -o terraform ./cmd/terraform - go build -o terragrunt ./cmd/terragrunt - go build -o atmos ./cmd/atmos - -run: ## Run service from your laptop. - go run ./main.go - -##@ Test + mkdir ./build || echo + go build -o ./build/tenv ./cmd/tenv + go build -o ./build/tofu ./cmd/tofu + go build -o ./build/terraform ./cmd/terraform + go build -o ./build/terragrunt ./cmd/terragrunt + go build -o ./build/atmos ./cmd/atmos + +##@ Run +run: build ## Run service from your laptop. + ./build/tenv + +##@ Lint lint: ## Run Go linter golangci-lint run ./... +##@ Test test: ## Run Go tests go test ./... + +##@ Clean +clean: + rm -f ./build \ No newline at end of file diff --git a/versionmanager/manager.go b/versionmanager/manager.go index ca39e93f..901ac094 100644 --- a/versionmanager/manager.go +++ b/versionmanager/manager.go @@ -25,6 +25,7 @@ import ( "os" "path/filepath" "slices" + "strings" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-version" @@ -38,8 +39,9 @@ import ( ) var ( - errEmptyVersion = errors.New("empty version") - errNoCompatible = errors.New("no compatible version found") + errEmptyVersion = errors.New("empty version") + errNoCompatible = errors.New("no compatible version found") + errNoCompatibleLocally = errors.New("no compatible version found locally") ) type ReleaseInfoRetriever interface { @@ -112,12 +114,22 @@ func (m VersionManager) Evaluate(requestedVersion string, proxyCall bool) (strin } } + m.conf.Displayer.Display("No compatible version found locally, search a remote one...") if m.conf.NoInstall { m.conf.Displayer.Flush(proxyCall) - return "", errNoCompatible + version, err := m.searchInstallRemote(predicateInfo, m.conf.NoInstall, proxyCall) + if err != nil { + return "", errNoCompatibleLocally + } + + cmdName := strings.ToLower(m.FolderName) + + m.conf.Displayer.Display("Auto-install is disabled. To install " + version + " version you can set environment variable TENV_AUTO_INSTALL=true, or install it via any of the following command: 'tenv " + cmdName + " install', 'tenv " + cmdName + " install " + version + "'") + + return "", errNoCompatibleLocally } - m.conf.Displayer.Display("No compatible version found locally, search a remote one...") + } return m.searchInstallRemote(predicateInfo, m.conf.NoInstall, proxyCall) From 20f8a5e2b5240d3159fed4156543616feb00cb08 Mon Sep 17 00:00:00 2001 From: Alexander Sharov Date: Fri, 14 Jun 2024 12:22:19 +0300 Subject: [PATCH 2/2] fix comments to manager.go Signed-off-by: Alexander Sharov --- versionmanager/manager.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/versionmanager/manager.go b/versionmanager/manager.go index 901ac094..bca1a966 100644 --- a/versionmanager/manager.go +++ b/versionmanager/manager.go @@ -116,17 +116,17 @@ func (m VersionManager) Evaluate(requestedVersion string, proxyCall bool) (strin m.conf.Displayer.Display("No compatible version found locally, search a remote one...") if m.conf.NoInstall { - m.conf.Displayer.Flush(proxyCall) - version, err := m.searchInstallRemote(predicateInfo, m.conf.NoInstall, proxyCall) + if err != nil { + m.conf.Displayer.Flush(proxyCall) return "", errNoCompatibleLocally } cmdName := strings.ToLower(m.FolderName) + m.conf.Displayer.Display(loghelper.Concat("Auto-install is disabled. To install ", version, " version you can set environment variable TENV_AUTO_INSTALL=true, or install it via any of the following command: 'tenv ", cmdName, " install', 'tenv ", cmdName, " install ", version, "'")) - m.conf.Displayer.Display("Auto-install is disabled. To install " + version + " version you can set environment variable TENV_AUTO_INSTALL=true, or install it via any of the following command: 'tenv " + cmdName + " install', 'tenv " + cmdName + " install " + version + "'") - + m.conf.Displayer.Flush(proxyCall) return "", errNoCompatibleLocally }