mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
Add --dest argument
This commit is contained in:
parent
debe93a82b
commit
cbd26b20c7
3 changed files with 10 additions and 5 deletions
|
|
@ -62,13 +62,13 @@ Check the [source file](https://github.com/antonbabenko/pre-commit-terraform/blo
|
|||
|
||||
1. `terraform_docs` and `terraform_docs_without_aggregate_type_defaults` will insert/update documentation generated by [terraform-docs](https://github.com/segmentio/terraform-docs) between markers - `<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->` and `<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->` if they are present in `README.md`. Make sure that `terraform-docs` is installed.
|
||||
|
||||
1. `terraform_docs_replace` replaces the entire README.md rather than doing string replacement between markers. Put your additional documentation at the top of your `main.tf` for it to be pulled in.
|
||||
1. `terraform_docs_replace` replaces the entire README.md rather than doing string replacement between markers. Put your additional documentation at the top of your `main.tf` for it to be pulled in. The optional `--dest` argument lets your change the name of the file that gets created/modified
|
||||
|
||||
1. Example:
|
||||
```yaml
|
||||
hooks:
|
||||
- id: terraform_docs_replace
|
||||
args: ['--with-aggregate-type-defaults', '--sort-inputs-by-required']
|
||||
args: ['--with-aggregate-type-defaults', '--sort-inputs-by-required', '--dest=TEST.md']
|
||||
```
|
||||
|
||||
1. It is possible to pass additional arguments to shell scripts when using `terraform_docs` and `terraform_docs_without_aggregate_type_defaults`. Send pull-request with the new hook if there is something missing.
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ def main(argv=None):
|
|||
pulling the documentation from main.tf in order to replace the entire
|
||||
README.md file each time."""
|
||||
)
|
||||
parser.add_argument(
|
||||
'--dest', dest='dest', default='README.md',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--sort-inputs-by-required', dest='sort', action='store_true',
|
||||
)
|
||||
|
|
@ -21,7 +24,9 @@ def main(argv=None):
|
|||
|
||||
dirs = []
|
||||
for filename in args.filenames:
|
||||
if os.path.realpath(filename) not in dirs:
|
||||
if (os.path.realpath(filename) not in dirs and \
|
||||
len(os.path.realpath(filename).strip()) > 0 and \
|
||||
(filename.endswith(".tf") or filename.endswith(".tfvars"))):
|
||||
dirs.append(os.path.dirname(filename))
|
||||
|
||||
retval = 0
|
||||
|
|
@ -38,7 +43,7 @@ def main(argv=None):
|
|||
procArgs.append(dir)
|
||||
procArgs.append("| sed -e '$ d' -e 'N;/^\\n$/D;P;D'")
|
||||
procArgs.append('>')
|
||||
procArgs.append('{}/README.md'.format(dir))
|
||||
procArgs.append("./{dir}/{dest}".format(dir=dir,dest=args.dest))
|
||||
subprocess.check_call(" ".join(procArgs), shell=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(e)
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -4,7 +4,7 @@ from setuptools import setup
|
|||
|
||||
setup(
|
||||
name='pre-commit-terraform',
|
||||
description='Pre-commit hooks for terraform_docs_replace,
|
||||
description='Pre-commit hooks for terraform_docs_replace',
|
||||
url='https://github.com/antonbabenko/pre-commit-terraform',
|
||||
version_format='{tag}+{gitsha}',
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue