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..bca1a966 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) + version, err := m.searchInstallRemote(predicateInfo, m.conf.NoInstall, proxyCall) + + if err != nil { + m.conf.Displayer.Flush(proxyCall) + return "", errNoCompatibleLocally + } - return "", errNoCompatible + 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.Flush(proxyCall) + return "", errNoCompatibleLocally } - m.conf.Displayer.Display("No compatible version found locally, search a remote one...") + } return m.searchInstallRemote(predicateInfo, m.conf.NoInstall, proxyCall)