vundler 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 508f9295c3c0e535a6d8b5943d5701733f063c6f
4
+ data.tar.gz: 2021d78083cb5c4d2ea1bc33a49b71847d5838c8
5
+ SHA512:
6
+ metadata.gz: 8e0b90432e44cbfb2c6a71c366dcb67ae78f36869cebe103765f374099ba1314fc7f791b368ab5013c005a38cd0ffa0215f734b4f92c0e4c11b534ff55dbd867
7
+ data.tar.gz: b656e119131ad6893b9a47894c5af575c2c65157e598614a44fff24f6698baffe68769c19651919f0dbfb44007aa1d26c1421875e4f77ae50eedc8b996bdbacb
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ development/.vagrant
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vundler.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'vagrant', github: 'mitchellh/vagrant'
8
+ gem 'vagrant-lxc', github: 'fgrehm/vagrant-lxc'
9
+ gem 'vagrant-cachier', github: 'fgrehm/vagrant-cachier'
10
+ gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine'
11
+ end
@@ -0,0 +1,60 @@
1
+ GIT
2
+ remote: git://github.com/fgrehm/vagrant-cachier.git
3
+ revision: ae6cb5bcfbdbb2157867d77ded8f2b6f430c0f6c
4
+ specs:
5
+ vagrant-cachier (0.2.0)
6
+
7
+ GIT
8
+ remote: git://github.com/fgrehm/vagrant-lxc.git
9
+ revision: 14c1ebfd7c6327307289de86c005a392d0a4d253
10
+ specs:
11
+ vagrant-lxc (0.4.0.dev)
12
+
13
+ GIT
14
+ remote: git://github.com/fgrehm/vagrant-pristine.git
15
+ revision: 45a8d75f048bd611e337583496eb2b48b6998bbd
16
+ specs:
17
+ vagrant-pristine (0.1.0)
18
+
19
+ GIT
20
+ remote: git://github.com/mitchellh/vagrant.git
21
+ revision: abd22dfe72eedc74f1e41a1d0d6095e25bd87c72
22
+ specs:
23
+ vagrant (1.2.4.dev)
24
+ childprocess (~> 0.3.7)
25
+ erubis (~> 2.7.0)
26
+ i18n (~> 0.6.0)
27
+ log4r (~> 1.1.9)
28
+ net-scp (~> 1.1.0)
29
+ net-ssh (~> 2.6.6)
30
+
31
+ PATH
32
+ remote: .
33
+ specs:
34
+ vundler (0.0.4)
35
+
36
+ GEM
37
+ remote: https://rubygems.org/
38
+ specs:
39
+ childprocess (0.3.9)
40
+ ffi (~> 1.0, >= 1.0.11)
41
+ erubis (2.7.0)
42
+ ffi (1.9.0)
43
+ i18n (0.6.4)
44
+ log4r (1.1.10)
45
+ net-scp (1.1.2)
46
+ net-ssh (>= 2.6.5)
47
+ net-ssh (2.6.8)
48
+ rake (10.1.0)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ bundler (~> 1.3)
55
+ rake
56
+ vagrant!
57
+ vagrant-cachier!
58
+ vagrant-lxc!
59
+ vagrant-pristine!
60
+ vundler!
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Fabio Rehm
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,82 @@
1
+ # Vundler
2
+
3
+ Dead easy Vagrant plugins management (not to be confused with [vim's Vundle](https://github.com/gmarik/vundle)),
4
+ think of it as soon-to-be "[Bundler](http://bundler.io/) for Vagrant".
5
+
6
+ ## WARNING
7
+
8
+ This is highly experimental and things might go wrong. It basically does some
9
+ [heavy monkey patching](lib/vundler/bend_vagrant.rb) on Vagrant's core and should
10
+ not be considered "production-ready". Please keep that in mind and be ready to
11
+ [revert Vundler's installation](#help-things-are-falling-apart) in case things
12
+ go crazy.
13
+
14
+
15
+ ## Installation
16
+
17
+ Make sure you have Vagrant 1.2+ and run:
18
+
19
+ ```
20
+ vagrant plugin install vundler
21
+ vagrant vundler setup
22
+ ```
23
+
24
+
25
+ ## Usage
26
+
27
+ Add a `plugins.json` file to your project root like the following:
28
+
29
+ ```json
30
+ [
31
+ "vagrant-lxc",
32
+ {"vagrant-cachier": "0.2.0"}
33
+ ]
34
+ ```
35
+
36
+ And run `vagrant plugin bundle` to install missing dependencies:
37
+
38
+ ```
39
+ $ vagrant plugin bundle
40
+
41
+ Installing plugins...
42
+ -> vagrant-lxc already installed
43
+ -> vagrant-cachier (0.2.0)
44
+ ```
45
+
46
+ List installed plugins with `vagrant plugin list`:
47
+
48
+ ```
49
+ $ vagrant plugin list
50
+
51
+ vagrant-lxc (0.4.0)
52
+ vundler (0.0.4)
53
+
54
+ Project dependencies:
55
+ -> vagrant-lxc
56
+ -> vagrant-cachier 0.2.0
57
+ ```
58
+
59
+
60
+ ## Help! Things are falling apart!
61
+
62
+ First bring back Vagrant's default `plugins.json` file:
63
+
64
+ ```
65
+ mv $HOME/.vagrant.d/{global-,}plugins.json
66
+ ```
67
+
68
+ And then remove the `require 'vundler'` from your `$HOME/.vagrant.d/Vagrantfile`.
69
+
70
+
71
+ ## How does it work?
72
+
73
+ Have a look at [this blog post](http://fabiorehm.com/blog/2013/07/15/vundler-dead-easy-plugin-management-for-vagrant/).
74
+
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create new Pull Request
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :clean do
4
+ sh 'rm -f pkg/*.gem'
5
+ end
6
+
7
+ task :install_vm do
8
+ Bundler.with_clean_env do
9
+ sh "cd development && vagrant ssh -c 'vagrant plugin uninstall vundler && vagrant plugin install /vagrant/pkg/vundler-*.gem'"
10
+ end
11
+ end
12
+
13
+ desc 'Rebuild plugin and install on Vagrant dev VM'
14
+ task :deploy => [:clean, :build, :install_vm]
@@ -0,0 +1,59 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.require_plugin 'vagrant-cachier'
5
+ Vagrant.require_plugin 'vagrant-pristine'
6
+ Vagrant.require_plugin 'vagrant-lxc'
7
+
8
+ Vagrant.configure("2") do |config|
9
+ config.vm.box = "quantal64"
10
+ config.vm.synced_folder "../", "/vagrant", id: 'vagrant-root', nfs: true
11
+
12
+ config.cache.auto_detect = true
13
+ config.cache.enable_nfs = true
14
+
15
+ config.vm.provider :lxc do |lxc|
16
+ # Required to boot nested containers
17
+ lxc.customize 'aa_profile', 'unconfined'
18
+ end
19
+
20
+ config.vm.provision :shell, inline: %[
21
+ if ! $(which lxc-create > /dev/null); then
22
+ cat <<STR > /etc/default/lxc
23
+ LXC_AUTO="true"
24
+ USE_LXC_BRIDGE="true"
25
+ LXC_BRIDGE="lxcbr0"
26
+ LXC_ADDR="10.0.253.1"
27
+ LXC_NETMASK="255.255.255.0"
28
+ LXC_NETWORK="10.0.253.0/24"
29
+ LXC_DHCP_RANGE="10.0.253.2,10.0.253.254"
30
+ LXC_DHCP_MAX="253"
31
+ LXC_SHUTDOWN_TIMEOUT=120
32
+ STR
33
+
34
+ apt-get update &&
35
+ apt-get upgrade -y &&
36
+ apt-get install -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' \
37
+ lxc redir htop vim
38
+ fi
39
+
40
+ if ! $(which vagrant > /dev/null); then
41
+ # Pick your Vagrant version:
42
+ # 1.2.3 -> http://files.vagrantup.com/packages/95d308caaecd139b8f62e41e7add0ec3f8ae3bd1/vagrant_1.2.3_x86_64.deb
43
+ # 1.2.2 -> http://files.vagrantup.com/packages/7e400d00a3c5a0fdf2809c8b5001a035415a607b/vagrant_1.2.2_x86_64.deb
44
+ # 1.2.1 -> http://files.vagrantup.com/packages/a7853fe7b7f08dbedbc934eb9230d33be6bf746f/vagrant_1.2.1_x86_64.deb
45
+ # 1.2.0 -> http://files.vagrantup.com/packages/f5ece47c510e5a632adb69701b78cb6dcbe03713/vagrant_1.2.0_x86_64.deb
46
+
47
+ wget http://files.vagrantup.com/packages/95d308caaecd139b8f62e41e7add0ec3f8ae3bd1/vagrant_1.2.3_x86_64.deb -O /tmp/vagrant.deb -q
48
+ dpkg -i /tmp/vagrant.deb
49
+ fi
50
+
51
+ if ! $(grep -q 'VAGRANT_DEFAULT_PROVIDER=lxc' /home/vagrant/.bashrc); then
52
+ echo 'export VAGRANT_DEFAULT_PROVIDER=lxc' >> /home/vagrant/.bashrc
53
+ fi
54
+
55
+ if [ `uname -r` = 3.5.0-17-generic ]; then
56
+ echo "Please restart the machine with 'vagrant reload'"
57
+ fi
58
+ ]
59
+ end
@@ -0,0 +1,5 @@
1
+ require_relative "vundler/version"
2
+ require_relative "vundler/plugin"
3
+ require_relative "vundler/logging"
4
+ require_relative 'vundler/plugin_not_found_error'
5
+ require_relative "vundler/bend_vagrant"
@@ -0,0 +1,122 @@
1
+ # WARNING: Monkey patches ahead
2
+
3
+ Vagrant::Environment.class_eval do
4
+ include VagrantPlugins::Vundler::Logging
5
+
6
+ # UGLY HACK: This is required because we need to load project specific plugins
7
+ # before the `:environment_load` hook from Vagrant::Environment on [1]. In order
8
+ # to run the hook, Vagrantfile configs have to be parsed [2] to build a
9
+ # Vagrant::Action::Runner [3].
10
+ #
11
+ # [1] - https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/environment.rb#L135
12
+ # [2] - https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/environment.rb#L239
13
+ # [3] - https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/environment.rb#L498-L510
14
+ #
15
+ # DISCUSS: What if Vagrant had another hook that was called before `:environment_load`?
16
+ alias old_hook hook
17
+ def hook(name)
18
+ unless @__custom_plugins_loaded
19
+ vundler_debug 'Loading local plugins...'
20
+ __load_local_plugins
21
+
22
+ @__custom_plugins_loaded = true
23
+ end
24
+ old_hook name
25
+ end
26
+
27
+ # This method loads plugins from a project specific `plugins.json` file
28
+ def __load_local_plugins
29
+ plugins_json = cwd.join('plugins.json')
30
+
31
+ unless plugins_json.file?
32
+ vundler_debug 'Local plugins.json file not found'
33
+ return
34
+ end
35
+
36
+ ARGV.each do |arg|
37
+ if !arg.start_with?("-") && arg == 'vundler'
38
+ vundler_debug 'vundler command detected, setting VAGRANT_NO_PLUGINS to 1'
39
+ ENV["VAGRANT_NO_PLUGINS"] = "1"
40
+ break
41
+ end
42
+ end
43
+
44
+ if ENV['VAGRANT_NO_PLUGINS']
45
+ vundler_debug 'VAGRANT_NO_PLUGINS is set to true, skipping local plugins.json parsing'
46
+ return
47
+ end
48
+
49
+ # Prepend our local gem path and reset the paths that Rubygems knows about.
50
+ ENV["GEM_PATH"] = "#{local_data_path.join('gems')}#{::File::PATH_SEPARATOR}#{ENV["GEM_PATH"]}"
51
+ ::Gem.clear_paths
52
+
53
+ data = JSON.parse(plugins_json.read)
54
+ vundler_debug "plugins.json data: #{data.inspect}"
55
+ data.each do |plugin|
56
+ if plugin.is_a?(String)
57
+ __load_plugin plugin
58
+ else
59
+ __load_plugin *plugin.first
60
+ end
61
+ end
62
+
63
+ if @__failed_to_load
64
+ plugins = @__failed_to_load.map do |plugin, version|
65
+ " -> #{plugin} (#{version || ">= 0"})"
66
+ end
67
+ raise VagrantPlugins::Vundler::PluginNotFoundError, plugins: plugins.join("\n")
68
+ end
69
+ end
70
+
71
+ def __load_plugin(plugin, version = nil)
72
+ vundler_debug "Loading #{plugin} (#{version.inspect})"
73
+ gem plugin, version
74
+ Vagrant.require_plugin plugin
75
+ rescue Gem::LoadError
76
+ (@__failed_to_load ||= []) << [plugin, version]
77
+ end
78
+ end
79
+
80
+ require Vagrant.source_root.join('plugins/commands/plugin/state_file').to_s
81
+ # Vagrant plugin commands manipulate a StateFile object that keeps track of system
82
+ # wide installed plugins. Since vundler is kept separately on `~/.vagrant.d/plugins`,
83
+ # we hard code a reference to it over here.
84
+ # If we don't do this, Vundler will be uninstalled after a system wide plugin install.
85
+ class VundlerStateFile < VagrantPlugins::CommandPlugin::StateFile
86
+ def installed_plugins
87
+ ['vundler'] + @data['installed']
88
+ end
89
+ end
90
+
91
+ require Vagrant.source_root.join('plugins/commands/plugin/command/base').to_s
92
+ # The patch makes sure Vagrant's system wide plugin commands manipulates the custom
93
+ # configuration file.
94
+ VagrantPlugins::CommandPlugin::Command::Base.class_eval do
95
+ alias old_action action
96
+ def action(callable, env=nil)
97
+ env = {
98
+ plugin_state_file: VundlerStateFile.new(@env.home_path.join("global-plugins.json")),
99
+ }.merge(env || {})
100
+
101
+ old_action(callable, env)
102
+ end
103
+ end
104
+
105
+ require Vagrant.source_root.join('plugins/commands/plugin/action/install_gem').to_s
106
+ # This patch ensures Vundler does not get a reference on `~/.vagrant.d/global-plugins.json`
107
+ VagrantPlugins::CommandPlugin::Action::InstallGem.class_eval do
108
+ include VagrantPlugins::Vundler::Logging
109
+
110
+ alias old_call call
111
+ def call(env)
112
+ if env[:plugin_name] == 'vundler'
113
+ vundler_debug 'Installing vundler to global plugins file'
114
+ # vundler is the only plugin that should be installed on the global state file
115
+ env[:plugin_state_file] = CommandPlugin::StateFile.new(env[:home_path].join("plugins.json"))
116
+ else
117
+ vundler_debug "Installing #{env[:plugin_name]} to $HOME/.vagrant.d"
118
+ end
119
+ old_call(env)
120
+ end
121
+ end
122
+
@@ -0,0 +1,9 @@
1
+ module VagrantPlugins
2
+ module Vundler
3
+ module Logging
4
+ def vundler_debug(msg)
5
+ @logger.debug "[VUNDLER] #{msg}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ I18n.load_path << File.expand_path(File.dirname(__FILE__) + '/../../locales/en.yml')
2
+ I18n.reload!
3
+
4
+ module VagrantPlugins
5
+ module Vundler
6
+ class Plugin < Vagrant.plugin('2')
7
+ name 'Vundler'
8
+
9
+ command("plugin") do
10
+ require_relative 'plugin_command/root'
11
+ PluginCommand::Root
12
+ end
13
+
14
+ command("vundler") do
15
+ require_relative 'vundler_command/root'
16
+ VundlerCommand::Root
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,94 @@
1
+ require_relative '../logging'
2
+
3
+ require Vagrant.source_root.join('plugins/commands/plugin/command/base').to_s
4
+ require "rubygems/dependency_installer"
5
+
6
+ module VagrantPlugins
7
+ module Vundler
8
+ module PluginCommand
9
+ # Based on https://github.com/mitchellh/vagrant/blob/master/plugins/commands/plugin/action/install_gem.rb
10
+ class Bundle < CommandPlugin::Command::Base
11
+ include VagrantPlugins::Vundler::Logging
12
+
13
+ def initialize(*)
14
+ super
15
+
16
+ if @env.local_data_path
17
+ @local_gems_path = @env.local_data_path.join('gems')
18
+ else
19
+ vundler_debug 'Local data path is not set'
20
+ end
21
+ end
22
+
23
+ def execute
24
+ plugins_json = @env.cwd.join('plugins.json')
25
+
26
+ if plugins_json.file?
27
+ data = JSON.parse(plugins_json.read)
28
+ vundler_debug "plugins.json data: #{data.inspect}"
29
+
30
+ if data.any?
31
+ @env.ui.info('Installing plugins...')
32
+
33
+ data.each do |plugin|
34
+ if plugin.is_a?(String)
35
+ install plugin
36
+ else
37
+ install *plugin.first
38
+ end
39
+ end
40
+ exit_code = 0
41
+ else
42
+ @env.ui.info('No plugins specified on plugins.json')
43
+ end
44
+ else
45
+ @env.ui.error "No plugins.json found!"
46
+ exit_code = 1
47
+ end
48
+
49
+ exit_code
50
+ end
51
+
52
+ def gem_helper(path)
53
+ CommandPlugin::GemHelper.new(path)
54
+ end
55
+
56
+ def installed_gems
57
+ @installed ||= {}.tap do |installed|
58
+ # Combine project specific gems and global plugins
59
+ gem_helper("#{@local_gems_path}#{::File::PATH_SEPARATOR}#{@env.gems_path}").with_environment do
60
+ Gem::Specification.find_all.each do |spec|
61
+ (installed[spec.name] ||= {})[spec.version.to_s] = spec
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ def install(plugin_name, version = nil)
68
+ plugin_name_label = plugin_name
69
+ plugin_name_label += " (#{version})" if version
70
+
71
+ versions = installed_gems.fetch(plugin_name, {}).keys
72
+ vundler_debug "Installed versions for #{plugin_name}: #{versions}"
73
+
74
+ if (versions.include? version) || (version.nil? && versions.any?)
75
+ @env.ui.info(" -> #{plugin_name_label} already installed")
76
+ return
77
+ end
78
+
79
+ gem_helper(@local_gems_path).with_environment do
80
+ installer = Gem::DependencyInstaller.new(:document => [])
81
+
82
+ begin
83
+ @env.ui.info(" -> #{plugin_name_label} ")
84
+ installer.install(plugin_name, version)
85
+ rescue Gem::GemNotFoundException
86
+ raise Vagrant::Errors::PluginInstallNotFound,
87
+ :name => plugin_name
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,46 @@
1
+ require Vagrant.source_root.join('plugins/commands/plugin/command/list').to_s
2
+
3
+ module VagrantPlugins
4
+ module Vundler
5
+ module PluginCommand
6
+ # Override the built in `plugin list` command to output project specific
7
+ # plugins information
8
+ class List < CommandPlugin::Command::List
9
+ include VagrantPlugins::Vundler::Logging
10
+
11
+ def execute
12
+ return unless super == 0
13
+
14
+ plugins_json = @env.cwd.join('plugins.json')
15
+
16
+ if plugins_json.file?
17
+ data = JSON.parse(plugins_json.read)
18
+ vundler_debug "plugins.json data: #{data.inspect}"
19
+
20
+ if data.any?
21
+ @env.ui.info "\nProject dependencies:"
22
+ data.each do |plugin|
23
+ if plugin.is_a?(String)
24
+ display plugin
25
+ else
26
+ display *plugin.first
27
+ end
28
+ end
29
+ end
30
+ else
31
+ @env.ui.info "\nNo project specific plugins.json file found!"
32
+ end
33
+
34
+ # Success, exit status 0
35
+ 0
36
+ end
37
+
38
+ def display(plugin, version = nil)
39
+ label = " -> #{plugin}"
40
+ label << " #{version}" if version
41
+ @env.ui.info label
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ require Vagrant.source_root.join('plugins/commands/plugin/command/root').to_s
2
+
3
+ module VagrantPlugins
4
+ module Vundler
5
+ module PluginCommand
6
+ class Root < CommandPlugin::Command::Root
7
+ def initialize(argv, env)
8
+ super
9
+
10
+ # Override the built in `plugin list` command to output project specific
11
+ # plugins information
12
+ @subcommands.register(:list) do
13
+ require_relative "list"
14
+ Vundler::PluginCommand::List
15
+ end
16
+
17
+ @subcommands.register(:bundle) do
18
+ require_relative "bundle"
19
+ Vundler::PluginCommand::Bundle
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ module VagrantPlugins
2
+ module Vundler
3
+ class PluginNotFoundError < Vagrant::Errors::VagrantError
4
+ error_key(:plugin_not_found_error)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Vundler
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,60 @@
1
+ require Vagrant.source_root.join('plugins/commands/plugin/command/root').to_s
2
+
3
+ module VagrantPlugins
4
+ module Vundler
5
+ module VundlerCommand
6
+ class Root < Vagrant.plugin(2, :command)
7
+ def initialize(argv, env)
8
+ super
9
+
10
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
11
+ @subcommands = Vagrant::Registry.new
12
+
13
+ @subcommands.register(:setup) do
14
+ require_relative "setup"
15
+ Vundler::VundlerCommand::Setup
16
+ end
17
+ end
18
+
19
+ def execute
20
+ if @main_args.include?("-h") || @main_args.include?("--help")
21
+ # Print the help for all the sub-commands.
22
+ return help
23
+ end
24
+
25
+ # If we reached this far then we must have a subcommand. If not,
26
+ # then we also just print the help and exit.
27
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
28
+ return help if !command_class || !@sub_command
29
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
30
+
31
+ # Initialize and execute the command class
32
+ command_class.new(@sub_args, @env).execute
33
+ end
34
+
35
+ # Prints the help out for this command
36
+ def help
37
+ opts = OptionParser.new do |o|
38
+ o.banner = "Usage: vagrant vundler <command> [<args>]"
39
+ o.separator ""
40
+ o.separator "Available subcommands:"
41
+
42
+ # Add the available subcommands as separators in order to print them
43
+ # out as well.
44
+ keys = []
45
+ @subcommands.each { |key, value| keys << key.to_s }
46
+
47
+ keys.sort.each do |key|
48
+ o.separator " #{key}"
49
+ end
50
+
51
+ o.separator ""
52
+ o.separator "For help on any individual command run `vagrant bundler COMMAND -h`"
53
+ end
54
+
55
+ @env.ui.info(opts.help, :prefix => false)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,56 @@
1
+ require_relative '../logging'
2
+
3
+ module VagrantPlugins
4
+ module Vundler
5
+ module VundlerCommand
6
+ class Setup < Vagrant.plugin(2, :command)
7
+ def execute
8
+ if @env.home_path.join('global-plugins.json').file?
9
+ @env.ui.info "Vundler has already been set up!"
10
+ return 0
11
+ end
12
+
13
+ # Load current plugins.json file
14
+ plugins_json = @env.home_path.join('plugins.json')
15
+ plugins_json_data = JSON.parse(plugins_json.read)
16
+ @logger.debug "Current #{plugins_json} data: #{plugins_json_data.inspect}"
17
+
18
+ # Gets a list of other plugins that are installed
19
+ @logger.debug "Getting list of installed plugins"
20
+ other_plugins = plugins_json_data['installed'].dup
21
+ other_plugins.delete('vundler')
22
+
23
+ # Save other plugins to a separate file
24
+ @logger.debug "Writing #{other_plugins.inspect} to #{@env.home_path.join('global-plugins.json')}"
25
+ @env.home_path.join('global-plugins.json').open("w+") do |f|
26
+ f.write(JSON.dump({'installed' => other_plugins}))
27
+ end
28
+
29
+ # Leave only vundler on the global plugins file
30
+ plugins_json_data['installed'] = ['vundler']
31
+ @logger.debug "Writing #{plugins_json_data.inspect} to #{plugins_json}"
32
+ plugins_json.open('w+') do |f|
33
+ f.write(JSON.dump plugins_json_data)
34
+ end
35
+
36
+ # Add require to ~/.vagrant.d/Vagrantfile
37
+ vagrantfile = @env.home_path.join('Vagrantfile')
38
+ vagrantfile_contents = vagrantfile.file? ? vagrantfile.read : ''
39
+ # FIXME: We need to handle emacs / vim file types comments
40
+ vagrantfile_contents = <<-STR
41
+ begin
42
+ require 'vundler'
43
+ rescue LoadError; end
44
+ #{vagrantfile_contents}
45
+ STR
46
+ @logger.debug "Writing to system wide Vagrantfile:\n#{vagrantfile_contents}"
47
+ @env.home_path.join('Vagrantfile').open("w+") do |f|
48
+ f.write vagrantfile_contents
49
+ end
50
+
51
+ 0
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ en:
2
+ vagrant:
3
+ errors:
4
+ plugin_not_found_error: |-
5
+ Could not find the following plugins for the current environment:
6
+ %{plugins}
7
+ Run `vagrant plugin bundle` to install missing plugins.
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vundler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vundler"
8
+ spec.version = Vundler::VERSION
9
+ spec.authors = ["Fabio Rehm"]
10
+ spec.email = ["fgrehm@gmail.com"]
11
+ spec.description = %q{Dead easy Vagrant plugins management}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/fgrehm/vundler"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vundler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Fabio Rehm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Dead easy Vagrant plugins management
42
+ email:
43
+ - fgrehm@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - development/Vagrantfile
55
+ - lib/vundler.rb
56
+ - lib/vundler/bend_vagrant.rb
57
+ - lib/vundler/logging.rb
58
+ - lib/vundler/plugin.rb
59
+ - lib/vundler/plugin_command/bundle.rb
60
+ - lib/vundler/plugin_command/list.rb
61
+ - lib/vundler/plugin_command/root.rb
62
+ - lib/vundler/plugin_not_found_error.rb
63
+ - lib/vundler/version.rb
64
+ - lib/vundler/vundler_command/root.rb
65
+ - lib/vundler/vundler_command/setup.rb
66
+ - locales/en.yml
67
+ - vundler.gemspec
68
+ homepage: https://github.com/fgrehm/vundler
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.0.0
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Dead easy Vagrant plugins management
92
+ test_files: []