-
-
Notifications
You must be signed in to change notification settings - Fork 541
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: Cleanup internal argument handling #142
Conversation
ARGS and FILES are global arrays - no need to pass them as function arguments
b22e77b
to
c862c4b
Compare
@sergei-ivanov Can you please take a look at this. I've cleaned up the argument handling in terraform_docs so we simply use the global arrays |
local -r args="$2" | ||
shift 2 | ||
local -a -r files=("$@") | ||
local -r terraform_docs_awk_file="$1" ; shift |
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.
There's not really much point in shift
anymore, now that we are using the globals.
local -r terraform_docs_awk_file="$1" ; shift | |
local -r terraform_docs_awk_file="$1" |
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.
There's not really much point in
shift
anymore, now that we are using the globals.
This is more of a safety net - it will throw an error if there is no arg.
done | ||
|
||
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do | ||
path_uniq="${path_uniq//__REPLACED__SPACE__/ }" | ||
pushd "$path_uniq" > /dev/null | ||
tfsec $ARGS | ||
tfsec "${ARGS[@]}" |
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.
Same here probably:
tfsec "${ARGS[@]}" | |
tfsec ${ARGS[*]} |
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.
OK
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.
Actually, I think using the quoted @
form is the correct approach here, and in terraform_docs
.
Can you re-check with 3a68667 and let me know what you think?
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.
FYI, it seems work OK for me:
$ pre-commit try-repo -a ~/code/pre-commit-terraform terraform_docs
===============================================================================
Using config:
===============================================================================
repos:
- repo: ../../../../pre-commit-terraform
rev: 3a68667efc0f95f9c01db4a79aff33075697fc2e
hooks:
- id: terraform_docs
===============================================================================
[INFO] Initializing environment for ../../../../pre-commit-terraform.
Terraform docs...........................................................Failed
- hook id: terraform_docs
- files were modified by this hook
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.
It does not work with args specified like this:
hooks:
- id: terraform_docs
args:
- '--args=document --indent 3'
...which is expected. But it does work when args are split into individual tokens:
hooks:
- id: terraform_docs
args:
- '--args=document'
- '--args=--indent'
- '--args=3'
I am not sure whether we would want to enforce passing the args one by one, or be more lenient like in the 1st example.
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 think that's a cleaner solution than trying to cope with eg. '--args=document --indent 3'
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.
Both options are fine by me. If we settle on option 2, I think we need a section in the documentation/readme with a usage example for additional arguments (feel free to use the example above). Simply because it is not obvious at all at the moment.
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.
Agreed - the docs need updating.
Is your example correct, though? Wouldn't it be this:
hooks:
- id: terraform_docs
args:
- 'document'
- '--indent=3'
I think the other examples in the README may be wrong too.
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.
The one above is correct and tested. One needs to prepend each argument with --args=
prefix. I guess that is because we want to distinguish the arguments to terraform-docs from the list of files passed in by pre-commit.
So the arguments should be passed like this:
- id: terraform_docs
args:
- '--args=document'
- '--args=--indent'
- '--args=3'
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.
OK, so I think we're saying we should use one arg per line ie. option 2 but that we should make sure we update the documentation to be clearer.
When is the slated to be merged in? Our tfsec exclusion parameter isn't being read properly and this fix is very important! |
This PR has been automatically marked as stale because it has been open 30 days |
file_with_path="${file_with_path// /__REPLACED__SPACE__}" | ||
paths[index]=$(dirname "$file_with_path") | ||
|
||
let "index+=1" | ||
(( index+=1 )) |
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.
(( index+=1 )) | |
(( index++ )) |
Nope, we should pass them to functions, because it explicitly mentions which vars go to function. |
ARGS and FILES are global arrays - no need to pass them as function arguments