-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,25 +4,22 @@ set -eo pipefail | |||||
main() { | ||||||
initialize_ | ||||||
parse_cmdline_ "$@" | ||||||
|
||||||
# propagate $FILES to custom function | ||||||
tfsec_ "$ARGS" "$FILES" | ||||||
tfsec_ | ||||||
} | ||||||
|
||||||
tfsec_() { | ||||||
# consume modified files passed from pre-commit so that | ||||||
# tfsec runs against only those relevant directories | ||||||
for file_with_path in $FILES; do | ||||||
for file_with_path in "${FILES[@]}"; do | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Same here probably:
Suggested change
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. OK 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. Actually, I think using the quoted 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 commentThe reason will be displayed to describe this comment to others. Learn more. FYI, it seems work OK for me:
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. 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 commentThe 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. 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. 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 commentThe 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:
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 commentThe 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 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 commentThe 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. |
||||||
popd > /dev/null | ||||||
done | ||||||
} | ||||||
|
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.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.
This is more of a safety net - it will throw an error if there is no arg.