vagrant-exec 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2013 Alex Rodionov
1
+ Copyright (c) 2013 Alex Rodionov
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -17,7 +17,7 @@ Example
17
17
  ```
18
18
 
19
19
  Installation
20
- -------
20
+ ------------
21
21
 
22
22
  ```shell
23
23
  ➜ vagrant plugin install vagrant-exec
@@ -26,6 +26,8 @@ Installation
26
26
  Configuration
27
27
  -------------
28
28
 
29
+ ### Custom folder
30
+
29
31
  The root directory can be configured using Vagrantfile.
30
32
 
31
33
  ```ruby
@@ -38,10 +40,12 @@ end
38
40
  ```shell
39
41
  ➜ vagrant exec pwd
40
42
  # is the same as
41
- ➜ vagrant ssh -c "cd /custom && bundle exec pwd'
43
+ ➜ vagrant ssh -c "cd /custom && bundle exec pwd"
42
44
  ```
43
45
 
44
- You can also enable bundler to prepend each command with `bundle exec` (note, that it won't be done for commands like `bundle install`).
46
+ ### Bundler
47
+
48
+ You can enable bundler to prepend each command with `bundle exec`. Note that it won't be done for commands starting with `bundle` (e.g. `bundle install`).
45
49
 
46
50
  ```ruby
47
51
  Vagrant.configure('2') do |config|
@@ -53,14 +57,16 @@ end
53
57
  ```shell
54
58
  ➜ vagrant exec pwd
55
59
  # is the same as
56
- ➜ vagrant ssh -c "cd /vagrant && bundle exec pwd'
60
+ ➜ vagrant ssh -c "cd /vagrant && bundle exec pwd"
57
61
 
58
62
  ➜ vagrant exec bundle install
59
63
  # is the same as
60
- ➜ vagrant ssh -c "cd /vagrant && bundle install'
64
+ ➜ vagrant ssh -c "cd /vagrant && bundle install"
61
65
  ```
62
66
 
63
- You can also add environment variables to be exported before.
67
+ ### Environment variables
68
+
69
+ You can add environment variables to be exported before.
64
70
 
65
71
  ```ruby
66
72
  Vagrant.configure('2') do |config|
@@ -73,7 +79,7 @@ end
73
79
  ```shell
74
80
  ➜ vagrant exec pwd
75
81
  # is the same as
76
- ➜ vagrant ssh -c "cd /vagrant && export RAILS_ENV=test && export RAILS_ROOT=/vagrant && pwd'
82
+ ➜ vagrant ssh -c "cd /vagrant && export RAILS_ENV=test && export RAILS_ROOT=/vagrant && pwd"
77
83
  ```
78
84
 
79
85
  Acceptance tests
@@ -83,6 +89,11 @@ Before running features, you'll need to bootstrap box.
83
89
 
84
90
  ```shell
85
91
  ➜ bundle exec rake features:bootstrap
92
+ ```
93
+
94
+ To run features, execute the following rake task.
95
+
96
+ ```shell
86
97
  ➜ bundle exec rake features:run
