rvm-completion 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/bin/install-rvm-completion +5 -3
- data/lib/rvm-completion.rb +20 -8
- data/rvm-completion.gemspec +2 -2
- data/test/helper.rb +87 -0
- data/test/test_rvm-completion.rb +101 -2
- metadata +4 -4
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/install-rvm-completion
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
rvm_scripts_path = ENV['rvm_scripts_path']
|
4
|
-
completion_source = File.expand_path(File.join(File.dirname(__FILE__), '../lib/rvm-completion.rb'))
|
5
|
-
completion_target = File.join(rvm_scripts_path, 'rvm-completion.rb')
|
6
4
|
|
7
5
|
if rvm_scripts_path.nil? or not (File.exist?(rvm_scripts_path) and File.directory?(rvm_scripts_path))
|
8
6
|
puts "Failed to find rvm scripts path - is rvm installed correctly?"
|
9
7
|
exit 1
|
10
8
|
end
|
11
9
|
|
10
|
+
completion_source = File.expand_path(File.join(File.dirname(__FILE__), '../lib/rvm-completion.rb'))
|
11
|
+
completion_target = File.join(rvm_scripts_path, 'rvm-completion.rb')
|
12
|
+
|
12
13
|
if system "cp #{completion_source} #{completion_target}"
|
13
14
|
puts "Success! rvm completion v#{File.read(File.expand_path(File.join(File.dirname(__FILE__), '../VERSION'))).chomp} installed to #{completion_target}", ""
|
14
15
|
|
15
|
-
puts "If you didn't do so before, please add the following line at the end of your
|
16
|
+
puts "If you didn't do so before, please add the following line at the end of your"
|
17
|
+
puts "~/.profile or ~/.bashrc and reload your terminal session"
|
16
18
|
puts " complete -C $rvm_scripts_path/#{File.basename(completion_target)} -o default rvm"
|
17
19
|
else
|
18
20
|
puts "Failed to copy the completion script to #{rvm_scripts_path}!"
|
data/lib/rvm-completion.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
#
|
4
4
|
# Bash completion for Ruby Version Manager commands, Rubies and gemsets
|
5
5
|
#
|
6
|
+
# See http://github.com/colszowka/rvm-completion#readme
|
7
|
+
#
|
8
|
+
# For manual setup:
|
6
9
|
# Add the following line to your ~/.profile or ~/.bashrc:
|
7
10
|
# complete -C PATH/TO/rvm_completion.rb -o default rvm
|
8
11
|
# Don't forget to make the completion script executable with chmod +x!
|
@@ -11,6 +14,7 @@
|
|
11
14
|
# (see http://github.com/ryanb/dotfiles/blob/master/bash/completion_scripts/project_completion)
|
12
15
|
#
|
13
16
|
class RVMCompletion
|
17
|
+
|
14
18
|
def initialize(comp_line)
|
15
19
|
@comp_line = comp_line
|
16
20
|
end
|
@@ -25,14 +29,14 @@ class RVMCompletion
|
|
25
29
|
case shell_argument
|
26
30
|
when /^use|uninstall|remove/
|
27
31
|
return [] if shell_argument(3).length > 0
|
28
|
-
select(rubies, shell_argument(2))
|
32
|
+
select(rubies, shell_argument(2), :regexp => true)
|
29
33
|
when /^install/
|
30
34
|
select(rvm_ruby_aliases, shell_argument(2))
|
31
35
|
|
32
36
|
when /^gemset/
|
33
37
|
case shell_argument(2)
|
34
38
|
when /use|copy|clear|delete|export/
|
35
|
-
select(gemsets, shell_argument(3))
|
39
|
+
select(gemsets, shell_argument(3), :regexp => true)
|
36
40
|
else
|
37
41
|
select(gemset_commands, shell_argument(2))
|
38
42
|
end
|
@@ -53,15 +57,22 @@ class RVMCompletion
|
|
53
57
|
end
|
54
58
|
|
55
59
|
# Matches the given (partial?) command against the given collection
|
56
|
-
def select(collection, command)
|
60
|
+
def select(collection, command, options={})
|
61
|
+
options = {:regexp => false}.merge(options)
|
62
|
+
return [] if collection.any? {|i| i.strip == command.strip}
|
57
63
|
collection.select do |item|
|
58
|
-
item[0, command.length] == command or item =~ /#{command}/
|
64
|
+
item[0, command.length] == command or (options[:regexp] and item =~ /#{command}/)
|
59
65
|
end.sort
|
60
66
|
end
|
61
67
|
|
68
|
+
# Retrieves the current ruby binary path
|
69
|
+
def current_ruby_path
|
70
|
+
@current_ruby_path ||= `which ruby`
|
71
|
+
end
|
72
|
+
|
62
73
|
# Retrieves the current rvm ruby
|
63
74
|
def current_ruby
|
64
|
-
@current_ruby ||=
|
75
|
+
@current_ruby ||= current_ruby_path.strip.chomp.gsub(File.join(ENV['rvm_rubies_path'], '/'), '').split('/').first
|
65
76
|
end
|
66
77
|
|
67
78
|
# Retrieves all available rubies
|
@@ -104,6 +115,7 @@ end
|
|
104
115
|
# f.puts RVMCompletion.new(ENV["COMP_LINE"]).shell_argument(2).inspect
|
105
116
|
# f.puts RVMCompletion.new(ENV["COMP_LINE"]).matches.inspect
|
106
117
|
# end
|
107
|
-
|
108
|
-
puts RVMCompletion.new(ENV["COMP_LINE"]).matches
|
109
|
-
exit 0
|
118
|
+
unless ENV['COMP_LINE'].nil?
|
119
|
+
puts RVMCompletion.new(ENV["COMP_LINE"]).matches
|
120
|
+
exit 0
|
121
|
+
end
|
data/rvm-completion.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rvm-completion}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Christoph Olszowka"]
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
]
|
34
34
|
s.homepage = %q{http://github.com/colszowka/rvm-completion}
|
35
35
|
s.post_install_message = %q{
|
36
|
-
To install rvm completion v0.
|
36
|
+
To install rvm completion v0.2.0, please run 'install-rvm-completion' in your terminal now!
|
37
37
|
|
38
38
|
}
|
39
39
|
s.rdoc_options = ["--charset=UTF-8"]
|
data/test/helper.rb
CHANGED
@@ -1,10 +1,97 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
3
|
require 'shoulda'
|
4
|
+
require 'fileutils'
|
4
5
|
|
5
6
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
7
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
8
|
require 'rvm-completion'
|
8
9
|
|
10
|
+
# Define path to tmp directory
|
11
|
+
tmp_root = File.expand_path(File.join(File.dirname(__FILE__), '../tmp'))
|
12
|
+
|
13
|
+
# Set environment vars used in completion to test-specific ones
|
14
|
+
ENV['rvm_rubies_path'] = File.join(tmp_root, 'rubies')
|
15
|
+
ENV['rvm_gems_path'] = File.join(tmp_root, 'gems')
|
16
|
+
ENV['rvm_gemset_separator'] = '@'
|
17
|
+
|
18
|
+
# Clean up and prepare test folders
|
19
|
+
FileUtils.rm_rf(tmp_root) if File.exist?(tmp_root)
|
20
|
+
|
21
|
+
def mock_gemset(ruby_name, gemset_name=nil)
|
22
|
+
if gemset_name.nil?
|
23
|
+
FileUtils.mkdir_p(File.join(ENV['rvm_gems_path'], "#{ruby_name}"))
|
24
|
+
else
|
25
|
+
FileUtils.mkdir_p(File.join(ENV['rvm_gems_path'], "#{ruby_name}#{ENV['rvm_gemset_separator']}#{gemset_name}"))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
FileUtils.mkdir_p(File.join(ENV['rvm_rubies_path'], 'default'))
|
30
|
+
|
31
|
+
["macruby-0.6", "rbx-1.0.1-20100603", "ree-1.8.7-2010.02", "ruby-1.8.7-p174",
|
32
|
+
"ruby-1.8.7-p299", "ruby-1.9.1-p378", "ruby-1.9.2-rc2"].each do |ruby_name|
|
33
|
+
FileUtils.mkdir_p(File.join(ENV['rvm_rubies_path'], ruby_name))
|
34
|
+
mock_gemset(ruby_name)
|
35
|
+
mock_gemset(ruby_name, 'global')
|
36
|
+
end
|
37
|
+
|
38
|
+
class RVMCompletion
|
39
|
+
# Required for mocking gemsets based upon selected ruby
|
40
|
+
attr_writer :current_ruby_path
|
41
|
+
end
|
42
|
+
|
9
43
|
class Test::Unit::TestCase
|
44
|
+
def self.using_ruby(ruby_name, options={})
|
45
|
+
options = {:gemsets => []}.merge(options)
|
46
|
+
options[:gemsets].each do |gemset|
|
47
|
+
mock_gemset ruby_name, gemset
|
48
|
+
end
|
49
|
+
context "using ruby #{ruby_name}" do
|
50
|
+
setup do
|
51
|
+
@current_ruby_path = File.join(File.join(ENV['rvm_rubies_path'], ruby_name, 'bin/ruby'))
|
52
|
+
end
|
53
|
+
yield
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.completion_for(*comp_lines)
|
58
|
+
comp_lines.each do |comp_line|
|
59
|
+
context "Completion for '#{comp_line}'" do
|
60
|
+
setup do
|
61
|
+
# Fake the use of a specific ruby by manipulating rvm bin path
|
62
|
+
if @current_ruby_path
|
63
|
+
instance = RVMCompletion.new(comp_line)
|
64
|
+
instance.current_ruby_path = @current_ruby_path
|
65
|
+
@completion = instance.matches
|
66
|
+
else
|
67
|
+
@completion = RVMCompletion.new(comp_line).matches
|
68
|
+
end
|
69
|
+
# puts "DEBUG: Complete '#{comp_line}' => #{@completion.inspect}"
|
70
|
+
end
|
71
|
+
subject { @completion }
|
72
|
+
should "return an Array" do
|
73
|
+
assert subject.instance_of?(Array)
|
74
|
+
end
|
75
|
+
yield
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.should_include(*values)
|
81
|
+
should "return #{values.length} completions" do
|
82
|
+
assert_equal values.length, subject.length
|
83
|
+
end
|
84
|
+
|
85
|
+
values.each do |value|
|
86
|
+
should "include '#{value}' in completion" do
|
87
|
+
assert subject.include?(value.to_s), "'#{value}' is not included in #{subject.inspect}!"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.should_include_nothing
|
93
|
+
should "include nothing in completion" do
|
94
|
+
assert_equal 0, subject.length
|
95
|
+
end
|
96
|
+
end
|
10
97
|
end
|
data/test/test_rvm-completion.rb
CHANGED
@@ -1,7 +1,106 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestRvmCompletion < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
4
|
+
completion_for 'rvm' do
|
5
|
+
should_include "debug", "fetch", "gem", "gemdir", "gemset", "implode", "info", "install", "list",
|
6
|
+
"monitor", "notes", "package", "rake", "reload", "remove", "reset", "ruby", "specs",
|
7
|
+
"srcdir", "tests", "uninstall", "update", "usage", "use", "version", "wrapper"
|
8
|
+
end
|
9
|
+
|
10
|
+
completion_for 'rvm insta' do
|
11
|
+
should_include 'install'
|
12
|
+
end
|
13
|
+
|
14
|
+
completion_for 'rvm install' do
|
15
|
+
should_include "ironruby", "jruby", "macruby", "maglev", "mput", "rbx", "ree", "ruby"
|
16
|
+
end
|
17
|
+
|
18
|
+
completion_for 'rvm install rub' do
|
19
|
+
should_include "ruby"
|
20
|
+
end
|
21
|
+
|
22
|
+
completion_for 'rvm install ruby' do
|
23
|
+
should_include_nothing
|
24
|
+
end
|
25
|
+
|
26
|
+
completion_for 'rvm us' do
|
27
|
+
should_include 'use', 'usage'
|
28
|
+
end
|
29
|
+
|
30
|
+
completion_for 'rvm use', 'rvm uninstall', 'rvm remove' do
|
31
|
+
should_include "system", "default", "macruby-0.6", "rbx-1.0.1-20100603", "ree-1.8.7-2010.02",
|
32
|
+
"ruby-1.8.7-p174", "ruby-1.8.7-p299", "ruby-1.9.1-p378", "ruby-1.9.2-rc2"
|
33
|
+
end
|
34
|
+
|
35
|
+
completion_for 'rvm use ruby', 'rvm uninstall ruby', 'rvm remove ruby' do
|
36
|
+
should_include "macruby-0.6", "ruby-1.8.7-p174", "ruby-1.8.7-p299", "ruby-1.9.1-p378", "ruby-1.9.2-rc2"
|
37
|
+
end
|
38
|
+
|
39
|
+
completion_for 'rvm use ruby-1.8', 'rvm uninstall ruby-1.8', 'rvm remove ruby-1.8' do
|
40
|
+
should_include "ruby-1.8.7-p174", "ruby-1.8.7-p299"
|
41
|
+
end
|
42
|
+
|
43
|
+
completion_for 'rvm use ruby-1.8.7-p1', 'rvm uninstall ruby-1.8.7-p1', 'rvm remove ruby-1.8.7-p1' do
|
44
|
+
should_include "ruby-1.8.7-p174"
|
45
|
+
end
|
46
|
+
|
47
|
+
completion_for 'rvm use ruby-1.8.7-p174', 'rvm uninstall ruby-1.8.7-p174', 'rvm remove ruby-1.8.7-p174' do
|
48
|
+
should_include_nothing
|
49
|
+
end
|
50
|
+
|
51
|
+
completion_for 'rvm use 174', 'rvm uninstall 174', 'rvm remove 174' do
|
52
|
+
should_include "ruby-1.8.7-p174"
|
53
|
+
end
|
54
|
+
|
55
|
+
completion_for 'rvm use 1.9.1' do
|
56
|
+
should_include "ruby-1.9.1-p378"
|
57
|
+
end
|
58
|
+
|
59
|
+
completion_for 'rvm use 1.9', 'rvm uninstall 1.9', 'rvm remove 1.9' do
|
60
|
+
should_include "ruby-1.9.1-p378", "ruby-1.9.2-rc2"
|
61
|
+
end
|
62
|
+
|
63
|
+
completion_for 'rvm usa' do
|
64
|
+
should_include 'usage'
|
65
|
+
end
|
66
|
+
|
67
|
+
completion_for 'rvm usage' do
|
68
|
+
should_include_nothing
|
69
|
+
end
|
70
|
+
|
71
|
+
completion_for 'rvm gems' do
|
72
|
+
should_include 'gemset'
|
73
|
+
end
|
74
|
+
|
75
|
+
completion_for 'rvm gemset' do
|
76
|
+
should_include "clear", "copy", "create", "delete", "dir", "empty", "export", "gemdir", "import", "install", "list", "name", "pristine", "use"
|
77
|
+
end
|
78
|
+
|
79
|
+
using_ruby 'ruby-1.8.7-p174', :gemsets => ['foo', 'bar'] do
|
80
|
+
completion_for 'rvm gemset use', 'rvm gemset copy', 'rvm gemset clear', 'rvm gemset delete', 'rvm gemset export' do
|
81
|
+
should_include 'global', 'foo', 'bar'
|
82
|
+
end
|
83
|
+
|
84
|
+
completion_for 'rvm gemset use o', 'rvm gemset copy o', 'rvm gemset clear o', 'rvm gemset delete o', 'rvm gemset export o' do
|
85
|
+
should_include 'global', 'foo'
|
86
|
+
end
|
87
|
+
|
88
|
+
completion_for 'rvm gemset use fo', 'rvm gemset copy fo', 'rvm gemset clear fo', 'rvm gemset delete fo', 'rvm gemset export fo' do
|
89
|
+
should_include 'foo'
|
90
|
+
end
|
91
|
+
|
92
|
+
completion_for 'rvm gemset use foo', 'rvm gemset copy foo', 'rvm gemset clear foo', 'rvm gemset delete foo', 'rvm gemset export foo' do
|
93
|
+
should_include_nothing
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
using_ruby 'ruby-1.8.7-p299' do
|
98
|
+
completion_for 'rvm gemset use', 'rvm gemset copy', 'rvm gemset clear', 'rvm gemset delete', 'rvm gemset export' do
|
99
|
+
should_include 'global'
|
100
|
+
end
|
101
|
+
|
102
|
+
completion_for 'rvm gemset use global', 'rvm gemset copy global', 'rvm gemset clear global', 'rvm gemset delete global', 'rvm gemset export global' do
|
103
|
+
should_include_nothing
|
104
|
+
end
|
6
105
|
end
|
7
106
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rvm-completion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Christoph Olszowka
|
@@ -59,7 +59,7 @@ licenses: []
|
|
59
59
|
|
60
60
|
post_install_message: |+
|
61
61
|
|
62
|
-
To install rvm completion v0.
|
62
|
+
To install rvm completion v0.2.0, please run 'install-rvm-completion' in your terminal now!
|
63
63
|
|
64
64
|
rdoc_options:
|
65
65
|
- --charset=UTF-8
|