Skip to content

Commit

Permalink
Allow to configure binstubs path. Closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed Feb 10, 2015
1 parent 00e6d21 commit 2b8a3a8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -143,6 +143,15 @@ To make plain SSH work, it saves current SSH configuration of Vagrant to tempora
Moving forward, you can use projects like [direnv](https://github.com/zimbatm/direnv) to add `bin/` to `PATH` and completely forget that you have VM running.
It is also possible to configure binstubs directory (e.g. default `bin/` collides with Rails binstubs):
```ruby
Vagrant.configure('2') do |config|
config.vm.box = 'precise32'
config.exec.binstubs_path = 'vbin'
end
```
Testing
----------------
Expand Down
17 changes: 16 additions & 1 deletion features/vagrant-exec/binstubs.feature
Expand Up @@ -88,6 +88,21 @@ Feature: vagrant-exec binstubs
"""

Scenario: respects configured binstubs directory
Given I write to "Vagrantfile" with:
"""
Vagrant.configure('2') do |config|
config.vm.box = 'vagrant_exec'
config.exec.binstubs_path = 'vbin'
config.exec.commands 'test'
end
"""
And I run `bundle exec vagrant up`
When I run `bundle exec vagrant exec --binstubs`
Then the output should contain "Generated binstub for test in vbin/test."
And a file named "vbin/test" should exist
But a file named "bin/test" should not exist

Scenario: escapes double-quotes in command
Given I write to "Vagrantfile" with:
"""
Expand Down Expand Up @@ -130,7 +145,7 @@ Feature: vagrant-exec binstubs
Then the exit status should be 0
And the output should contain "No commands to generate binstubs for."

Scenario: raises if vagrant is not upped
Scenario: raises if vagrant is not up
Given I write to "Vagrantfile" with:
"""
Vagrant.configure('2') do |config|
Expand Down
8 changes: 4 additions & 4 deletions lib/vagrant-exec/command.rb
Expand Up @@ -86,23 +86,23 @@ def generate_binstubs
}
end

shell = vm.config.ssh.shell
binstubs_path = vm.config.exec.binstubs_path
Dir.mkdir(binstubs_path) unless Dir.exist?(binstubs_path)

Dir.mkdir('bin') unless Dir.exist?('bin')
explicit.each do |command|
command[:constructed].gsub!('"', '\"') # escape double-quotes

variables = {
ssh_host: vm.name || 'default',
ssh_config: SSH_CONFIG,
shell: shell,
shell: vm.config.ssh.shell,
command: command[:constructed],
}
variables.merge!(template_root: "#{File.dirname(__FILE__)}/templates")

binstub = Vagrant::Util::TemplateRenderer.render('binstub', variables)

filename = "bin/#{command[:command]}"
filename = [binstubs_path, command[:command]].join('/')
File.open(filename, 'w') { |file| file.write binstub }
File.chmod(0755, filename)

Expand Down
5 changes: 5 additions & 0 deletions lib/vagrant-exec/config.rb
Expand Up @@ -9,7 +9,10 @@ class Config < Vagrant.plugin(2, :config)
}
}.freeze

attr_accessor :binstubs_path

def initialize
@binstubs_path = UNSET_VALUE
@commands = UNSET_VALUE
end

Expand Down Expand Up @@ -65,6 +68,8 @@ def validate(_)
end

def finalize!
@binstubs_path = 'bin' if @binstubs_path == UNSET_VALUE

if @commands == UNSET_VALUE
@commands = [DEFAULT_SETTINGS.dup]
else
Expand Down

0 comments on commit 2b8a3a8

Please sign in to comment.