fix: Cleanup internal argument handling#142
fix: Cleanup internal argument handling#142robinbowes wants to merge 2 commits intoantonbabenko:masterfrom
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.
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.
There's not really much point in
shiftanymore, now that we are using the globals.
This is more of a safety net - it will throw an error if there is no arg.
| path_uniq="${path_uniq//__REPLACED__SPACE__/ }" | ||
| pushd "$path_uniq" > /dev/null | ||
| tfsec $ARGS | ||
| tfsec "${ARGS[@]}" |
There was a problem hiding this comment.
Same here probably:
| tfsec "${ARGS[@]}" | |
| tfsec ${ARGS[*]} |
There was a problem hiding this comment.
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.
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.
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.
I think that's a cleaner solution than trying to cope with eg. '--args=document --indent 3'
There was a problem hiding this comment.
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.
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.
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.
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 |
| paths[index]=$(dirname "$file_with_path") | ||
|
|
||
| let "index+=1" | ||
| (( index+=1 )) |
There was a problem hiding this comment.
| (( 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