87
98
  ```
88
99
 
data/Rakefile CHANGED
@@ -5,14 +5,14 @@ Bundler::GemHelper.install_tasks
5
5
  namespace :features do
6
6
  desc 'Downloads and adds vagrant box for testing.'
7
7
  task(:bootstrap) do
8
- system('bundle exec vagrant box add vagrant_exec http://files.vagrantup.com/precise32.box')
8
+ system('bundle exec vagrant box add vagrant_exec http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box')
9
9
  end
10
10
 
11
11
  Cucumber::Rake::Task.new(:run) do |t|
12
12
  t.cucumber_opts = %w(--format pretty)
13
13
  end
14
14
 
15
- desc 'Removes testing vagrant box .'
15
+ desc 'Removes testing vagrant box.'
16
16
  task(:cleanup) do
17
17
  system('bundle exec vagrant destroy -f')
18
18
  system('bundle exec vagrant box remove vagrant_exec virtualbox')
@@ -16,14 +16,14 @@ Feature: vagrant-exec
16
16
  Given I run `bundle exec vagrant up`
17
17
  When I run `bundle exec vagrant exec pwd`
18
18
  Then the exit status should be 0
19
- And the output should contain "Executing single command on remote machine: cd /vagrant && pwd"
19
+ And the output should contain "Executing single command on remote machine: source ~/.profile && cd /vagrant && pwd"
20
20
 
21
21
  Scenario: can use custom folder
22
22
  Given I set vagrant-exec folder to "/tmp"
23
23
  And I run `bundle exec vagrant up`
24
24
  When I run `bundle exec vagrant exec pwd`
25
25
  Then the exit status should be 0
26
- And the output should contain "Executing single command on remote machine: cd /tmp && pwd"
26
+ And the output should contain "Executing single command on remote machine: source ~/.profile && cd /tmp && pwd"
27
27
 
28
28
  Scenario: raises error if folder is improperly set
29
29
  Given I set vagrant-exec folder to true
@@ -42,13 +42,13 @@ Feature: vagrant-exec
42
42
  And I run `bundle exec vagrant up`
43
43
  When I run `bundle exec vagrant exec pwd`
44
44
  Then the exit status should not be 0
45
- And the output should contain "Executing single command on remote machine: cd /vagrant && bundle exec pwd"
45
+ And the output should contain "Executing single command on remote machine: source ~/.profile && cd /vagrant && bundle exec pwd"
46
46
 
47
47
  Scenario: does not use bundler for bundle commands
48
48
  Given I set vagrant-exec bundler to true
49
49
  And I run `bundle exec vagrant up`
50
50
  When I run `bundle exec vagrant exec bundle install`
51
- Then the output should contain "Executing single command on remote machine: cd /vagrant && bundle install"
51
+ Then the output should contain "Executing single command on remote machine: source ~/.profile && cd /vagrant && bundle install"
52
52
 
53
53
  Scenario: raises error if bundler is improperly set
54
54
  Given I set vagrant-exec bundler to "true"
@@ -64,7 +64,7 @@ Feature: vagrant-exec
64
64
  And I run `bundle exec vagrant up`
65
65
  When I run `bundle exec vagrant exec pwd`
66
66
  Then the exit status should be 0
67
- And the output should contain "Executing single command on remote machine: cd /vagrant && export TEST1=true && export TEST2=false && pwd"
67
+ And the output should contain "Executing single command on remote machine: source ~/.profile && cd /vagrant && export TEST1=true && export TEST2=false && pwd"
68
68
 
69
69
  Scenario Outline: shows help correctly
70
70
  Given I run `bundle exec vagrant up`
@@ -81,7 +81,7 @@ Feature: vagrant-exec
81
81
  Scenario Outline: passes command arguments correctly
82
82
  Given I run `bundle exec vagrant up`
83
83
  When I run `bundle exec vagrant exec <cmd>`
84
- Then the output should contain "Executing single command on remote machine: cd /vagrant && <cmd>"
84
+ Then the output should contain "Executing single command on remote machine: source ~/.profile && cd /vagrant && <cmd>"
85
85
  Examples:
86
86
  | cmd |
87
87
  | cwd . |
@@ -3,6 +3,32 @@ module VagrantPlugins
3
3
  class Command < Vagrant.plugin(2, :command)
4
4
 
5
5
  def execute
6
+ cmd, cmd_args = parse_args
7
+ cmd && cmd_args or return nil
8
+
9
+ # Execute the actual SSH
10
+ with_target_vms(nil, single_target: true) do |vm|
11
+ vm.config.exec.finalize! # TODO: do we have to call it explicitly?
12
+
13
+ plain = "#{cmd} " << cmd_args.join(' ')
14
+
15
+ command = "source ~/.profile && "
16
+ command << "cd #{vm.config.exec.folder} && "
17
+ command << add_env(vm.config.exec.env)
18
+ command << add_bundler(vm.config.exec.bundler, plain)
19
+ command << plain
20
+
21
+ @logger.info("Executing single command on remote machine: #{command}")
22
+ env = vm.action(:ssh_run, ssh_run_command: command)
23
+
24
+ status = env[:ssh_run_exit_status] || 0
25
+ return status
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def parse_args
6
32
  opts = OptionParser.new do |o|
7
33
  o.banner = 'Usage: vagrant exec [options] <command>'
8
34
  o.separator ''
@@ -21,31 +47,24 @@ module VagrantPlugins
21
47
  return nil
22
48
  end
23
49
 
24
- # Execute the actual SSH
25
- with_target_vms(nil, single_target: true) do |vm|
26
- vm.config.exec.finalize! # TODO: do we have to call it explicitly?
27
-
28
- plain = "#{cmd} " << cmd_args.join(' ')
29
- command = "cd #{vm.config.exec.folder} && "
50
+ return cmd, cmd_args
51
+ end
30
52
 
31
- env = vm.config.exec.env
53
+ def add_env(env)
54
+ ''.tap do |command|
32
55
  if env.any?
33
56
  env.each do |key, value|
34
57
  command << "export #{key}=#{value} && "
35
58
  end
36
59
  end
60
+ end
61
+ end
37
62
 
38
- if vm.config.exec.bundler && !(plain =~ /^bundle /)
63
+ def add_bundler(bundler, plain_command)
64
+ ''.tap do |command|
65
+ if bundler && plain_command !~ /^bundle /
39
66
  command << 'bundle exec '
40
67
  end
41
-
42
- command << plain
43
-
44
- @logger.info("Executing single command on remote machine: #{command}")
45
- env = vm.action(:ssh_run, ssh_run_command: command)
46
-
47
- status = env[:ssh_run_exit_status] || 0
48
- return status
49
68
  end
50
69
  end
51
70
 
@@ -2,7 +2,7 @@ module VagrantPlugins
2
2
  module Exec
3
3
  class Plugin < Vagrant.plugin(2)
4
4
 
5
- name 'Vagrant Exec'
5
+ name 'vagrant-exec'
6
6
  description 'Plugin allows to execute commands within the context of synced folder.'
7
7
 
8
8
  config :exec do
@@ -1,7 +1,7 @@
1
1
  module VagrantPlugins
2
2
  module Exec
3
3
 
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
 
6
6
  end # Exec
7
7
  end # VagrantPlugins
data/vagrant-exec.gemspec CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = 'http://github.com/p0deje/vagrant-exec'
11
11
  s.summary = 'Execute commands in Vagrant synced folder'
12
12
  s.description = 'Vagrant plugin to execute commands within the context of VM synced folder'
13
+ s.license = 'MIT'
13
14
 
14
15
  s.files = `git ls-files`.split("\n")
15
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-exec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-16 00:00:00.000000000 Z
12
+ date: 2013-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aruba
@@ -63,7 +63,8 @@ files:
63
63
  - lib/vagrant-exec/version.rb
64
64
  - vagrant-exec.gemspec
65
65
  homepage: http://github.com/p0deje/vagrant-exec
66
- licenses: []
66
+ licenses:
67
+ - MIT
67
68
  post_install_message:
68
69
  rdoc_options: []
69
70
  require_paths:
@@ -76,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
77
  version: '0'
77
78
  segments:
78
79
  - 0
79
- hash: 1395843341620425617
80
+ hash: 657150828523853671
80
81
  required_rubygems_version: !ruby/object:Gem::Requirement
81
82
  none: false
82
83
  requirements:
@@ -85,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
86
  version: '0'
86
87
  segments:
87
88
  - 0
88
- hash: 1395843341620425617
89
+ hash: 657150828523853671
89
90
  requirements: []
90
91
  rubyforge_project:
91
92
  rubygems_version: 1.8.23