diff --git a/src/pre_commit_terraform/_cli.py b/src/pre_commit_terraform/_cli.py index 70f7a70a3..2ad7c5e31 100644 --- a/src/pre_commit_terraform/_cli.py +++ b/src/pre_commit_terraform/_cli.py @@ -18,6 +18,9 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType: Includes initializing parsers of all the sub-apps and choosing what to execute. + + Returns: + ReturnCodeType: The return code of the app. """ root_cli_parser = initialize_argument_parser() parsed_cli_args = root_cli_parser.parse_args(cli_args) diff --git a/src/pre_commit_terraform/_cli_parsing.py b/src/pre_commit_terraform/_cli_parsing.py index a51a6fc2b..4bdebf6d0 100644 --- a/src/pre_commit_terraform/_cli_parsing.py +++ b/src/pre_commit_terraform/_cli_parsing.py @@ -32,7 +32,11 @@ def attach_subcommand_parsers_to(root_cli_parser: ArgumentParser, /) -> None: def initialize_argument_parser() -> ArgumentParser: - """Return the root argument parser with sub-commands.""" + """Return the root argument parser with sub-commands. + + Returns: + ArgumentParser: The root parser with sub-commands attached. + """ root_cli_parser = ArgumentParser(prog=f'python -m {__package__ !s}') attach_subcommand_parsers_to(root_cli_parser) return root_cli_parser diff --git a/src/pre_commit_terraform/terraform_docs_replace.py b/src/pre_commit_terraform/terraform_docs_replace.py index d92e9c6b8..d273d6dac 100644 --- a/src/pre_commit_terraform/terraform_docs_replace.py +++ b/src/pre_commit_terraform/terraform_docs_replace.py @@ -12,6 +12,7 @@ def populate_argument_parser(subcommand_parser: ArgumentParser) -> None: + """Populate the parser for the subcommand.""" subcommand_parser.description = ( 'Run terraform-docs on a set of files. Follows the standard ' 'convention of pulling the documentation from main.tf in order to ' @@ -47,13 +48,19 @@ def populate_argument_parser(subcommand_parser: ArgumentParser) -> None: def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType: + """Run the entry-point of the CLI app. + + Returns: + ReturnCodeType: The return code of the app. + """ warnings.warn( '`terraform_docs_replace` hook is DEPRECATED.' 'For migration instructions see ' 'https://github.com/antonbabenko/pre-commit-terraform/issues/248' '#issuecomment-1290829226', category=UserWarning, - stacklevel=1, # It's should be 2, but tests are failing w/ values >1. As it's deprecated hook, it's safe to leave it as is w/o fixing it later. + stacklevel=1, # It's should be 2, but tests are failing w/ values >1. + # As it's deprecated hook, it's safe to leave it as is w/o fixing it. ) dirs: list[str] = [] @@ -65,24 +72,24 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType: retval = ReturnCode.OK - for dir in dirs: + for directory in dirs: try: - procArgs = [] - procArgs.append('terraform-docs') + proc_args = [] + proc_args.append('terraform-docs') if cast_to('bool', parsed_cli_args.sort): - procArgs.append('--sort-by-required') - procArgs.extend( + proc_args.append('--sort-by-required') + proc_args.extend( ( 'md', - f'./{dir}', + f'./{directory}', '>', './{dir}/{dest}'.format( - dir=dir, + dir=directory, dest=cast_to('str', parsed_cli_args.dest), ), ), ) - subprocess.check_call(' '.join(procArgs), shell=True) + subprocess.check_call(' '.join(proc_args), shell=True) except subprocess.CalledProcessError as e: print(e) retval = ReturnCode.ERROR diff --git a/tests/pytest/_cli_test.py b/tests/pytest/_cli_test.py index a265102c4..262df81d7 100644 --- a/tests/pytest/_cli_test.py +++ b/tests/pytest/_cli_test.py @@ -23,7 +23,6 @@ @pytest.mark.parametrize( ('raised_error', 'expected_stderr'), ( - # pytest.param(PreCommitTerraformExit('sentinel'), 'App exiting: sentinel', id='app-exit'), pytest.param( PreCommitTerraformRuntimeError('sentinel'), 'App execution took an unexpected turn: sentinel. Exiting...', @@ -97,7 +96,7 @@ def invoke_cli_app(self, parsed_cli_args: Namespace) -> ReturnCodeType: [CustomCmdStub()], ) - with pytest.raises(PreCommitTerraformExit, match='^sentinel$'): + with pytest.raises(PreCommitTerraformExit, match=r'^sentinel$'): invoke_cli_app(['sentinel']) captured_outputs = capsys.readouterr()