-
Notifications
You must be signed in to change notification settings - Fork 253
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
Nesting 'with' fails #43
Comments
Unfortunately it won't work that way because of the way (instance val) that You don't have to use the nested DSL, 'execute' also accepts all the DSL On Thursday, October 31, 2013, Clinton Blackburn wrote:
Lee Hambleyhttp://lee.hambley.name/ |
Can you provide an example? My code below doesn't work as expected. The final argument seems is ignored. def django_manage(*args)
within release_path do
execute :python, 'manage.py', {:with => {:path => "#{fetch(:virtualenv_dir)}/bin:$PATH"}}
end
end |
I would have expected that to work, it's possible that the hash argument is Lee Hambleyhttp://lee.hambley.name/ On 1 November 2013 14:08, Clinton Blackburn [email protected]:
|
Ok, I've been dealing with this issue a few days now and I've figured out with the help of a colleague, a workaround and also I think there might be a need for a change in the code. What you say above won't actually work. # sshkit / lib / sshkit / backends/abstract.rb
def command(*args)
options = args.extract_options!
SSHKit::Command.new(*[*args, options.merge({in: @pwd.nil? ? nil : File.join(@pwd), env: @env, host: @host, user: @user, group: @group})])
end Right now the options being passed in or overridden by anything from the dsl. If you give an env option right now, nothing will be passed in. It will be overridden by this merge and you'll either get what you had in a with or you get "".If you flip the above merge and put it on the left then the command arg will take precedent. #sshkit / lib / sshkit / backends/abstract.rb
def command(*args)
options = args.extract_options!
SSHKit::Command.new(*[*args, {in: @pwd.nil? ? nil : File.join(@pwd), env: @env, host: @host, user: @user, group: @group}.merge(options)])
end I was about to submit a pull request but wanted to know the intended behaviour before I put together a fix. @leehambley would you like a pull request of this fix it like this? The workaround using the dsl is to simply create a hash in the with like this: on 'google.com' do
with foo: 'foo', bar: 'bar' do
execute :ls, '-al'
end
end |
Should be fixed with PR #345 |
If someone can confirm, I'd be glad to close this. I'll swing by again in a few days and check. |
@leehambley I had a problem during deploy with capistrano and whenever:update_crontab.
I switched to sshkit master branch and the PR #345 that was merged solved my problem. |
@leehambley I echo @ArturT, updating to master fixed it for me. If it helps confirm, here's output with
|
Thanks for verifying! I'll close this issue since it has been fixed by PR #345. I'll release 1.11.0 in a few hours. |
🚢 1.11.0 |
## [1.11.3][] (2016-09-16) * Fix known_hosts caching to match on the entire hostlist [PR #364](capistrano/sshkit#364) @byroot ## [1.11.2][] (2016-07-29) ### Bug fixes * Fixed a crash occurring when `Host@keys` was set to a non-Enumerable. @xavierholt [PR #360](capistrano/sshkit#360) ## [1.11.1][] (2016-06-17) ### Bug fixes * Fixed a regression in 1.11.0 that would cause `ArgumentError: invalid option(s): known_hosts` in some older versions of net-ssh. @byroot [#357](capistrano/sshkit#357) ## [1.11.0][] (2016-06-14) ### Bug fixes * Fixed colorized output alignment in Logger::Pretty. @xavierholt [PR #349](capistrano/sshkit#349) * Fixed a bug that prevented nested `with` calls [#43](capistrano/sshkit#43) ### Other changes * Known hosts lookup optimization is now enabled by default. @byroot ## 1.10.0 (2016-04-22) * You can now opt-in to caching of SSH's known_hosts file for a speed boost when deploying to a large fleet of servers. Refer to the [README](https://github.com/capistrano/sshkit/tree/v1.10.0#known-hosts-caching) for details. We plan to turn this on by default in a future version of SSHKit. [PR #330](capistrano/sshkit#330) @byroot * SSHKit now explicitly closes its pooled SSH connections when Ruby exits; this fixes `zlib(finalizer): the stream was freed prematurely` warnings [PR #343](capistrano/sshkit#343) @mattbrictson * Allow command map entries (`SSHKit::CommandMap#[]`) to be Procs [PR #310](capistrano/sshkit#310) @mikz ## 1.9.0 **Refer to the 1.9.0.rc1 release notes for a full list of new features, fixes, and potentially breaking changes since SSHKit 1.8.1.** There are no changes since 1.9.0.rc1. ## 1.9.0.rc1 ### Potentially breaking changes * The SSHKit DSL is no longer automatically included when you `require` it. **This means you must now explicitly `include SSHKit::DSL`.** See [PR #219](capistrano/sshkit#219) for details. @beatrichartz * `SSHKit::Backend::Printer#test` now always returns true [PR #312](capistrano/sshkit#312) @mikz ### New features * `SSHKit::Formatter::Abstract` now accepts an optional Hash of options [PR #308](capistrano/sshkit#308) @mattbrictson * Add `SSHKit::Backend.current` so that Capistrano plugin authors can refactor helper methods and still have easy access to the currently-executing Backend without having to use global variables. * Add `SSHKit.config.default_runner` options that allows to override default command runner. This option also accepts a name of the custom runner class. * The ConnectionPool has been rewritten in this release to be more efficient and have a cleaner internal API. You can still completely disable the pool by setting `SSHKit::Backend::Netssh.pool.idle_timeout = 0`. @mattbrictson @byroot [PR #328](capistrano/sshkit#328) ### Bug fixes * make sure working directory for commands is properly cleared after `within` blocks [PR #307](capistrano/sshkit#307) @steved * display more accurate string for commands with spaces being output in `Formatter::Pretty` [PR #304](capistrano/sshkit#304) @steved [PR #319](capistrano/sshkit#319) @mattbrictson * Fix a race condition experienced in JRuby that could cause multi-server deploys to fail. [PR #322](capistrano/sshkit#322) @mattbrictson
I have some example code below from my Capistrano v3 tasks for Django. It seems that nesting 'with' calls is broken. Is this functionality supposed to be supported? The docs state "One will notice that it's quite low level, but exposes a convenient API, the as()/within()/with() are nestable in any order, repeatable, and stackable."
My current work around is to wrap the body of with_virtualenv in a begin-rescue block that captures the NameError and check for the message "instance variable @_env not defined".
Note that my intention is to keep the Django and virtualenv tasks in separate files/gems, hence my not simply merging the with calls.
The text was updated successfully, but these errors were encountered: