Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(terraform_docs): Add support for custom markers to better support other formats than Markdown #752

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tarfu
Copy link

@tarfu tarfu commented Jan 14, 2025

Put an x into the box if that apply:

  • This PR introduces breaking change.
  • This PR fixes a bug.
  • This PR adds new functionality.
  • This PR enhances existing functionality.

Description of your changes

This adds support to pass custom markers.
This helps to improve support for other formats like asciidoc which you can use if you use a config for terraform-doc.

How can we test changes

Add your custom marker to a README and run the hook with the options. You may also want to change the template used by terraform-doc

terraform_docs.sh --hook-config=--path-to-file=README.adoc --hook-config="--custom-marker-begin=// BEGIN_TF_DOCS" --hook-config="--custom-marker-end=// END_TF_DOCS" --args=--config=.terraform-docs.yml ./path/to/file.tf

@tarfu tarfu force-pushed the tfdocs-custom-markers branch from 895c3fe to c6065ae Compare January 14, 2025 11:18
Copy link
Collaborator

@yermulnik yermulnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. Please have a look into comments I added.
I'd also think of adding this as a single configuration parameter to avoid use of mix of standard and custom markers. Something like --custom-markers="// BEGIN;// END". This may decrease clarity and readability and separator needs a more thorough think though.

README.md Outdated Show resolved Hide resolved
hooks/terraform_docs.sh Outdated Show resolved Hide resolved
hooks/terraform_docs.sh Outdated Show resolved Hide resolved
Copy link
Collaborator

@yermulnik yermulnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. @MaxymVlasov What do you think?

@MaxymVlasov MaxymVlasov changed the title feat(terraform-doc): Add support for custom markers to better support other formats than markdown feat(terraform_docs): Add support for custom markers to better support other formats than Markdown Jan 14, 2025
@MaxymVlasov MaxymVlasov changed the title feat(terraform_docs): Add support for custom markers to better support other formats than Markdown feat(terraform_docs): Add support for custom markers to better support other formats than Markdown Jan 14, 2025
@MaxymVlasov MaxymVlasov added feature New feature or request hook/terraform_docs Bash hook labels Jan 14, 2025
Copy link

codecov bot commented Jan 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.38%. Comparing base (2e6b270) to head (fc53d0a).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##            master     #752      +/-   ##
===========================================
- Coverage   100.00%   96.38%   -3.62%     
===========================================
  Files            9       10       +1     
  Lines          161      249      +88     
  Branches         5        7       +2     
===========================================
+ Hits           161      240      +79     
- Misses           0        9       +9     
Flag Coverage Δ
CI-GHA 96.38% <ø> (-3.62%) ⬇️
MyPy 91.05% <ø> (?)
OS-Linux 96.38% <ø> (?)
OS-Windows 100.00% <ø> (ø)
OS-macOS 100.00% <ø> (ø)
Py-3.10.11 100.00% <ø> (ø)
Py-3.10.16 100.00% <ø> (?)
Py-3.11.11 100.00% <ø> (?)
Py-3.11.9 100.00% <ø> (ø)
Py-3.12.8 100.00% <ø> (ø)
Py-3.13.1 96.38% <ø> (-3.62%) ⬇️
Py-3.9.13 100.00% <ø> (ø)
Py-3.9.21 100.00% <ø> (ø)
VM-macos-13 100.00% <ø> (ø)
VM-macos-14 100.00% <ø> (ø)
VM-ubuntu-24.04 100.00% <ø> (?)
VM-ubuntu-latest 91.05% <ø> (?)
VM-windows-2025 100.00% <ø> (ø)
pytest 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MaxymVlasov
Copy link
Collaborator

Hmm, you probably had // BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK and // END OF PRE-COMMIT-TERRAFORM DOCS HOOK?

trace: replace_old_markers terraform_docs main main
       terraform_docs.sh:45: sed -i -e 's/^<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->$/\/\/ BEGIN_TF_DOCS/' README.adoc

trace: replace_old_markers terraform_docs main main
       terraform_docs.sh:46: sed -i -e 's/^<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->$/\/\/ END_TF_DOCS/' README.adoc

@MaxymVlasov
Copy link
Collaborator

Also, I found that

formatter: asciidoc table
output:
  file: README.adoc
  mode: inject
  template: |-
    // BEGIN_TF_DOCS
    {{ .Content }}
    // END_TF_DOCS
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
  rev: fc53d0a10b7846fa8571ddd504660cbe5c6110d6
    - id: terraform_docs
      args:
      - --hook-config=--add-to-existing-file=true     # Boolean. true or false
      #- --hook-config=--custom-marker-begin=// BEGIN_TF_DOCS
      #- --hook-config=--custom-marker-end=// END_TF_DOCS

When you have empty README.adoc, works fine without custom-marker-begin and custom-marker-end options.

And it produces identical result as for rev: 1.96.3

Can you please elaborate on what exactly you tried to fix/add by this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request hook/terraform_docs Bash hook
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants