From 72e82d39510aaad3a434b422e370a1de81a74b2b Mon Sep 17 00:00:00 2001 From: Mike Peachey Date: Sat, 6 Feb 2021 17:25:21 +0000 Subject: [PATCH 1/2] Do not grep recursively for min-required --- libexec/tfenv-min-required | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libexec/tfenv-min-required b/libexec/tfenv-min-required index d54169d..1609ef6 100755 --- a/libexec/tfenv-min-required +++ b/libexec/tfenv-min-required @@ -74,8 +74,7 @@ see https://www.terraform.io/docs/configuration/terraform.html for details'; find_min_required() { local root="${1}"; - # Only grep recursively if we cannot a required version in base of directory - versions="$( echo $(grep -h required_version --include '*tf' "${root}"/* || grep -h -R required_version --include '*tf' "${root}"/*) | grep -o '\([0-9]\+\.\?\)\{2,3\}\(-[a-z]\+[0-9]\+\)\?')"; + versions="$( echo $(grep -h required_version --include '*tf' "${root}"/* ) | grep -o '\([0-9]\+\.\?\)\{2,3\}\(-[a-z]\+[0-9]\+\)\?')"; if [[ "${versions}" =~ ([~=!<>]{0,2}[[:blank:]]*[0-9]+[0-9.]+)[^0-9]*(-[a-z]+[0-9]+)? ]]; then found_min_required="${BASH_REMATCH[1]}${BASH_REMATCH[2]}" From 356192f5df52fa46b36af2bb391bd69afdde2ab8 Mon Sep 17 00:00:00 2001 From: Mike Peachey Date: Sat, 6 Feb 2021 19:32:55 +0000 Subject: [PATCH 2/2] Change grep to not require include support and suppress error on lack of tf files --- libexec/tfenv-min-required | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/tfenv-min-required b/libexec/tfenv-min-required index 1609ef6..e550a98 100755 --- a/libexec/tfenv-min-required +++ b/libexec/tfenv-min-required @@ -74,7 +74,7 @@ see https://www.terraform.io/docs/configuration/terraform.html for details'; find_min_required() { local root="${1}"; - versions="$( echo $(grep -h required_version --include '*tf' "${root}"/* ) | grep -o '\([0-9]\+\.\?\)\{2,3\}\(-[a-z]\+[0-9]\+\)\?')"; + versions="$( echo $(grep -h required_version "${root}"/*.tf 2>/dev/null ) | grep -o '\([0-9]\+\.\?\)\{2,3\}\(-[a-z]\+[0-9]\+\)\?')"; if [[ "${versions}" =~ ([~=!<>]{0,2}[[:blank:]]*[0-9]+[0-9.]+)[^0-9]*(-[a-z]+[0-9]+)? ]]; then found_min_required="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"