Skip to content

Commit 0d9676f

Browse files
authored
Discard changes to src/pre_commit_terraform/terraform_docs_replace.py
1 parent 851674b commit 0d9676f

File tree

1 file changed

+23
-42
lines changed

1 file changed

+23
-42
lines changed
Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"""`terraform_docs_replace` hook. Deprecated."""
2-
31
import os
4-
import subprocess # noqa: S404. We invoke cli tools
2+
import subprocess
53
import warnings
64
from argparse import ArgumentParser, Namespace
75
from typing import cast as cast_to
@@ -14,27 +12,20 @@
1412

1513

1614
def populate_argument_parser(subcommand_parser: ArgumentParser) -> None:
17-
"""Populate the parser for the subcommand."""
1815
subcommand_parser.description = (
1916
'Run terraform-docs on a set of files. Follows the standard '
2017
'convention of pulling the documentation from main.tf in order to '
2118
'replace the entire README.md file each time.'
2219
)
2320
subcommand_parser.add_argument(
24-
'--dest',
25-
dest='dest',
26-
default='README.md',
21+
'--dest', dest='dest', default='README.md',
2722
)
2823
subcommand_parser.add_argument(
29-
'--sort-inputs-by-required',
30-
dest='sort',
31-
action='store_true',
24+
'--sort-inputs-by-required', dest='sort', action='store_true',
3225
help='[deprecated] use --sort-by-required instead',
3326
)
3427
subcommand_parser.add_argument(
35-
'--sort-by-required',
36-
dest='sort',
37-
action='store_true',
28+
'--sort-by-required', dest='sort', action='store_true',
3829
)
3930
subcommand_parser.add_argument(
4031
'--with-aggregate-type-defaults',
@@ -50,13 +41,7 @@ def populate_argument_parser(subcommand_parser: ArgumentParser) -> None:
5041

5142

5243
def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
53-
"""Run the entry-point of the CLI app.
54-
55-
Returns:
56-
ReturnCodeType: The return code of the app.
57-
58-
"""
59-
warnings.warn( # noqa: B028. that's user warning, no need to show stacktrace etc.
44+
warnings.warn(
6045
'`terraform_docs_replace` hook is DEPRECATED.'
6146
'For migration instructions see '
6247
'https://github.com/antonbabenko/pre-commit-terraform/issues/248'
@@ -65,32 +50,28 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
6550
)
6651

6752
dirs: list[str] = []
68-
for filename in cast_to('list[str]', parsed_cli_args.filenames):
69-
if os.path.realpath(filename) not in dirs and (
70-
filename.endswith(('.tf', '.tfvars'))
71-
):
72-
dirs.append(os.path.dirname(filename)) # noqa: PTH120. Legacy hook, no need to refactor
53+
for filename in cast_to(list[str], parsed_cli_args.filenames):
54+
if (os.path.realpath(filename) not in dirs and
55+
(filename.endswith(".tf") or filename.endswith(".tfvars"))):
56+
dirs.append(os.path.dirname(filename))
7357

7458
retval = ReturnCode.OK
7559

76-
for directory in dirs:
60+
for dir in dirs:
7761
try:
78-
proc_args = []
79-
proc_args.append('terraform-docs')
80-
if cast_to('bool', parsed_cli_args.sort):
81-
proc_args.append('--sort-by-required')
82-
proc_args.extend(
83-
(
84-
'md',
85-
f'./{directory}',
86-
'>',
87-
f"./{directory}/{cast_to('bool', parsed_cli_args.dest)}",
88-
),
62+
procArgs = []
63+
procArgs.append('terraform-docs')
64+
if cast_to(bool, parsed_cli_args.sort):
65+
procArgs.append('--sort-by-required')
66+
procArgs.append('md')
67+
procArgs.append("./{dir}".format(dir=dir))
68+
procArgs.append('>')
69+
procArgs.append(
70+
'./{dir}/{dest}'.
71+
format(dir=dir, dest=cast_to(bool, parsed_cli_args.dest)),
8972
)
90-
# We call cli tools, of course we use shell=True
91-
subprocess.check_call(' '.join(proc_args), shell=True) # noqa: S602
92-
# Legacy hook, no need to refactor
93-
except subprocess.CalledProcessError as e: # noqa: PERF203
94-
print(e) # noqa: T201
73+
subprocess.check_call(" ".join(procArgs), shell=True)
74+
except subprocess.CalledProcessError as e:
75+
print(e)
9576
retval = ReturnCode.ERROR
9677
return retval

0 commit comments

Comments
 (0)