vagrant-bundler-tools 0.0.3.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vagrant_bundler_tools/command/base.rb +31 -0
- data/lib/vagrant_bundler_tools/command/bundle.rb +53 -0
- data/lib/vagrant_bundler_tools/command/bundle_list.rb +11 -0
- data/lib/vagrant_bundler_tools/command/bundle_open.rb +33 -0
- data/lib/vagrant_bundler_tools/command/bundle_show.rb +24 -0
- data/lib/vagrant_bundler_tools.rb +7 -1
- metadata +27 -32
- data/lib/vagrant_bundler_tools/command.rb +0 -60
@@ -0,0 +1,31 @@
|
|
1
|
+
module VagrantBundlerTools
|
2
|
+
module Command
|
3
|
+
class Base < Vagrant::Command::Base
|
4
|
+
protected
|
5
|
+
def locate_gem(gem_name)
|
6
|
+
guest_path = ssh_execute("cd /vagrant && bundle show #{gem_name}").strip
|
7
|
+
unless guest_path.start_with?('/vagrant/')
|
8
|
+
raise Errors::BundlePathOutsideVagrantDirectory.new
|
9
|
+
end
|
10
|
+
host_path = guest_path.gsub(%r{^/vagrant/}, '')
|
11
|
+
File.expand_path(host_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def ssh_execute(command)
|
15
|
+
output = ''
|
16
|
+
with_target_vms(nil, true) do |vm|
|
17
|
+
# Basic checks that are required for proper SSH
|
18
|
+
raise Errors::VMNotCreatedError if !vm.created?
|
19
|
+
raise Errors::VMInaccessible if !vm.state == :inaccessible
|
20
|
+
raise Errors::VMNotRunningError if vm.state != :running
|
21
|
+
|
22
|
+
vm.channel.execute(command, :error_check => false) do |type, data|
|
23
|
+
output << data.to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
output
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module VagrantBundlerTools
|
4
|
+
module Command
|
5
|
+
class Bundle < Base
|
6
|
+
def initialize(argv, env)
|
7
|
+
super
|
8
|
+
|
9
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
10
|
+
|
11
|
+
@subcommands = Vagrant::Registry.new
|
12
|
+
@subcommands.register(:list) { VagrantBundlerTools::Command::BundleList }
|
13
|
+
@subcommands.register(:open) { VagrantBundlerTools::Command::BundleOpen }
|
14
|
+
@subcommands.register(:show) { VagrantBundlerTools::Command::BundleShow }
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute
|
18
|
+
if @main_args.include?("-h") || @main_args.include?("--help")
|
19
|
+
# Print the help for all the box commands.
|
20
|
+
return help
|
21
|
+
end
|
22
|
+
|
23
|
+
# If we reached this far then we must have a subcommand. If not,
|
24
|
+
# then we also just print the help and exit.
|
25
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
26
|
+
return help if !command_class || !@sub_command
|
27
|
+
|
28
|
+
# Initialize and execute the command class
|
29
|
+
command_class.new(@sub_args, @env).execute
|
30
|
+
end
|
31
|
+
|
32
|
+
# Prints the help out for this command
|
33
|
+
def help
|
34
|
+
opts = OptionParser.new do |opts|
|
35
|
+
opts.banner = "Usage: vagrant bundle <command> [<args>]"
|
36
|
+
opts.separator ""
|
37
|
+
opts.separator "Available subcommands:"
|
38
|
+
|
39
|
+
# Add the available subcommands as separators in order to print them
|
40
|
+
# out as well.
|
41
|
+
keys = []
|
42
|
+
@subcommands.each { |key, value| keys << key }
|
43
|
+
|
44
|
+
keys.each do |key|
|
45
|
+
opts.separator " #{key}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@env.ui.info(opts.help, :prefix => false)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module VagrantBundlerTools
|
2
|
+
module Command
|
3
|
+
class BundleOpen < Base
|
4
|
+
def execute
|
5
|
+
opts = OptionParser.new do |opts|
|
6
|
+
opts.banner = "Show the path to a bundle gem on the vagrant box"
|
7
|
+
opts.separator ""
|
8
|
+
opts.separator "Usage: vagrant bundle show <gem_name>"
|
9
|
+
end
|
10
|
+
|
11
|
+
# Parse the options
|
12
|
+
argv = parse_options(opts)
|
13
|
+
|
14
|
+
return if !argv
|
15
|
+
|
16
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1
|
17
|
+
|
18
|
+
# Method largely copied and pasted from from Bundler::CLI#open
|
19
|
+
editor = [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
|
20
|
+
if editor
|
21
|
+
gem_path = locate_gem(argv[0])
|
22
|
+
Dir.chdir(gem_path) do
|
23
|
+
command = "#{editor} #{gem_path}"
|
24
|
+
success = system(command)
|
25
|
+
@env.ui.info "Could not run '#{command}'" unless success
|
26
|
+
end
|
27
|
+
else
|
28
|
+
@env.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module VagrantBundlerTools
|
4
|
+
module Command
|
5
|
+
class BundleShow < Base
|
6
|
+
def execute
|
7
|
+
opts = OptionParser.new do |opts|
|
8
|
+
opts.banner = "Show the path to a bundle gem on the vagrant box"
|
9
|
+
opts.separator ""
|
10
|
+
opts.separator "Usage: vagrant bundle show <gem_name>"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Parse the options
|
14
|
+
argv = parse_options(opts)
|
15
|
+
|
16
|
+
return if !argv
|
17
|
+
|
18
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1
|
19
|
+
|
20
|
+
@env.ui.info locate_gem(argv[0])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'vagrant'
|
2
|
-
require 'vagrant_bundler_tools/command'
|
2
|
+
require 'vagrant_bundler_tools/command/base'
|
3
|
+
require 'vagrant_bundler_tools/command/bundle'
|
4
|
+
require 'vagrant_bundler_tools/command/bundle_list'
|
5
|
+
require 'vagrant_bundler_tools/command/bundle_open'
|
6
|
+
require 'vagrant_bundler_tools/command/bundle_show'
|
3
7
|
require 'vagrant_bundler_tools/errors'
|
4
8
|
|
5
9
|
module VagrantBundlerTools
|
@@ -11,5 +15,7 @@ module VagrantBundlerTools
|
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
18
|
+
Vagrant.commands.register(:bundle) { VagrantBundlerTools::Command::Bundle }
|
19
|
+
|
14
20
|
# # Default I18n to load the en locale
|
15
21
|
I18n.load_path << File.expand_path("templates/locales/en.yml", VagrantBundlerTools.source_root)
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-bundler-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 0.0.3.1
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Joel Chippindale
|
@@ -19,32 +18,25 @@ cert_chain: []
|
|
19
18
|
date: 2012-02-09 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
22
22
|
type: :runtime
|
23
|
-
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 7
|
32
|
-
- 0
|
33
|
-
version: 0.7.0
|
34
|
-
- - <
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
hash: 59
|
28
|
+
hash: 53
|
37
29
|
segments:
|
38
30
|
- 0
|
39
31
|
- 9
|
40
|
-
-
|
41
|
-
version: 0.9.
|
42
|
-
|
43
|
-
prerelease: false
|
32
|
+
- 7
|
33
|
+
version: 0.9.7
|
34
|
+
version_requirements: *id001
|
44
35
|
name: vagrant
|
45
36
|
- !ruby/object:Gem::Dependency
|
37
|
+
prerelease: false
|
46
38
|
type: :runtime
|
47
|
-
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
48
40
|
none: false
|
49
41
|
requirements:
|
50
42
|
- - ">="
|
@@ -55,12 +47,12 @@ dependencies:
|
|
55
47
|
- 5
|
56
48
|
- 0
|
57
49
|
version: 0.5.0
|
58
|
-
|
59
|
-
prerelease: false
|
50
|
+
version_requirements: *id002
|
60
51
|
name: i18n
|
61
52
|
- !ruby/object:Gem::Dependency
|
53
|
+
prerelease: false
|
62
54
|
type: :development
|
63
|
-
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
64
56
|
none: false
|
65
57
|
requirements:
|
66
58
|
- - ">="
|
@@ -69,12 +61,12 @@ dependencies:
|
|
69
61
|
segments:
|
70
62
|
- 0
|
71
63
|
version: "0"
|
72
|
-
|
73
|
-
prerelease: false
|
64
|
+
version_requirements: *id003
|
74
65
|
name: rake
|
75
66
|
- !ruby/object:Gem::Dependency
|
67
|
+
prerelease: false
|
76
68
|
type: :development
|
77
|
-
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
78
70
|
none: false
|
79
71
|
requirements:
|
80
72
|
- - ">="
|
@@ -83,12 +75,12 @@ dependencies:
|
|
83
75
|
segments:
|
84
76
|
- 0
|
85
77
|
version: "0"
|
86
|
-
|
87
|
-
prerelease: false
|
78
|
+
version_requirements: *id004
|
88
79
|
name: rdoc
|
89
80
|
- !ruby/object:Gem::Dependency
|
81
|
+
prerelease: false
|
90
82
|
type: :development
|
91
|
-
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
92
84
|
none: false
|
93
85
|
requirements:
|
94
86
|
- - ">="
|
@@ -97,8 +89,7 @@ dependencies:
|
|
97
89
|
segments:
|
98
90
|
- 0
|
99
91
|
version: "0"
|
100
|
-
|
101
|
-
prerelease: false
|
92
|
+
version_requirements: *id005
|
102
93
|
name: minitest
|
103
94
|
description: |
|
104
95
|
vagrant-bundler-tools is a vagrant plugin to make it possible to interact
|
@@ -113,9 +104,13 @@ extra_rdoc_files:
|
|
113
104
|
- README.mdown
|
114
105
|
files:
|
115
106
|
- README.mdown
|
116
|
-
- lib/vagrant_bundler_tools/command.rb
|
117
|
-
- lib/vagrant_bundler_tools/errors.rb
|
118
107
|
- lib/vagrant_bundler_tools.rb
|
108
|
+
- lib/vagrant_bundler_tools/command/base.rb
|
109
|
+
- lib/vagrant_bundler_tools/command/bundle.rb
|
110
|
+
- lib/vagrant_bundler_tools/command/bundle_list.rb
|
111
|
+
- lib/vagrant_bundler_tools/command/bundle_open.rb
|
112
|
+
- lib/vagrant_bundler_tools/command/bundle_show.rb
|
113
|
+
- lib/vagrant_bundler_tools/errors.rb
|
119
114
|
- lib/vagrant_init.rb
|
120
115
|
- templates/locales/en.yml
|
121
116
|
homepage: http://github.com/mocoso/vagrant-bundler-tools
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module VagrantBundlerTools
|
2
|
-
class Command < Vagrant::Command::GroupBase
|
3
|
-
register "bundle", "Commands to interact with bundled gems on guest"
|
4
|
-
|
5
|
-
desc "list", "Show all of the gems in the guest's bundle"
|
6
|
-
def list
|
7
|
-
env.ui.info ssh_execute("cd /vagrant && bundle list")
|
8
|
-
end
|
9
|
-
|
10
|
-
desc "show GEM_NAME", "Show location of guest's bundled gem on host file system"
|
11
|
-
def show(gem_name)
|
12
|
-
env.ui.info locate_gem(gem_name)
|
13
|
-
end
|
14
|
-
|
15
|
-
desc "open GEM_NAME", "Open guest's bundled gem with host's editor"
|
16
|
-
def open(gem_name)
|
17
|
-
# Method largely copied and pasted from from Bundler::CLI#open
|
18
|
-
editor = [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
|
19
|
-
if editor
|
20
|
-
gem_path = locate_gem(gem_name)
|
21
|
-
Dir.chdir(gem_path) do
|
22
|
-
command = "#{editor} #{gem_path}"
|
23
|
-
success = system(command)
|
24
|
-
env.ui.info "Could not run '#{command}'" unless success
|
25
|
-
end
|
26
|
-
else
|
27
|
-
env.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
protected
|
32
|
-
def locate_gem(gem_name)
|
33
|
-
guest_path = ssh_execute("cd /vagrant && bundle show #{gem_name}").strip
|
34
|
-
unless guest_path.start_with?('/vagrant/')
|
35
|
-
raise Errors::BundlePathOutsideVagrantDirectory.new
|
36
|
-
end
|
37
|
-
host_path = guest_path.gsub(%r{^/vagrant/}, '')
|
38
|
-
File.expand_path(host_path)
|
39
|
-
end
|
40
|
-
|
41
|
-
def ssh_execute(command)
|
42
|
-
ssh_vm.ssh.execute do |ssh|
|
43
|
-
ssh.exec!(command)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def ssh_vm
|
48
|
-
@ssh_vm ||= begin
|
49
|
-
vm = target_vms.first
|
50
|
-
|
51
|
-
# Basic checks that are required for proper SSH
|
52
|
-
raise Vagrant::Errors::VMNotCreatedError if !vm.created?
|
53
|
-
raise Vagrant::Errors::VMInaccessible if !vm.vm.accessible?
|
54
|
-
raise Vagrant::Errors::VMNotRunningError if !vm.vm.running?
|
55
|
-
|
56
|
-
vm
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|