vagrant-triggers 0.2.1 → 0.2.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66df1e94338bdbd5b8ea22fa123abc641dbc9e05
4
+ data.tar.gz: 1310d39fe9e67faaac2a2784b6ed841939a7092e
5
+ SHA512:
6
+ metadata.gz: 3cd9b20a5e2fdb1f15c702502f008fb89afbb91d3685874c4270bde7000bce13cb44506203085c5e651af3d9900dd655c01743e13bed877c6134b7773c39e7cf
7
+ data.tar.gz: 600308d8966f0b35fba1c2a17698382ecce0c80054f02103374124144f94345a4e560a301ce47ef97f3bdc85fd90bd99351470dd4c38f7580b3e3fb46b02dab5
data/.gitignore CHANGED
@@ -4,6 +4,8 @@
4
4
  pkg/*
5
5
  Gemfile.lock
6
6
 
7
+ coverage
8
+
7
9
  .rspec
8
10
 
9
11
  .vagrant
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ env:
5
+ - VAGRANT_VERSION=v1.4.3
6
+ matrix:
7
+ include:
8
+ - env: VAGRANT_VERSION=v1.3.5
9
+ rvm: 1.9.3
10
+ - env: VAGRANT_VERSION=v1.2.7
11
+ rvm: 1.9.3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.2.2 (unreleased)
2
+
3
+ NEW FEATURES:
4
+
5
+ - Add ```:info``` as an alternative to ```:execute```.
6
+
7
+ BUG FIXES:
8
+
9
+ - Remove Vagrant specific environment variables when executing commands [(#5)](https://github.com/emyl/vagrant-triggers/issues/2)
10
+
1
11
  ## 0.2.1 (November 19, 2013)
2
12
 
3
13
  BUG FIXES:
data/Gemfile CHANGED
@@ -3,5 +3,9 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
6
+ gem "vagrant", :github => "mitchellh/vagrant", :ref => ENV.fetch("VAGRANT_VERSION", "v1.4.3")
7
+ end
8
+
9
+ group :test do
10
+ gem "simplecov", :require => false
7
11
  end
data/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # vagrant-triggers
2
2
 
3
+ [![Build Status](https://travis-ci.org/emyl/vagrant-triggers.png?branch=master)](https://travis-ci.org/emyl/vagrant-triggers)
4
+
3
5
  Allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands.
4
6
 
5
7
  ## Installation
6
8
 
7
- Ensure you have downloaded and installed Vagrant from the
9
+ Ensure you have downloaded and installed Vagrant 1.2+ from the
8
10
  [Vagrant downloads page](http://downloads.vagrantup.com/).
9
11
 
10
- Installation is performed in the prescribed manner for Vagrant 1.1+ plugins.
12
+ Installation is performed in the prescribed manner for Vagrant plugins:
11
13
 
12
14
  $ vagrant plugin install vagrant-triggers
13
15
 
@@ -30,6 +32,8 @@ The first argument is the command in which the trigger will be tied. It could be
30
32
  ### Options
31
33
 
32
34
  * ```:execute => "script"```: the script to execute
35
+ * ```:info => "string"```: an informational message to be displayed, instead of executing a command. This is only displayed if :execute is not set.
36
+
33
37
  * ```:append_to_path => ["dir", "dir"]```: additional places where looking for the script. See [this wiki page](https://github.com/emyl/vagrant-triggers/wiki/The-:append_to_path-option) for details.
34
38
  * ```:force => true```: continue even if the script fails (exits with non-zero code)
35
39
  * ```:stdout => true```: display script output
@@ -53,7 +57,7 @@ Vagrant.configure("2") do |config|
53
57
  }.each do |command, trigger|
54
58
  config.trigger.before command, :execute => "vboxmanage #{trigger}", :stdout => true
55
59
  end
56
-
60
+
57
61
  end
58
62
  ```
59
63
 
@@ -15,30 +15,36 @@ module VagrantPlugins
15
15
 
16
16
  def call(env)
17
17
  fire_triggers
18
-
18
+
19
19
  # Carry on
20
20
  @app.call(env)
21
21
  end
22
22
 
23
+ private
24
+
25
+ def build_environment
26
+ @logger.debug("Original environment: #{ENV.inspect}")
27
+
28
+ # Remove GEM_ environment variables
29
+ ["GEM_HOME", "GEM_PATH", "GEMRC"].each { |gem_var| ENV.delete(gem_var) }
30
+
31
+ # Create the new PATH removing Vagrant bin directory
32
+ # and appending directories specified through the
33
+ # :append_to_path option
34
+ new_path = ENV["VAGRANT_INSTALLER_ENV"] ? ENV["PATH"].gsub(/#{ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]}.*?#{File::PATH_SEPARATOR}/, "") : ENV["PATH"]
35
+ new_path += Array(@options[:append_to_path]).map { |dir| "#{File::PATH_SEPARATOR}#{dir}" }.join
36
+ ENV["PATH"] = new_path
37
+ @logger.debug("PATH modifed: #{ENV["PATH"]}")
38
+ end
39
+
23
40
  def execute(raw_command)
24
41
  @env[:ui].info 'Executing command "' + raw_command + '"...'
25
42
  command = Shellwords.shellsplit(raw_command)
26
43
  env_backup = ENV.to_hash
27
44
  begin
45
+ build_environment
28
46
  result = Vagrant::Util::Subprocess.execute(command[0], *command[1..-1])
29
47
  rescue Vagrant::Errors::CommandUnavailable, Vagrant::Errors::CommandUnavailableWindows
30
- @logger.debug("Command not found in the path.")
31
- @logger.debug("Current PATH: #{ENV["PATH"]}")
32
- new_path = Array(@options[:append_to_path]).join(File::PATH_SEPARATOR)
33
- @logger.debug("Temporary replacing the system PATH with #{new_path}.")
34
- unless new_path.empty?
35
- new_env = env_backup.dup
36
- new_env.delete("PATH")
37
- new_env["PATH"] = new_path
38
- ENV.replace(new_env)
39
- @options[:append_to_path] = nil
40
- retry
41
- end
42
48
  raise Errors::CommandUnavailable, :command => command[0]
43
49
  ensure
44
50
  ENV.replace(env_backup)
@@ -65,6 +71,8 @@ module VagrantPlugins
65
71
  @options = trigger[:options]
66
72
  if @options[:execute]
67
73
  execute(@options[:execute])
74
+ elsif @options[:info]
75
+ @env[:ui].info @options[:info]
68
76
  else
69
77
  @logger.debug("Trigger command not found.")
70
78
  end
@@ -74,4 +82,4 @@ module VagrantPlugins
74
82
  end
75
83
  end
76
84
  end
77
- end
85
+ end
@@ -1,12 +1,6 @@
1
- begin
2
- require "vagrant"
3
- rescue LoadError
4
- raise "The Vagrant Triggers plugin must be run within Vagrant."
5
- end
6
-
7
1
  # This is a sanity check to make sure no one is attempting to install
8
2
  # this into an early Vagrant version.
9
- if Vagrant::VERSION < "1.1.0"
3
+ if Vagrant::VERSION < "1.2.0"
10
4
  raise "The Vagrant Triggers plugin is only compatible with Vagrant 1.1+"
11
5
  end
12
6
 
@@ -28,7 +22,7 @@ module VagrantPlugins
28
22
  hook.append(Action.action_trigger(:after))
29
23
  end
30
24
  end
31
-
25
+
32
26
  config(:trigger) do
33
27
  require_relative "config"
34
28
  Config
@@ -42,4 +36,4 @@ module VagrantPlugins
42
36
  end
43
37
  end
44
38
  end
45
- end
39
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Triggers
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
- end
5
+ end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,5 @@
1
- require_relative "../lib/vagrant-triggers"
1
+ require "simplecov"
2
+ SimpleCov.start
3
+
4
+ require "vagrant"
5
+ require_relative "../lib/vagrant-triggers"
@@ -1,6 +1,5 @@
1
+ require "fileutils"
1
2
  require "spec_helper"
2
- require "vagrant/util/platform"
3
- require "vagrant/util/subprocess"
4
3
 
5
4
  describe VagrantPlugins::Triggers::Action::Trigger do
6
5
  let(:app) { lambda { |env| } }
@@ -80,6 +79,13 @@ describe VagrantPlugins::Triggers::Action::Trigger do
80
79
  result.stub(:exit_code => 1)
81
80
  expect { described_class.new(app, env, condition).call(env) }.not_to raise_error()
82
81
  end
82
+
83
+ it "should display output if :stdout option was specified" do
84
+ @triggers[0][:options][:stdout] = true
85
+ result.stub(:stdout => "Some output")
86
+ ui.should_receive(:info).with("Command output:\n\nSome output\n")
87
+ described_class.new(app, env, condition).call(env)
88
+ end
83
89
  end
84
90
 
85
91
  context "with a command not in the PATH" do
@@ -115,4 +121,62 @@ describe VagrantPlugins::Triggers::Action::Trigger do
115
121
  expect { described_class.new(app, env, condition).call(env) }.not_to raise_error()
116
122
  end
117
123
  end
118
- end
124
+
125
+ context "within the Vagrant environment" do
126
+ before do
127
+ @original_path = ENV["PATH"]
128
+ ENV["EMBEDDED_DIR"] = Vagrant::Util::Platform.windows? ? ENV["USERPROFILE"] : ENV["HOME"]
129
+ ENV["GEM_HOME"] = "#{ENV["EMBEDDED_DIR"]}/gems"
130
+ ENV["GEM_PATH"] = ENV["GEM_HOME"]
131
+ ENV["GEMRC"] = "#{ENV["EMBEDDED_DIR"]}/etc/gemrc"
132
+ ENV["PATH"] = "#{ENV["EMBEDDED_DIR"]}/bin:#{ENV["PATH"]}"
133
+ end
134
+
135
+ context "with a command which is present into the Vagrant embedded dir" do
136
+ before do
137
+ Dir.mkdir("#{ENV["EMBEDDED_DIR"]}/bin")
138
+ File.open("#{ENV["EMBEDDED_DIR"]}/bin/foo", "w+", 0700) { |file| }
139
+ end
140
+
141
+ it "should raise a CommandUnavailable error" do
142
+ expect { described_class.new(app, env, condition).call(env) }.to raise_error(VagrantPlugins::Triggers::Errors::CommandUnavailable)
143
+ end
144
+
145
+ after do
146
+ FileUtils.rm_rf("#{ENV["EMBEDDED_DIR"]}/bin")
147
+ end
148
+ end
149
+
150
+ it "should not pass GEM_HOME to the executed command" do
151
+ Vagrant::Util::Subprocess.should_receive(:execute) do |command|
152
+ expect(ENV).not_to have_key("GEM_HOME")
153
+ result
154
+ end
155
+ described_class.new(app, env, condition).call(env)
156
+ end
157
+
158
+ it "should not pass GEM_PATH to the executed command" do
159
+ Vagrant::Util::Subprocess.should_receive(:execute) do |command|
160
+ expect(ENV).not_to have_key("GEM_PATH")
161
+ result
162
+ end
163
+ described_class.new(app, env, condition).call(env)
164
+ end
165
+
166
+ it "should not pass GEMRC to the executed command" do
167
+ Vagrant::Util::Subprocess.should_receive(:execute) do |command|
168
+ expect(ENV).not_to have_key("GEMRC")
169
+ result
170
+ end
171
+ described_class.new(app, env, condition).call(env)
172
+ end
173
+
174
+ after do
175
+ ENV["EMBEDDED_DIR"] = nil
176
+ ENV["GEM_HOME"] = nil
177
+ ENV["GEM_PATH"] = nil
178
+ ENV["GEMRC"] = nil
179
+ ENV["PATH"] = @original_path
180
+ end
181
+ end
182
+ end
@@ -14,6 +14,18 @@ describe VagrantPlugins::Triggers::Config do
14
14
  its("triggers") { should eq [] }
15
15
  end
16
16
 
17
+ describe "add triggers" do
18
+ it "should add before triggers" do
19
+ config.before :up, :exec => "echo ls"
20
+ expect(config.triggers.first).to eq({ :action => :up, :condition => :before, :options => { :exec => "echo ls" } })
21
+ end
22
+
23
+ it "should add after triggers" do
24
+ config.after :up, :exec => "echo ls"
25
+ expect(config.triggers.first).to eq({ :action => :up, :condition => :after, :options => { :exec => "echo ls" } })
26
+ end
27
+ end
28
+
17
29
  describe "accept multiple entries" do
18
30
  it "should record multiple entries" do
19
31
  config.before :up, :exec => "echo ls"
@@ -38,4 +50,4 @@ describe VagrantPlugins::Triggers::Config do
38
50
  expect(config.validate(machine)["triggers"]).to have(1).item
39
51
  end
40
52
  end
41
- end
53
+ end
@@ -0,0 +1,6 @@
1
+ describe "Vagrant" do
2
+ it "can run vagrant with the plugin loaded" do
3
+ env = Vagrant::Environment.new
4
+ expect(env.cli("-h")).to eq(0)
5
+ end
6
+ end
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.email = "emiticci@gmail.com"
9
9
  spec.summary = "Triggers for Vagrant commands."
10
10
  spec.description = "This plugin allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands."
11
-
11
+
12
12
  # The following block of code determines the files that should be included
13
13
  # in the gem. It does this by reading all the files in the directory where
14
14
  # this gemspec is, and parsing out the ignored files from the gitignore.
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  root_path = File.dirname(__FILE__)
18
18
  all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
19
19
  all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
20
+ all_files.reject! { |file| file.start_with?("coverage/") }
20
21
  gitignore_path = File.join(root_path, ".gitignore")
21
22
  gitignore = File.readlines(gitignore_path)
22
23
  gitignore.map! { |line| line.chomp.strip }
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-triggers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Emiliano Ticci
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-19 00:00:00.000000000 Z
11
+ date: 2014-03-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,33 +27,29 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: This plugin allow the definition of arbitrary scripts that will run on
@@ -82,39 +75,35 @@ files:
82
75
  - spec/spec_helper.rb
83
76
  - spec/vagrant-triggers/action/trigger_spec.rb
84
77
  - spec/vagrant-triggers/config_spec.rb
78
+ - spec/vagrant-triggers/vagrant_spec.rb
85
79
  - vagrant-triggers.gemspec
86
80
  - .gitignore
81
+ - .travis.yml
87
82
  homepage:
88
83
  licenses: []
84
+ metadata: {}
89
85
  post_install_message:
90
86
  rdoc_options: []
91
87
  require_paths:
92
88
  - lib
93
89
  required_ruby_version: !ruby/object:Gem::Requirement
94
- none: false
95
90
  requirements:
96
- - - ! '>='
91
+ - - '>='
97
92
  - !ruby/object:Gem::Version
98
93
  version: '0'
99
- segments:
100
- - 0
101
- hash: -2957871706623383121
102
94
  required_rubygems_version: !ruby/object:Gem::Requirement
103
- none: false
104
95
  requirements:
105
- - - ! '>='
96
+ - - '>='
106
97
  - !ruby/object:Gem::Version
107
98
  version: '0'
108
- segments:
109
- - 0
110
- hash: -2957871706623383121
111
99
  requirements: []
112
100
  rubyforge_project:
113
- rubygems_version: 1.8.23
101
+ rubygems_version: 2.0.14
114
102
  signing_key:
115
- specification_version: 3
103
+ specification_version: 4
116
104
  summary: Triggers for Vagrant commands.
117
105
  test_files:
118
106
  - spec/spec_helper.rb
119
107
  - spec/vagrant-triggers/action/trigger_spec.rb
120
108
  - spec/vagrant-triggers/config_spec.rb
109
+ - spec/vagrant-triggers/vagrant_spec.rb