vagrant-exec 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2473ab163ba85fb8cc4d9e802771390a95d977f
4
- data.tar.gz: 4af5e4619102413eaf5ef543f6f848cc991be591
3
+ metadata.gz: 4b89068882edbaa84b37d2ba85e1e590560304f3
4
+ data.tar.gz: 2b75d7b7fddae121d5497ff896883fa02adda639
5
5
  SHA512:
6
- metadata.gz: 886d5a874793ed7a27eadf7830095e12e21ac6f241c63c7ce77d51f476ddbc266e1dbcc0748ae6d680bc8477557ac40b62e286b52965bc831bda5c7710bfcafc
7
- data.tar.gz: 40e06e6cdc5ed0c7a09d6ab93e35b8da76dc23ad6d6cfd6098ffaa64ef2c6108872f708d325c7c348dc25a87a07880587786bf0005b2245dda5faca37b2ed00b
6
+ metadata.gz: a2d2a14a6cdb183e07c4bfec1549a606348e61590b5489ce8914f33cc9d681317eaa301e8abe2fd3b191ae4e102ad55f1f3c329ff9e0a7e2bda6061ca94321fb
7
+ data.tar.gz: 84098dcd483f3ae1c58ec57d7c5830432e146c0bbe89750cea35b19154edee28c8b5ecb5c128a545bb593bda4a2c7e1a728964c7dac1925233d63653de21fcc5
data/CHANGELOG.md ADDED
@@ -0,0 +1,38 @@
1
+ ## 0.5.0 (unreleased)
2
+
3
+ * Added binstubs support
4
+
5
+ ## 0.4.1
6
+
7
+ * Fixed problem with environment variable values containing spaces by wrapping them in quotes
8
+ * Ensured `:prepend` option is added in the end of constructed command
9
+
10
+ ## 0.4.0
11
+
12
+ * Brand new Commands API (#5)
13
+
14
+ ## 0.3.1
15
+
16
+ * Ensure `--` is removed from command (#2)
17
+
18
+ ## 0.3.0
19
+
20
+ * Renamed `:folder` option to `:root`
21
+ * Replaced `:bundler` option with `:prepend_with`
22
+ * Updated to work on Vagrant 1.4.1
23
+
24
+ ## 0.2.1
25
+
26
+ * Changed plugin name from "Vagrant Exec" to "vagrant-exec"
27
+ * Added (dirty) fix to make it work on Vagrant 1.4
28
+ * Added MIT license
29
+
30
+ ## 0.2.0
31
+
32
+ * Added support for exporting environment variables via `config.exec.env`
33
+ * Removed `--machine` switch
34
+ * Fixed handling of `--help` switch
35
+
36
+ ## 0.1.0
37
+
38
+ * Initial release
data/README.md CHANGED
@@ -101,6 +101,48 @@ Vagrant.configure('2') do |config|
101
101
  end
102
102
  ```
103
103
 
104
+ Binstubs
105
+ ----------------
106
+
107
+ It is possible can generate binstubs for all your configured commands. You might want to do this to avoid typing `vagrant exec` every time before command, or if you want integrate your flow in editor (e.g. running tests from editor).
108
+
109
+ Assuming you have the following configuration:
110
+
111
+ ```ruby
112
+ Vagrant.configure('2') do |config|
113
+ config.vm.box = 'precise32'
114
+ config.exec.commands 'bundle'
115
+ config.exec.commands %w(rails rake), prepend: 'bundle exec'
116
+ config.exec.commands %w(rspec cucumber), prepend: 'spring'
117
+ end
118
+ ```
119
+
120
+ You can generate binstubs for each command:
121
+
122
+ ```bash
123
+ ➜ vagrant exec --binstubs
124
+ Generated binstub for bundle in bin/bundle.
125
+ Generated binstub for cucumber in bin/cucumber.
126
+ Generated binstub for rails in bin/rails.
127
+ Generated binstub for rake in bin/rake.
128
+ Generated binstub for rspec in bin/rspec.
129
+ ```
130
+
131
+ Now you can use `bin/cucumber` instead of `vagrant exec cucumber` to execute commands in VM. All your configuration (directory, environment variables, prepend) will still be used.
132
+
133
+ Since binstubs use plain SSH to connect to VM, it creates connection much faster because Vagrant is not invoked:
134
+
135
+ ```bash
136
+ ➜ time bin/echo 1
137
+ 0.28 real
138
+ ➜ time vagrant exec echo 1
139
+ 2.84 real
140
+ ```
141
+
142
+ To make plain SSH work, it saves current SSH configuration of Vagrant to temporary file when you run `vagrant exec --binstubs`. This means that if your VM network configuration has changed (IP address, port), you will have to regenerate binstubs again. So far I had no problems with this, but it's not very convenient for sure.
143
+
144
+ 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.
145
+
104
146
  Testing
105
147
  ----------------
106
148
 
@@ -122,7 +164,7 @@ After you're done, remove Vagrant box.
122
164
  ➜ bundle exec rake features:cleanup
123
165
  ```
124
166
 
125
- To show stduot, add `@announce-stdout` tag to scenario/feature.
167
+ To show stdout, add `@announce-stdout` tag to scenario/feature.
126
168
 
127
169
  Known issues
128
170
  -----------------------------
@@ -6,3 +6,10 @@ Then(/^SHH subprocess should execute command "(.+)"$/) do |command|
6
6
  ssh += ['-q', '-t', "bash -l -c '#{command.delete("''")}'"]
7
7
  assert_partial_output("Executing SSH in subprocess: #{ssh}", all_output)
8
8
  end
9
+
10
+ Then(/^the file "(.+)" should contain result of vagrant ssh-config$/) do |file|
11
+ # since "bundle exec" adds some output, we actually
12
+ # assert that file contents are included in stdout
13
+ step 'I run `bundle exec vagrant ssh-config`'
14
+ with_file_content(file) { |content| expect(all_stdout).to include(content) }
15
+ end
@@ -3,6 +3,7 @@ unless `bundle exec vagrant box list`.include?('vagrant_exec')
3
3
  end
4
4
 
5
5
  require 'aruba/cucumber'
6
+ require 'pry-byebug'
6
7
  ENV['VAGRANT_LOG'] = 'info'
7
8
 
8
9
  Before do
@@ -16,7 +16,13 @@ Feature: vagrant-exec
16
16
 
17
17
  Scenario Outline: shows help correctly
18
18
  When I run `bundle exec vagrant exec <args>`
19
- Then the output should contain "Usage: vagrant exec [options] <command>"
19
+ Then the output should contain:
20
+ """
21
+ Usage: vagrant exec [options] <command>
22
+
23
+ -h, --help Print this help
24
+ --binstubs Generate binstubs for configured commands
25
+ """
20
26
  Examples:
21
27
  | args |
22
28
  | |
@@ -0,0 +1,137 @@
1
+ @no-clobber
2
+ Feature: vagrant-exec binstubs
3
+ In order to easily integrate vagrant-exec into editors/IDEs
4
+ And significantly increase speed of executing commands in VM
5
+ As a user
6
+ I want to be able to generate binstubs for configured commands
7
+ Which use plan SSH
8
+
9
+ Scenario: generates binstubs for each configured command
10
+ Given I write to "Vagrantfile" with:
11
+ """
12
+ Vagrant.configure('2') do |config|
13
+ config.vm.box = 'vagrant_exec'
14
+ config.exec.commands 'echo', directory: '/tmp'
15
+ config.exec.commands %w(pwd echo), prepend: 'test -d . &&', env: { 'TEST' => 1 }
16
+ end
17
+ """
18
+ And I run `bundle exec vagrant up`
19
+ When I run `bundle exec vagrant exec --binstubs`
20
+ Then the exit status should be 0
21
+ And the output should contain "Generated binstub for echo in bin/echo."
22
+ And the output should contain "Generated binstub for pwd in bin/pwd."
23
+ And a file named "bin/echo" should exist
24
+ And a file named "bin/pwd" should exist
25
+ And the mode of filesystem object "bin/echo" should match "755"
26
+ And the mode of filesystem object "bin/pwd" should match "755"
27
+ And the file "bin/echo" should contain exactly:
28
+ """
29
+ #!/bin/bash
30
+ ssh -F .vagrant/ssh_config -q -t default "bash -l -c 'cd /tmp && export TEST=1 && test -d . && echo $@'"
31
+
32
+ """
33
+ And the file "bin/pwd" should contain exactly:
34
+ """
35
+ #!/bin/bash
36
+ ssh -F .vagrant/ssh_config -q -t default "bash -l -c 'cd /vagrant && export TEST=1 && test -d . && pwd $@'"
37
+
38
+ """
39
+ When I run `bin/echo test`
40
+ Then the exit status should be 0
41
+ And the output should contain "test"
42
+ When I run `bin/pwd`
43
+ Then the exit status should be 0
44
+ And the output should contain "/vagrant"
45
+
46
+ Scenario: dumps vagrant ssh-config to file
47
+ Given I write to "Vagrantfile" with:
48
+ """
49
+ Vagrant.configure('2') do |config|
50
+ config.vm.box = 'vagrant_exec'
51
+ config.exec.commands 'echo'
52
+ end
53
+ """
54
+ And I run `bundle exec vagrant up`
55
+ When I run `bundle exec vagrant exec --binstubs`
56
+ Then a file named ".vagrant/ssh_config" should exist
57
+ And the file ".vagrant/ssh_config" should contain result of vagrant ssh-config
58
+
59
+ Scenario: respects configured shell
60
+ Given I write to "Vagrantfile" with:
61
+ """
62
+ Vagrant.configure('2') do |config|
63
+ config.vm.box = 'vagrant_exec'
64
+ config.ssh.shell = 'zsh -l'
65
+ config.exec.commands 'echo'
66
+ end
67
+ """
68
+ And I run `bundle exec vagrant up`
69
+ When I run `bundle exec vagrant exec --binstubs`
70
+ Then the file "bin/echo" should contain exactly:
71
+ """
72
+ #!/bin/bash
73
+ ssh -F .vagrant/ssh_config -q -t default "zsh -l -c 'cd /vagrant && echo $@'"
74
+
75
+ """
76
+
77
+ Scenario: escapes double-quotes in command
78
+ Given I write to "Vagrantfile" with:
79
+ """
80
+ Vagrant.configure('2') do |config|
81
+ config.vm.box = 'vagrant_exec'
82
+ config.exec.commands 'echo', env: { 'TEST' => 'one two' }
83
+ end
84
+ """
85
+ And I run `bundle exec vagrant up`
86
+ When I run `bundle exec vagrant exec --binstubs`
87
+ Then the file "bin/echo" should contain exactly:
88
+ """
89
+ #!/bin/bash
90
+ ssh -F .vagrant/ssh_config -q -t default "bash -l -c 'cd /vagrant && export TEST=\"one two\" && echo $@'"
91
+
92
+ """
93
+
94
+ Scenario: skips if no commands are configured
95
+ Given I write to "Vagrantfile" with:
96
+ """
97
+ Vagrant.configure('2') do |config|
98
+ config.vm.box = 'vagrant_exec'
99
+ end
100
+ """
101
+ And I run `bundle exec vagrant up`
102
+ When I run `bundle exec vagrant exec --binstubs`
103
+ Then the exit status should be 0
104
+ And the output should contain "No commands to generate binstubs for."
105
+
106
+ Scenario: skips if only splat commands are configured
107
+ Given I write to "Vagrantfile" with:
108
+ """
109
+ Vagrant.configure('2') do |config|
110
+ config.vm.box = 'vagrant_exec'
111
+ config.exec.commands '*', env: { 'TEST' => 'one two' }
112
+ end
113
+ """
114
+ And I run `bundle exec vagrant up`
115
+ When I run `bundle exec vagrant exec --binstubs`
116
+ Then the exit status should be 0
117
+ And the output should contain "No commands to generate binstubs for."
118
+
119
+ Scenario: raises if vagrant is not upped
120
+ Given I write to "Vagrantfile" with:
121
+ """
122
+ Vagrant.configure('2') do |config|
123
+ config.vm.box = 'vagrant_exec'
124
+ end
125
+ """
126
+ When I run `bundle exec vagrant exec --binstubs`
127
+ Then the exit status should not be 0
128
+ And the stderr should contain:
129
+ """
130
+ The provider for this Vagrant-managed machine is reporting that it
131
+ is not yet ready for SSH. Depending on your provider this can carry
132
+ different meanings. Make sure your machine is created and running and
133
+ try again. Additionally, check the output of `vagrant status` to verify
134
+ that the machine is in the state that you expect. If you continue to
135
+ get this error message, please view the documentation for the provider
136
+ you're using.
137
+ """
@@ -12,12 +12,12 @@ Feature: vagrant-exec directory
12
12
  config.vm.box = 'vagrant_exec'
13
13
  end
14
14
  """
15
- Given I run `bundle exec vagrant up`
15
+ And I run `bundle exec vagrant up`
16
16
  When I run `bundle exec vagrant exec pwd`
17
17
  Then the exit status should be 0
18
18
  And SHH subprocess should execute command "cd /vagrant && pwd"
19
19
 
20
- Scenario: can use custom directory for all commands
20
+ Scenario: uses custom directory for all commands
21
21
  Given I write to "Vagrantfile" with:
22
22
  """
23
23
  Vagrant.configure('2') do |config|
@@ -30,7 +30,7 @@ Feature: vagrant-exec directory
30
30
  Then the exit status should be 0
31
31
  And SHH subprocess should execute command "cd /tmp && pwd"
32
32
 
33
- Scenario: can use custom directory for specific commands
33
+ Scenario: uses custom directory for specific commands
34
34
  Given I write to "Vagrantfile" with:
35
35
  """
36
36
  Vagrant.configure('2') do |config|
@@ -5,7 +5,7 @@ Feature: vagrant-exec environment variables
5
5
  As a user
6
6
  I should be able to specify them in Vagrantfile
7
7
 
8
- Scenario: can export environment variables for all commands
8
+ Scenario: exports environment variables for all commands
9
9
  Given I write to "Vagrantfile" with:
10
10
  """
11
11
  Vagrant.configure('2') do |config|
@@ -18,7 +18,7 @@ Feature: vagrant-exec environment variables
18
18
  Then the exit status should be 0
19
19
  And SHH subprocess should execute command "cd /vagrant && export TEST1=true && export TEST2=false && pwd"
20
20
 
21
- Scenario: can export environment variables for specific commands
21
+ Scenario: exports environment variables for specific commands
22
22
  Given I write to "Vagrantfile" with:
23
23
  """
24
24
  Vagrant.configure('2') do |config|
@@ -37,7 +37,7 @@ Feature: vagrant-exec environment variables
37
37
  When I run `bundle exec vagrant exec env`
38
38
  Then SHH subprocess should execute command "cd /vagrant && env"
39
39
 
40
- Scenario: can combine environment variables
40
+ Scenario: combines environment variables
41
41
  Given I write to "Vagrantfile" with:
42
42
  """
43
43
  Vagrant.configure('2') do |config|
@@ -5,7 +5,7 @@ Feature: vagrant-exec prepend
5
5
  As a user
6
6
  I should be able to specify it in Vagrantfile
7
7
 
8
- Scenario: can prepend all commands
8
+ Scenario: prepends all commands
9
9
  Given I write to "Vagrantfile" with:
10
10
  """
11
11
  Vagrant.configure('2') do |config|
@@ -18,7 +18,7 @@ Feature: vagrant-exec prepend
18
18
  Then the exit status should be 0
19
19
  And SHH subprocess should execute command "cd /vagrant && echo vagrant-exec && pwd"
20
20
 
21
- Scenario: can prepend specific commands
21
+ Scenario: prepends specific commands
22
22
  Given I write to "Vagrantfile" with:
23
23
  """
24
24
  Vagrant.configure('2') do |config|
@@ -37,7 +37,7 @@ Feature: vagrant-exec prepend
37
37
  When I run `bundle exec vagrant exec env`
38
38
  Then SHH subprocess should execute command "cd /vagrant && env"
39
39
 
40
- Scenario: can combine prepended
40
+ Scenario: combines prepended
41
41
  Given I write to "Vagrantfile" with:
42
42
  """
43
43
  Vagrant.configure('2') do |config|
data/lib/vagrant-exec.rb CHANGED
@@ -2,3 +2,5 @@ require 'vagrant'
2
2
 
3
3
  require 'vagrant-exec/plugin'
4
4
  require 'vagrant-exec/version'
5
+ require 'vagrant-exec/support/command_constructor'
6
+ require 'vagrant-exec/support/ssh_helper'
@@ -2,6 +2,8 @@ module VagrantPlugins
2
2
  module Exec
3
3
  class Command < Vagrant.plugin(2, :command)
4
4
 
5
+ include SSHHelper
6
+
5
7
  def self.synopsis
6
8
  'executes commands in virtual machine'
7
9
  end
@@ -12,36 +14,13 @@ module VagrantPlugins
12
14
 
13
15
  # Execute the actual SSH
14
16
  with_target_vms(nil, single_target: true) do |vm|
15
- settings = vm.config.exec._parsed_commands
16
- passed_command, constructed_command = cmd.dup, ''
17
-
18
- # directory is applied only once in the beginning
19
- settings.reverse.each do |command|
20
- if command_matches?(command[:cmd], passed_command) && !directory_added?
21
- constructed_command << add_directory(command[:opts][:directory])
22
- end
23
- end
24
-
25
- # apply environment variables
26
- settings.each do |command|
27
- if command_matches?(command[:cmd], passed_command)
28
- constructed_command << add_env(command[:opts][:env])
29
- end
30
- end
31
-
32
- # apply prepend in the end
33
- settings.each do |command|
34
- if command_matches?(command[:cmd], passed_command)
35
- constructed_command << add_prepend(command[:opts][:prepend])
36
- end
37
- end
38
-
39
- constructed_command << passed_command
40
- constructed_command << ' ' << cmd_args.join(' ') if cmd_args.any?
17
+ constructor = CommandConstructor.new(cmd, vm.config.exec.commands)
18
+ command = constructor.construct_command
19
+ command << ' ' << cmd_args.join(' ') if cmd_args.any?
41
20
 
42
- @logger.info("Executing single command on remote machine: #{constructed_command}")
21
+ @logger.info("Executing single command on remote machine: #{command}")
43
22
  ssh_opts = { extra_args: ['-q'] } # make it quiet
44
- env = vm.action(:ssh_run, ssh_run_command: constructed_command, ssh_opts: ssh_opts)
23
+ env = vm.action(:ssh_run, ssh_run_command: command, ssh_opts: ssh_opts)
45
24
 
46
25
  status = env[:ssh_run_exit_status] || 0
47
26
  return status
@@ -58,11 +37,19 @@ module VagrantPlugins
58
37
  o.on('-h', '--help', 'Print this help') do
59
38
  safe_puts(opts.help)
60
39
  end
40
+
41
+ o.on('--binstubs', 'Generate binstubs for configured commands')
61
42
  end
62
43
 
63
44
  argv = split_main_and_subcommand(@argv.dup)
64
45
  exec_args, cmd, cmd_args = argv[0], argv[1], argv[2]
65
46
 
47
+ # generate binstubs
48
+ if exec_args.include?('--binstubs')
49
+ generate_binstubs
50
+ return nil
51
+ end
52
+
66
53
  # show help
67
54
  if !cmd || exec_args.any? { |a| a == '-h' || a == '--help' }
68
55
  safe_puts(opts.help)
@@ -76,36 +63,51 @@ module VagrantPlugins
76
63
  return cmd, cmd_args
77
64
  end
78
65
 
79
- def add_directory(directory)
80
- ''.tap do |str|
81
- if directory
82
- str << "cd #{directory} && "
83
- @directory_added = true
66
+ def generate_binstubs
67
+ with_target_vms(nil, single_target: true) do |vm|
68
+ save_ssh_config(vm.name, vm.ssh_info)
69
+
70
+ commands = vm.config.exec.commands
71
+
72
+ explicit = commands.select { |command| command[:cmd] != '*' }
73
+ .map { |command| command[:cmd] }
74
+ .flatten
75
+ .uniq
76
+
77
+ if explicit.empty?
78
+ vm.env.ui.error('No commands to generate binstubs for.')
79
+ return nil
84
80
  end
85
- end
86
- end
87
81
 
88
- def add_env(env)
89
- ''.tap do |str|
90
- env.each do |key, value|
91
- value = %("#{value}") if value.is_a?(String) && value.include?(' ')
92
- str << "export #{key}=#{value} && "
93
- end if env
94
- end
95
- end
82
+ explicit = explicit.map do |command|
83
+ {
84
+ command: command,
85
+ constructed: CommandConstructor.new(command, commands).construct_command
86
+ }
87
+ end
96
88
 
97
- def add_prepend(prep)
98
- ''.tap do |str|
99
- str << "#{prep.strip} " if prep
100
- end
101
- end
89
+ shell = vm.config.ssh.shell
102
90
 
103
- def command_matches?(expected, actual)
104
- expected =='*' || expected == actual || expected.include?(actual)
105
- end
91
+ Dir.mkdir('bin') unless Dir.exist?('bin')
92
+ explicit.each do |command|
93
+ command[:constructed].gsub!('"', '\"') # escape double-quotes
94
+
95
+ variables = {
96
+ ssh_config: SSH_CONFIG,
97
+ shell: shell,
98
+ command: command[:constructed],
99
+ }
100
+ variables.merge!(template_root: "#{File.dirname(__FILE__)}/templates")
101
+
102
+ binstub = Vagrant::Util::TemplateRenderer.render('binstub', variables)
106
103
 
107
- def directory_added?
108
- !!@directory_added
104
+ filename = "bin/#{command[:command]}"
105
+ File.open(filename, 'w') { |file| file.write binstub }
106
+ File.chmod(0755, filename)
107
+
108
+ vm.env.ui.success("Generated binstub for #{command[:command]} in #{filename}.")
109
+ end
110
+ end
109
111
  end
110
112
 
111
113
  end # Command
@@ -14,17 +14,27 @@ module VagrantPlugins
14
14
  end
15
15
 
16
16
  #
17
- # Configures commands.
17
+ # Retrieve or add command.
18
18
  #
19
- # @param cmd [String, Array<String>]
20
- # @param opts [Hash]
21
- # @option opts [String] :directory Directory to execute commands in
22
- # @option opts [String] :prepend Command to prepend with
23
- # @option opts [Hash] :env Environmental variables to export
19
+ # @overload commands
20
+ # Returns array of commands and all their options
24
21
  #
25
- def commands(cmd, opts = {})
22
+ # @overload commands(command, options)
23
+ # Configures command with options.
24
+ # @param command [String, Array<String>]
25
+ # @param opts [Hash]
26
+ # @option opts [String] :directory Directory to execute commands in
27
+ # @option opts [String] :prepend Command to prepend with
28
+ # @option opts [Hash] :env Environmental variables to export
29
+ #
30
+ def commands(*args)
26
31
  @commands = [] if @commands == UNSET_VALUE
27
- @commands << { cmd: cmd, opts: opts }
32
+
33
+ if args.empty?
34
+ @commands
35
+ else
36
+ @commands << { cmd: args[0], opts: args[1] || {} }
37
+ end
28
38
  end
29
39
 
30
40
  def validate(_)
@@ -66,11 +76,6 @@ module VagrantPlugins
66
76
  end
67
77
  end
68
78
 
69
- # @api private
70
- def _parsed_commands
71
- @commands
72
- end
73
-
74
79
  private
75
80
 
76
81
  def array_of_strings?(array)
@@ -0,0 +1,74 @@
1
+ module VagrantPlugins
2
+ module Exec
3
+ class CommandConstructor
4
+
5
+ def initialize(command, config)
6
+ @command = command.dup
7
+ @config = config
8
+ end
9
+
10
+ def construct_command
11
+ ''.tap do |constructed_command|
12
+ # directory is applied only once in the beginning
13
+ @config.reverse.each do |command|
14
+ if command_matches?(command[:cmd], @command) && !directory_added?
15
+ constructed_command << add_directory(command[:opts][:directory])
16
+ end
17
+ end
18
+
19
+ # apply environment variables
20
+ @config.each do |command|
21
+ if command_matches?(command[:cmd], @command)
22
+ constructed_command << add_env(command[:opts][:env])
23
+ end
24
+ end
25
+
26
+ # apply prepend in the end
27
+ @config.each do |command|
28
+ if command_matches?(command[:cmd], @command)
29
+ constructed_command << add_prepend(command[:opts][:prepend])
30
+ end
31
+ end
32
+
33
+ constructed_command << @command
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def add_directory(directory)
40
+ ''.tap do |str|
41
+ if directory
42
+ str << "cd #{directory} && "
43
+ @directory_added = true
44
+ end
45
+ end
46
+ end
47
+
48
+ def add_env(env)
49
+ ''.tap do |str|
50
+ env.each do |key, value|
51
+ value = %("#{value}") if value.is_a?(String) && value.include?(' ')
52
+ str << "export #{key}=#{value} && "
53
+ end if env
54
+ end
55
+ end
56
+
57
+ def add_prepend(prep)
58
+ ''.tap do |str|
59
+ str << "#{prep.strip} " if prep
60
+ end
61
+ end
62
+
63
+ def command_matches?(expected, actual)
64
+ expected == '*' || expected == actual || expected.include?(actual)
65
+ end
66
+
67
+
68
+ def directory_added?
69
+ !!@directory_added
70
+ end
71
+
72
+ end # CommandConstructor
73
+ end # Exec
74
+ end # VagrantPlugins
@@ -0,0 +1,32 @@
1
+ module VagrantPlugins
2
+ module Exec
3
+ module SSHHelper
4
+
5
+ SSH_CONFIG = '.vagrant/ssh_config'.freeze
6
+
7
+ private
8
+
9
+ # @todo Pretty much copy-paste of vagrant 'plugins/commands/ssh_config'
10
+ def save_ssh_config(host, ssh_info)
11
+ raise Vagrant::Errors::SSHNotReady if ssh_info.nil?
12
+
13
+ variables = {
14
+ host_key: host || "vagrant",
15
+ ssh_host: ssh_info[:host],
16
+ ssh_port: ssh_info[:port],
17
+ ssh_user: ssh_info[:username],
18
+ private_key_path: ssh_info[:private_key_path],
19
+ forward_agent: ssh_info[:forward_agent],
20
+ forward_x11: ssh_info[:forward_x11],
21
+ proxy_command: ssh_info[:proxy_command]
22
+ }
23
+
24
+ template = 'commands/ssh_config/config'
25
+ config = Vagrant::Util::TemplateRenderer.render(template, variables)
26
+
27
+ File.open(SSH_CONFIG, 'w') { |file| file.write(config) }
28
+ end
29
+
30
+ end # SSHHelper
31
+ end # Exec
32
+ end # VagrantPlugins
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ ssh -F <%= ssh_config %> -q -t default "<%= shell %> -c '<%= command %> $@'"
@@ -1,7 +1,7 @@
1
1
  module VagrantPlugins
2
2
  module Exec
3
3
 
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.0'
5
5
 
6
6
  end # Exec
7
7
  end # VagrantPlugins
data/vagrant-exec.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- $:.push File.expand_path("../lib", __FILE__)
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
2
  require 'vagrant-exec/version'
3
3
 
4
4
  Gem::Specification.new do |s|
@@ -14,9 +14,10 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
18
  s.require_paths = %w(lib)
19
19
 
20
20
  s.add_development_dependency 'aruba'
21
21
  s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'pry-byebug'
22
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-exec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rodionov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-16 00:00:00.000000000 Z
11
+ date: 2014-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Vagrant plugin to execute commands within the context of VM synced folder
42
56
  email: p0deje@gmail.com
43
57
  executables: []
@@ -45,6 +59,7 @@ extensions: []
45
59
  extra_rdoc_files: []
46
60
  files:
47
61
  - ".gitignore"
62
+ - CHANGELOG.md
48
63
  - Gemfile
49
64
  - LICENSE.md
50
65
  - README.md
@@ -53,6 +68,7 @@ files:
53
68
  - features/step_definitions/steps.rb
54
69
  - features/support/env.rb
55
70
  - features/vagrant-exec.feature
71
+ - features/vagrant-exec/binstubs.feature
56
72
  - features/vagrant-exec/directory.feature
57
73
  - features/vagrant-exec/environment_variables.feature
58
74
  - features/vagrant-exec/prepend.feature
@@ -61,6 +77,9 @@ files:
61
77
  - lib/vagrant-exec/command.rb
62
78
  - lib/vagrant-exec/config.rb
63
79
  - lib/vagrant-exec/plugin.rb
80
+ - lib/vagrant-exec/support/command_constructor.rb
81
+ - lib/vagrant-exec/support/ssh_helper.rb
82
+ - lib/vagrant-exec/templates/binstub.erb
64
83
  - lib/vagrant-exec/version.rb
65
84
  - vagrant-exec.gemspec
66
85
  homepage: http://github.com/p0deje/vagrant-exec
@@ -91,6 +110,7 @@ test_files:
91
110
  - features/step_definitions/steps.rb
92
111
  - features/support/env.rb
93
112
  - features/vagrant-exec.feature
113
+ - features/vagrant-exec/binstubs.feature
94
114
  - features/vagrant-exec/directory.feature
95
115
  - features/vagrant-exec/environment_variables.feature
96
116
  - features/vagrant-exec/prepend.feature