mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2026-06-05 08:26:55 +02:00
refactor: improve directory handling and tofu validate logic
Deduplicate directories in tofu_docs_replace.py by using a set of real paths, ensuring each directory is processed only once. Refactor tofu_validate.sh to use command substitution with proper exit code handling, improving reliability and clarity. Signed-off-by: Michael Rosenfeld <michael@rosesecurity.com>
This commit is contained in:
parent
b766f82b08
commit
9316d2989c
2 changed files with 22 additions and 12 deletions
|
|
@ -36,13 +36,14 @@ def main(argv=None):
|
|||
args = parser.parse_args(argv)
|
||||
|
||||
dirs = []
|
||||
seen_dirs = set()
|
||||
for filename in args.filenames:
|
||||
if os.path.realpath(filename) not in dirs and (
|
||||
filename.endswith(".tf")
|
||||
or filename.endswith(".tofu")
|
||||
or filename.endswith(".tfvars")
|
||||
):
|
||||
dirs.append(os.path.dirname(filename))
|
||||
if filename.endswith((".tf", ".tofu", ".tfvars")):
|
||||
dir_path = os.path.dirname(filename)
|
||||
dir_key = os.path.realpath(dir_path)
|
||||
if dir_key not in seen_dirs:
|
||||
seen_dirs.add(dir_key)
|
||||
dirs.append(dir_path)
|
||||
|
||||
retval = 0
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue