Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve logging for detect command #165

Merged
merged 2 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ terraform
terragrunt
tofu
atmos

./build/**
29 changes: 19 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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<target>\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)
Expand All @@ -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
22 changes: 17 additions & 5 deletions versionmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path/filepath"
"slices"
"strings"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-version"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Loading