mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
feat: spport .tofu files (#6)
Signed-off-by: T. Hinrichsmeyer <t.hinrichsmeyer@ndr.de>
This commit is contained in:
parent
81b78c8fd7
commit
e059c5859b
4 changed files with 53 additions and 35 deletions
|
|
@ -155,7 +155,7 @@ function tofu_docs {
|
|||
#
|
||||
if $create_if_not_exist && [[ ! -f "$text_file" ]]; then
|
||||
dir_have_tf_files="$(
|
||||
find . -maxdepth 1 -type f | sed 's|.*\.||' | sort -u | grep -oE '^tf$|^tfvars$' ||
|
||||
find . -maxdepth 1 -type f | sed 's|.*\.||' | sort -u | grep -oE '^tofu|^tf$|^tfvars$' ||
|
||||
exit 0
|
||||
)"
|
||||
|
||||
|
|
|
|||
|
|
@ -7,30 +7,41 @@ import sys
|
|||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(
|
||||
description="""Run terraform-docs on a set of files. Follows the standard convention of
|
||||
pulling the documentation from main.tf in order to replace the entire
|
||||
pulling the documentation from main.(tf|tofu) in order to replace the entire
|
||||
README.md file each time."""
|
||||
)
|
||||
parser.add_argument(
|
||||
'--dest', dest='dest', default='README.md',
|
||||
"--dest",
|
||||
dest="dest",
|
||||
default="README.md",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--sort-inputs-by-required', dest='sort', action='store_true',
|
||||
help='[deprecated] use --sort-by-required instead',
|
||||
"--sort-inputs-by-required",
|
||||
dest="sort",
|
||||
action="store_true",
|
||||
help="[deprecated] use --sort-by-required instead",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--sort-by-required', dest='sort', action='store_true',
|
||||
"--sort-by-required",
|
||||
dest="sort",
|
||||
action="store_true",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--with-aggregate-type-defaults', dest='aggregate', action='store_true',
|
||||
help='[deprecated]',
|
||||
"--with-aggregate-type-defaults",
|
||||
dest="aggregate",
|
||||
action="store_true",
|
||||
help="[deprecated]",
|
||||
)
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
|
||||
parser.add_argument("filenames", nargs="*", help="Filenames to check.")
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
dirs = []
|
||||
for filename in args.filenames:
|
||||
if (os.path.realpath(filename) not in dirs and
|
||||
(filename.endswith(".tf") or filename.endswith(".tfvars"))):
|
||||
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))
|
||||
|
||||
retval = 0
|
||||
|
|
@ -38,12 +49,12 @@ def main(argv=None):
|
|||
for dir in dirs:
|
||||
try:
|
||||
procArgs = []
|
||||
procArgs.append('terraform-docs')
|
||||
procArgs.append("terraform-docs")
|
||||
if args.sort:
|
||||
procArgs.append('--sort-by-required')
|
||||
procArgs.append('md')
|
||||
procArgs.append("--sort-by-required")
|
||||
procArgs.append("md")
|
||||
procArgs.append("./{dir}".format(dir=dir))
|
||||
procArgs.append('>')
|
||||
procArgs.append(">")
|
||||
procArgs.append("./{dir}/{dest}".format(dir=dir, dest=args.dest))
|
||||
subprocess.check_call(" ".join(procArgs), shell=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
|
@ -52,5 +63,5 @@ def main(argv=None):
|
|||
return retval
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
|
|
|||
|
|
@ -312,10 +312,10 @@ EOF
|
|||
|
||||
# Read content of all OpenTofu files
|
||||
# shellcheck disable=SC2207
|
||||
all_tf_content=$(find "${full_module_dir}" -name '*.tf' -maxdepth 1 -type f -exec cat {} +)
|
||||
all_tf_content=$(find "${full_module_dir}" -regex '.*\.(tf|tofu)' -maxdepth 1 -type f -exec cat {} +)
|
||||
|
||||
if [[ ! $all_tf_content ]]; then
|
||||
common::colorify "yellow" "Skipping ${full_module_dir} because there are no *.tf files."
|
||||
common::colorify "yellow" "Skipping ${full_module_dir} because there are no *.(tf|tofu) files."
|
||||
continue
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue