-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Added #env-vars for adding environmental variables to Drush commands #955
Conversation
…s to generated Drush commands.
Looks pretty good. %env-vars does not contain a path, though, so it should just be |
I'm new to Drush contribution - what's the significance of the percent sign? I'm wondering if it should still have it if I move it higher up in the Site Record. |
You're right -- as a top-level element, it should be '#env-vars'. Truthfully, there isn't a lot of consistency here, but the # will prevent backend invoke from attempting to add env-vars to the remote command as commandline options. The simple fact that this variable is an array would serve the same purpose, really, but still, it is best to not leave it 'naked', so that it does not look like an option. |
The other thing I was just wondering about was, what if someone wanted to define command-specific environment variables? We do not necessarily need to support that; it was just a thought. |
Thanks Greg, I made the change to add #env-vars to the top-level of the site record. As the code is now, users would have to replace the values of the site record temporarily in their call, for example:
Which would override the default value of $site_record['#env-vars']['KEY'] for that call. If there was a Drush hook for modifying commands before they were generated (i.e. hook_drush_build_drush_command) users could more easily add this logic in. |
Is there a way to re-run tests? I'm not sure why the last one failed as I changed almost nothing. |
I had the same question! The Regarding your suggestion vis-a-vis drush_invoke_process, yes, that would work for per-instance changes to environment variables, but I was thinking more along the lines of inserting I don't think that the command-specific mechanism in Drush works in the right way for this to work; the functionality would have to be duplicated in backend invoke. I don't really have a use case at this time, so I think we can just punt on that for now. I'm satisfied with the patch as submitted. |
Re-run the tests. Now it's green. |
Added %env-vars for adding environmental variables to Drush commands
You can rerun the tests if you are sufficiently privileged in Travis.There is a recycle icon whose alt text is 'restart build'. No idea how I can add more admins. Thanks @mortenson. |
Following a discussion in Issue #950, I have added a path-aliases option to add arbitrary environmental variables to generated Drush commands. This is useful for Drush users who have setups that require an environmental variable to be set for every Drush execution.
In my case I needed to send a dynamic variable to the my %drush-script, but there are likely other use cases for this as well. In my example, the %drush-script looks like:
and my site record looks like:
In this example, a dynamic $user is used to run Drush commands. I'm willing to change my approach to this if anyone has any suggestions.