Skip to content

Installed plugins were not loaded by Vagrant when continuing the proccess #3

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

Merged
merged 2 commits into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,20 @@ Vagrant.configure(2) do |config|

end
```

### Invoking

Just `vagrant up` or `vagrant reload` as usual!

_**Danger:** this is so easy to use that you could forget that you are checking for missing dependencies every time you bootstrap your machine :D_

#### Bypass the dependency manager

You might want to skip the dependency manager proccess that runs just before Vagrant. If it's your case, you can up your Vagrant machine as always with the `--skip-dependency-manager`` parameter before the Vagrant command.

Example:
```
vagrant --skip-dependency-manager up
```

_Remember: if you type the vagrant command before the `--skip-dependency-manager` paramter you will get an error because Vagrant tries to run an invalid option_
40 changes: 26 additions & 14 deletions dependency_manager.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
#!/usr/bin/ruby
# @Author: Dev_NIX
# @Date: 2016-03-07 14:24:11
# @Last Modified by: Dev_NIX
# @Last Modified time: 2016-03-07 16:36:38

require 'getoptlong'

def check_plugins(dependencies)
if ['up', 'reload'].include? ARGV[0]
skip_dependency_manager = false

opts = GetoptLong.new(
[ '--skip-dependency-manager', GetoptLong::OPTIONAL_ARGUMENT ]
)

opts.each do |opt, arg|
case opt
when '--skip-dependency-manager'
skip_dependency_manager = true
end
end

if ['up', 'reload'].include?(ARGV[0]) && !skip_dependency_manager
installed_dependencies = []

puts "\033[1m" << "Checking dependencies..." << "\e[0m"
Expand All @@ -22,30 +34,30 @@ def check_plugins(dependencies)
installed_dependencies.push plugin.slice((first)..(plugin.index("(")-1)).strip
end

no_missing = false
dependencies_already_satisfied = true

dependencies.each_with_index do |dependency, index|
if not installed_dependencies.include? dependency
dependencies_already_satisfied = false
puts "\033[33m" << " - Missing '#{dependency}'!" << "\e[0m"
if not system "vagrant plugin install #{dependency}"
puts "\n\033[33m" << " - Could not install plugin '#{dependency}'. " << "\e[0m\033[41m" <<"Stopped." << "\e[0m"
exit -1
end

if no_missing == nil
no_missing = false
end
else
if no_missing == nil
no_missing = true
end
end
end

if no_missing
if dependencies_already_satisfied
puts "\033[1m\033[36m" << " - All dependencies already satisfied" << "\e[0m"
else
puts "\033[1m\033[32m" << " - Dependencies installed" << "\e[0m"
exec "vagrant " << "--skip-dependency-manager " << ARGV.join(" ")
exit
end
end

if ARGV.include?('--skip-dependency-manager')
ARGV.delete_at(ARGV.index('--skip-dependency-manager'))
end

end