tfutils / tfenv

Terraform version manager
MIT License
4.52k stars 454 forks source link

Refactor readlink_f to common helpers #366

Closed OJFord closed 1 year ago

OJFord commented 1 year ago

In the course of fixing #355's use of realpath --relative-to for macOS, I tried to use readlink --canonicalize/-f which had a similar problem, and through that noticed the extensive extant use of a readlink_f function to achieve that functionality. The same function is currently replicated 23 times through the repo.

In the interest of readability, maintainability etc., this PR refactors that to the common helpers.sh, exporting it for use everywhere without redefinition.

355 also revealed a bug in the implementation I copied again, which I subsequently fixed in that instance. That's reproduced here too (and thus for all uses of the function) in 1784a4f0d8b96d23b70f472197a952db575d1e05.

(This is based on top of #355, since that PR adds another instance of this function. I'll rebase this once that's merged - please consider this a draft until then.)

OJFord commented 1 year ago

Bah, I see why this was done now, the existing use of readlink_f is in finding TFENV_ROOT, and helpers.sh is sourced from within that dir.