-
-
Notifications
You must be signed in to change notification settings - Fork 544
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
fix(terraform_docs
): Fix issue and prioritize output.file
setting from .terraform-docs.yml
config over --hook-config=--path-to-file=
#698
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ab5f7ac
fix(terraform_docs): force rendered documentation to be written to st…
sworisbreathing c6ef954
Prioritize terraform-docs config
MaxymVlasov 5240d53
Catch edge cases
MaxymVlasov 5f136ea
f
MaxymVlasov bff1191
Apply review suggestions
MaxymVlasov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,13 +159,24 @@ function terraform_docs { | |
if [[ "$args" != *"--config"* ]]; then | ||
local tf_docs_formatter="md" | ||
|
||
# Suppress terraform_docs color | ||
else | ||
|
||
local config_file=${args#*--config} | ||
config_file=${config_file#*=} | ||
config_file=${config_file% *} | ||
|
||
# Prioritize `.terraform-docs.yml` `output.file` over | ||
# `--hook-config=--path-to-file=` if it set | ||
local output_file | ||
# Get latest non-commented `output.file` from `.terraform-docs.yml` | ||
output_file=$(grep -A1000 -e '^output:$' "$config_file" | grep ' file:' | grep -v '#' | tail -n 1 || true) | ||
MaxymVlasov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if [ "$output_file" ]; then | ||
MaxymVlasov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Extract filename from `output.file` line | ||
text_file=$(echo "$output_file" | awk -F':' '{print $2}' | tr -d '[:space:]"' | tr -d "'") | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done it this way to avoid introduction of new dependencies ( |
||
|
||
# Suppress terraform_docs color | ||
local config_file_no_color | ||
config_file_no_color="$config_file$(date +%s).yml" | ||
|
||
|
@@ -228,7 +239,7 @@ function terraform_docs { | |
|
||
if [[ "$terraform_docs_awk_file" == "0" ]]; then | ||
# shellcheck disable=SC2086 | ||
terraform-docs $tf_docs_formatter $args ./ > "$tmp_file" | ||
terraform-docs --output-file="" $tf_docs_formatter $args ./ > "$tmp_file" | ||
else | ||
# Can't append extension for mktemp, so renaming instead | ||
local tmp_file_docs | ||
|
@@ -239,7 +250,7 @@ function terraform_docs { | |
|
||
awk -f "$terraform_docs_awk_file" ./*.tf > "$tmp_file_docs_tf" | ||
# shellcheck disable=SC2086 | ||
terraform-docs $tf_docs_formatter $args "$tmp_file_docs_tf" > "$tmp_file" | ||
terraform-docs --output-file="" $tf_docs_formatter $args "$tmp_file_docs_tf" > "$tmp_file" | ||
rm -f "$tmp_file_docs_tf" | ||
fi | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't seem to understand the reasoning: ain't it better to raise error when both options are used instead of silently ignoring hook config's one? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean is that if a user provides this option to hook, then the user expects it to use this option. When there's a race condition, we should raise error or indicate incorrect setting by other mean(s) (e.g. by printing warning message that the one from YAML is used and the hook config's one is ignored).
I'm ok with either approach when this is clearly brought to user's attention and knowledge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reasoning was described in #382
I'll add warning msg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a read and... and didn't get it =( I'd appreciate "tl;dr" =)
It's most common that command line parameters override config file params. Which is sort of comparable with
--hook-config
.Either way I'm relying on your opinion in this case 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love removing code. Much more than write new one :D
Because you don't need to maintain code which not exist.
At the end, I'd like to replace as much hand-made settings as possible by 3rd-party, in this case - by terraform-docs settings. So, at the end, I'd like to deprecate and remove every
--hook-config
which can be replaced byterraform-docs
settings, as long as it will not violate main idea of how pre-commit hooks worksThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So keeping this in mind, we can clearly see that native terraform-docs settings should have precedence over
--hook-config
settings, as long as they not break hook execution - in last case we try explicitly disable such settings (or at least mention in docs that they shouldn't be used)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, now I think I got the point: hook config's parameter is a workaround from when tf-docs wasn't mature enough — this makes sense to me now 👍🏻 Thanks.