-
-
Notifications
You must be signed in to change notification settings - Fork 549
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: Adding getopt flag and feature: --env-passthrough #347
Conversation
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 we can introduce logic that covers more cases.
Firstly, we should avoid difficult-to-understand logic for users.
Secondly, it should be simple to understand and know how to use (UX).
Hooks are not run in environment isolation (that's where from your use case) so, the first idea - is just to use the POSIX standard of environment variables.
I spend some time with @yermulnik brainstorming how it can be done and created #363.
Please check if that will work for you.
P.S. Before I start working on #363, I quickly review your PR and leave some comments. No more need to implement suggestions in them, I keep them JFYI, hope it will be helpful :)
# | ||
# Example usage: | ||
# - FOO=one | ||
# - __ENV_FOO__ becomes "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.
Please, provide func doc as it specified in Google Shell styleguide
# - __ENV_FOO__ becomes "one" | ||
|
||
function common::passthrough_env_vars { | ||
local var |
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.
- Pass
ENV_PASSTHRU
from outside, don't use global vars. local var
declaration not needed at all
This issue has been resolved in version 1.69.0 🎉 |
Put an
x
into the box if that apply:Description of your changes
Context: I need to pass in the location of an alternate
tflint
config in CI.The location is based on an environment variable in my CI environment, so
hard-coding the value as an argument isn't tenable.
This PR adds the
__ENV_*__
placeholder, and the argument--env-passthrough
.The idea is to replace the
__ENV_FOO__
placeholder with the value ofenvironment variable
${FOO}
.Example config leveraging the changes in this PR:
Note: hooks which do not use the common argument parser in
_common.sh
were not modified to use this functionalityHow can we test changes
pre-commit try-repo https://andrew-glenn/pc-sandbox env-debug
For transparency, here's the
.pre-commit-hooks.yaml
config in my sandbox repohttps://github.com/andrew-glenn/pc-sandbox/blob/abcdad5b40aee08484185451912b8ad191f80138/.pre-commit-hooks.yaml
as well as the script that echo's args passed to it:
https://github.com/andrew-glenn/pc-sandbox/blob/abcdad5b40aee08484185451912b8ad191f80138/env.sh#L1-L19
Modify your local
.pre-commit-config
file to add my sandbox repo, replacingFOO
with an environment variable name of your choice.Example output: