Skip to content

Commit

Permalink
Merge pull request #165 from tofuutils/feat/improve-logging
Browse files Browse the repository at this point in the history
feat: improve logging for detect command
  • Loading branch information
kvendingoldo authored Jun 16, 2024
2 parents dcd10d8 + 20f8a5e commit f33fa8d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
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

0 comments on commit f33fa8d

Please sign in to comment.