cldwalker-lightning 0.1.1 → 0.1.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.
- data/README.markdown +6 -4
- data/bin/lightning-complete +10 -4
- data/bin/lightning-full_path +8 -5
- data/bin/lightning-install +4 -2
- data/lib/lightning/bolt.rb +31 -0
- data/lib/lightning/bolts.rb +12 -0
- data/lib/lightning/completion.rb +6 -6
- data/lib/lightning/config.rb +23 -26
- data/lib/lightning/generator.rb +5 -4
- data/lib/lightning/path_map.rb +13 -13
- data/lib/lightning.rb +23 -9
- data/test/lightning_bolt_test.rb +27 -0
- data/test/lightning_completion_test.rb +7 -7
- data/test/lightning_config_test.rb +33 -12
- data/test/lightning_path_map_test.rb +10 -24
- data/test/lightning_test.rb +25 -2
- data/test/test_helper.rb +3 -2
- metadata +5 -2
data/README.markdown
CHANGED
@@ -26,6 +26,8 @@ In this case, rvim is configured to complete my ruby core and standard library f
|
|
26
26
|
Install
|
27
27
|
=======
|
28
28
|
|
29
|
+
For newcomers to github, install this gem with: `gem install cldwalker-lightning -s http://gems.github.com`
|
30
|
+
|
29
31
|
To make your own commands, you'll need to:
|
30
32
|
|
31
33
|
1. Create ~/.lightning.yml or a lightning.yml in the current directory.
|
@@ -36,7 +38,7 @@ To make your own commands, you'll need to:
|
|
36
38
|
below. See lightning\_completions.example for what would be generated for the enclosed example
|
37
39
|
config.
|
38
40
|
|
39
|
-
3. Source the generated file in your bashrc ie `source ~/.
|
41
|
+
3. Source the generated file in your bashrc ie `source ~/.lightning_completions`.
|
40
42
|
|
41
43
|
|
42
44
|
Globbable paths
|
@@ -119,9 +121,9 @@ But once I saw how easy it was to manipulate completion through ruby,
|
|
119
121
|
http://github.com/ryanb/dotfiles/blob/master/bash/completion\_scripts/project\_completion,
|
120
122
|
I had to do something.
|
121
123
|
|
122
|
-
Todo
|
123
|
-
|
124
|
+
Todo/Ideas
|
125
|
+
==========
|
124
126
|
|
125
|
-
* Clean up code to better test.
|
126
127
|
* Aliases for common autocompletions.
|
127
128
|
* Allow lightning commands to only path-resolve one of multiple arguments given.
|
129
|
+
* Command interface to easily add/remove current directory or globs from a command
|
data/bin/lightning-complete
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
# == Description
|
4
|
+
# Used to complete a lightning command
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..","lib","lightning"))
|
4
6
|
|
5
|
-
|
6
|
-
puts Lightning
|
7
|
-
exit 0
|
7
|
+
if (command = ARGV.shift)
|
8
|
+
puts Lightning.complete(command, ENV["COMP_LINE"])
|
9
|
+
exit 0
|
10
|
+
else
|
11
|
+
puts "No command given"
|
12
|
+
exit 1
|
13
|
+
end
|
data/bin/lightning-full_path
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# == Description
|
4
|
-
# Used by path completion functions to return first possible full path which matches the given basename for the given
|
5
|
-
# Warning: Basenames that occur in multiple directories will return the first directory found.
|
4
|
+
# Used by path completion functions to return first possible full path which matches the given basename for the given command.
|
6
5
|
|
7
|
-
require File.expand_path(File.dirname(__FILE__)
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..","lib","lightning"))
|
8
7
|
|
9
|
-
|
8
|
+
command = ARGV.shift
|
9
|
+
if command.nil?
|
10
|
+
puts "No command given"
|
11
|
+
exit 1
|
12
|
+
end
|
10
13
|
if ARGV.empty?
|
11
14
|
puts "No arguments given"
|
12
15
|
exit 1
|
13
16
|
end
|
14
|
-
puts Lightning.
|
17
|
+
puts Lightning.translate(command, ARGV)
|
15
18
|
exit 0
|
data/bin/lightning-install
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
# == Description
|
4
|
+
# Used to generate shell file from configuration
|
4
5
|
|
5
|
-
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..","lib","lightning"))
|
7
|
+
Lightning::Generator.generate_completions ARGV.shift
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# A bolt, referenced by a key, is the basic unit needed to access a lightning command's functionality.
|
2
|
+
class Lightning
|
3
|
+
class Bolt
|
4
|
+
attr_reader :key
|
5
|
+
def initialize(bolt_key)
|
6
|
+
@key = bolt_key
|
7
|
+
end
|
8
|
+
|
9
|
+
def completions
|
10
|
+
path_map.keys
|
11
|
+
end
|
12
|
+
|
13
|
+
def path_map
|
14
|
+
@path_map ||= Lightning::PathMap.new(self.paths)
|
15
|
+
end
|
16
|
+
|
17
|
+
def resolve_completion(basename)
|
18
|
+
basename = basename.join(" ") if basename.is_a?(Array)
|
19
|
+
basename.gsub!(/\s*#{TEST_FLAG}\s*/,'')
|
20
|
+
#TODO
|
21
|
+
# if (regex = Lightning.config_command(Lightning.current_command)['completion_regex'])
|
22
|
+
# basename = basename[/#{regex}/]
|
23
|
+
# end
|
24
|
+
path_map[basename] || ''
|
25
|
+
end
|
26
|
+
|
27
|
+
def paths
|
28
|
+
@paths ||= Lightning.config[:paths][key] || []
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/lightning/completion.rb
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
#This class handles completions given a path key and the text already typed.
|
3
3
|
class Lightning
|
4
4
|
class Completion
|
5
|
-
def self.complete(text_to_complete,
|
6
|
-
new(text_to_complete,
|
5
|
+
def self.complete(text_to_complete, bolt_key)
|
6
|
+
new(text_to_complete, bolt_key).matches
|
7
7
|
end
|
8
8
|
|
9
|
-
def initialize(text_typed,
|
9
|
+
def initialize(text_typed, bolt_key)
|
10
10
|
@text_typed = text_typed
|
11
|
-
@
|
11
|
+
@bolt_key = bolt_key
|
12
12
|
end
|
13
13
|
|
14
14
|
def matches
|
@@ -24,7 +24,7 @@ class Lightning
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def possible_completions
|
27
|
-
Lightning.
|
27
|
+
Lightning.bolts[@bolt_key].completions
|
28
28
|
end
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
data/lib/lightning/config.rb
CHANGED
@@ -1,53 +1,50 @@
|
|
1
1
|
module Lightning::Config
|
2
|
+
def load_config
|
3
|
+
@config = setup_config
|
4
|
+
end
|
5
|
+
|
2
6
|
def config
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
@config ||= setup_config
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup_config
|
11
|
+
hash = read_config_file
|
12
|
+
configure_commands_and_paths(hash)
|
13
|
+
hash
|
8
14
|
end
|
9
15
|
|
10
|
-
def
|
16
|
+
def read_config_file(config_file=nil)
|
11
17
|
default_config = {:shell=>'bash', :generated_file=>File.expand_path(File.join('~', '.lightning_completions'))}
|
12
18
|
config_file ||= File.exists?('lightning.yml') ? 'lightning.yml' : File.expand_path(File.join("~",".lightning.yml"))
|
13
19
|
hash = YAML::load(File.new(config_file))
|
14
20
|
default_config.merge(hash.symbolize_keys)
|
15
21
|
end
|
16
22
|
|
17
|
-
#should return array of globbable paths
|
18
|
-
def globbable_paths_by_key(key)
|
19
|
-
config[:paths][key] || []
|
20
|
-
end
|
21
|
-
|
22
23
|
def config_command(name)
|
23
24
|
config[:commands].find {|e| e['name'] == name} || {}
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
+
def commands_to_bolt_key(map_to_command, new_command)
|
27
28
|
"#{map_to_command}-#{new_command}"
|
28
29
|
end
|
29
30
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def add_command_paths(config)
|
35
|
-
config[:paths] ||= {}
|
36
|
-
config[:commands].each do |e|
|
31
|
+
def configure_commands_and_paths(hash)
|
32
|
+
hash[:paths] ||= {}
|
33
|
+
hash[:commands].each do |e|
|
37
34
|
#mapping a referenced path
|
38
35
|
if e['paths'].is_a?(String)
|
39
|
-
e['
|
40
|
-
e['paths'] = config[:paths][e['paths'].strip] || []
|
36
|
+
e['bolt_key'] = e['paths'].dup
|
41
37
|
end
|
42
38
|
#create a path entry + key if none exists
|
43
|
-
if e['
|
39
|
+
if e['bolt_key'].nil?
|
44
40
|
#extract command in case it has options after it
|
45
41
|
e['map_to'] =~ /\s*(\w+)/
|
46
|
-
|
47
|
-
e['
|
48
|
-
|
42
|
+
bolt_key = commands_to_bolt_key($1, e['name'])
|
43
|
+
e['bolt_key'] = bolt_key
|
44
|
+
hash[:paths][bolt_key] = e['paths'] || []
|
49
45
|
end
|
50
46
|
end
|
47
|
+
hash
|
51
48
|
end
|
52
49
|
|
53
50
|
def ignore_paths
|
@@ -57,4 +54,4 @@ module Lightning::Config
|
|
57
54
|
end
|
58
55
|
@ignore_paths
|
59
56
|
end
|
60
|
-
end
|
57
|
+
end
|
data/lib/lightning/generator.rb
CHANGED
@@ -2,9 +2,10 @@
|
|
2
2
|
class Lightning
|
3
3
|
class Generator
|
4
4
|
class<<self
|
5
|
-
def generate_completions
|
5
|
+
def generate_completions(generated_file=nil)
|
6
|
+
generated_file ||= Lightning.config[:generated_file]
|
6
7
|
output = generate(Lightning.config[:shell], Lightning.config[:commands])
|
7
|
-
File.open(
|
8
|
+
File.open(generated_file, 'w'){|f| f.write(output) }
|
8
9
|
output
|
9
10
|
end
|
10
11
|
|
@@ -29,7 +30,7 @@ class Lightning
|
|
29
30
|
echo "No arguments given"
|
30
31
|
return
|
31
32
|
fi
|
32
|
-
FULL_PATH="`${LBIN_PATH}lightning-full_path #{e['
|
33
|
+
FULL_PATH="`${LBIN_PATH}lightning-full_path #{e['name']} $@`#{e['post_path'] if e['post_path']}"
|
33
34
|
if [ $1 == '#{Lightning::TEST_FLAG}' ]; then
|
34
35
|
CMD="#{e['map_to']} '$FULL_PATH'#{' '+ e['add_to_command'] if e['add_to_command']}"
|
35
36
|
echo $CMD
|
@@ -37,7 +38,7 @@ class Lightning
|
|
37
38
|
#{e['map_to']} "$FULL_PATH"#{' '+ e['add_to_command'] if e['add_to_command']}
|
38
39
|
fi
|
39
40
|
}
|
40
|
-
complete -o default -C "${LBIN_PATH}lightning-complete #{e['
|
41
|
+
complete -o default -C "${LBIN_PATH}lightning-complete #{e['name']}" #{e['name']}
|
41
42
|
EOS
|
42
43
|
end
|
43
44
|
body.gsub(/^\s{6,10}/, '')
|
data/lib/lightning/path_map.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
#This class maps completions to their full paths for
|
1
|
+
#This class maps completions to their full paths for the given blobs
|
2
2
|
class Lightning
|
3
3
|
class PathMap
|
4
|
-
|
5
|
-
@maps = {}
|
6
|
-
end
|
7
|
-
|
8
|
-
def [](key)
|
9
|
-
@maps[key] ||= create_map(key)
|
10
|
-
end
|
4
|
+
attr_accessor :map
|
11
5
|
|
12
|
-
def
|
13
|
-
|
6
|
+
def initialize(*globs)
|
7
|
+
#globs need to be an array
|
8
|
+
globs.flatten!
|
9
|
+
@map = create_map_for_globs(globs)
|
14
10
|
end
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
def [](completion)
|
13
|
+
@map[completion]
|
14
|
+
end
|
15
|
+
|
16
|
+
def keys
|
17
|
+
@map.keys
|
18
|
+
end
|
19
19
|
|
20
20
|
#should return hash
|
21
21
|
def create_map_for_globs(globs)
|
data/lib/lightning.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))
|
2
2
|
require 'yaml'
|
3
|
+
require 'lightning/bolt'
|
4
|
+
require 'lightning/bolts'
|
3
5
|
require 'lightning/completion'
|
4
6
|
require 'lightning/config'
|
5
7
|
require 'lightning/path_map'
|
@@ -9,18 +11,30 @@ require 'lightning/generator'
|
|
9
11
|
class Lightning
|
10
12
|
TEST_FLAG = '-test'
|
11
13
|
extend Config
|
12
|
-
class<<self
|
13
|
-
|
14
|
-
|
14
|
+
class<<self
|
15
|
+
attr_accessor :current_command
|
16
|
+
def complete(command, text_to_complete)
|
17
|
+
load_config
|
18
|
+
@current_command = command
|
19
|
+
if bolt_key = config_command(command)['bolt_key']
|
20
|
+
Completion.complete(text_to_complete, bolt_key)
|
21
|
+
else
|
22
|
+
["Error: No paths found for this command.", "If this is a bug contact me."]
|
23
|
+
end
|
15
24
|
end
|
16
25
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
if
|
21
|
-
|
26
|
+
def translate(command, argv)
|
27
|
+
load_config
|
28
|
+
@current_command = command
|
29
|
+
if bolt_key = config_command(command)['bolt_key']
|
30
|
+
bolts[bolt_key].resolve_completion(argv)
|
31
|
+
else
|
32
|
+
'Error-no_paths_found_for_this_command'
|
22
33
|
end
|
23
|
-
|
34
|
+
end
|
35
|
+
|
36
|
+
def bolts
|
37
|
+
@bolts ||= Bolts.new
|
24
38
|
end
|
25
39
|
end
|
26
40
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class LightningBoltTest < Test::Unit::TestCase
|
4
|
+
context "Bolt" do
|
5
|
+
before(:each) do
|
6
|
+
@path_map = {'path1'=>'/dir/path1','path2'=>'/dir/path2'}
|
7
|
+
@bolt = Lightning::Bolt.new('blah')
|
8
|
+
@bolt.path_map.map = @path_map
|
9
|
+
end
|
10
|
+
|
11
|
+
test "fetches correct completions" do
|
12
|
+
assert_equal @bolt.completions, @path_map.keys
|
13
|
+
end
|
14
|
+
|
15
|
+
test "resolves completion" do
|
16
|
+
assert_equal @path_map['path1'], @bolt.resolve_completion('path1')
|
17
|
+
end
|
18
|
+
|
19
|
+
test "resolves completion with test flag" do
|
20
|
+
assert_equal @path_map['path1'], @bolt.resolve_completion('-test path1')
|
21
|
+
end
|
22
|
+
|
23
|
+
test "creates path_map only once" do
|
24
|
+
assert_equal @bolt.path_map.object_id, @bolt.path_map.object_id
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -2,21 +2,21 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
class LightningCompletionTest < Test::Unit::TestCase
|
4
4
|
context "Completion" do
|
5
|
-
|
5
|
+
before(:each) {
|
6
|
+
@key = 'blah';
|
7
|
+
Lightning.bolts[@key].stub!(:completions, :return=>%w{at ap blah})
|
8
|
+
}
|
6
9
|
test "from script matches correctly" do
|
7
|
-
Lightning.
|
8
|
-
assert_arrays_equal Lightning::Completion.complete('cd-test a', 'blah'), %w{at ap}
|
10
|
+
assert_arrays_equal Lightning::Completion.complete('cd-test a', @key), %w{at ap}
|
9
11
|
end
|
10
12
|
|
11
13
|
test "for basic case matches correctly" do
|
12
|
-
Lightning.
|
13
|
-
@completion = Lightning::Completion.new('cd-test a', 'blah')
|
14
|
+
@completion = Lightning::Completion.new('cd-test a', @key)
|
14
15
|
assert_arrays_equal @completion.matches, %w{at ap}
|
15
16
|
end
|
16
17
|
|
17
18
|
test "with test flag matches correctly" do
|
18
|
-
Lightning.
|
19
|
-
@completion = Lightning::Completion.new('cd-test -test a', 'blah')
|
19
|
+
@completion = Lightning::Completion.new('cd-test -test a', @key)
|
20
20
|
assert_arrays_equal @completion.matches, %w{at ap}
|
21
21
|
end
|
22
22
|
end
|
@@ -2,40 +2,61 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
class LightningConfigTest < Test::Unit::TestCase
|
4
4
|
context "A config" do
|
5
|
-
|
5
|
+
before(:all) {
|
6
|
+
@config = Lightning.read_config_file(File.dirname(__FILE__) + '/lightning.yml')
|
7
|
+
}
|
6
8
|
|
7
9
|
should "be a hash" do
|
8
|
-
assert config.is_a?(Hash)
|
10
|
+
assert @config.is_a?(Hash)
|
9
11
|
end
|
10
12
|
|
11
13
|
should "have keys that are symbols" do
|
12
|
-
assert config.keys.all? {|e| e.is_a?(Symbol)}
|
14
|
+
assert @config.keys.all? {|e| e.is_a?(Symbol)}
|
13
15
|
end
|
14
16
|
|
15
17
|
should "have read supported keys" do
|
16
18
|
supported_keys = [:generated_file, :commands, :ignore_paths, :paths, :shell]
|
17
|
-
assert_arrays_equal supported_keys, config.keys
|
19
|
+
assert_arrays_equal supported_keys, @config.keys
|
18
20
|
end
|
19
21
|
|
20
22
|
should "have a generated_file key which is a string" do
|
21
|
-
assert config[:generated_file].is_a?(String)
|
23
|
+
assert @config[:generated_file].is_a?(String)
|
22
24
|
end
|
23
25
|
|
24
26
|
should "have a commands key which is an array" do
|
25
|
-
assert config[:commands].is_a?(Array)
|
27
|
+
assert @config[:commands].is_a?(Array)
|
26
28
|
end
|
27
29
|
|
28
30
|
should "have a command with valid keys" do
|
29
|
-
assert config[:commands][0].slice('name', 'map_to', 'description').values.all? {|e| e.is_a?(String)}
|
30
|
-
assert config[:commands][0]['paths'].is_a?(Array)
|
31
|
+
assert @config[:commands][0].slice('name', 'map_to', 'description').values.all? {|e| e.is_a?(String)}
|
32
|
+
assert @config[:commands][0]['paths'].is_a?(Array)
|
31
33
|
end
|
32
34
|
|
33
35
|
should "have a paths key which is a hash" do
|
34
|
-
assert config[:paths].is_a?(Hash)
|
36
|
+
assert @config[:paths].is_a?(Hash)
|
35
37
|
end
|
36
38
|
|
37
39
|
should "have an ignore_paths key which is an array" do
|
38
|
-
assert config[:ignore_paths].is_a?(Array)
|
39
|
-
end
|
40
|
+
assert @config[:ignore_paths].is_a?(Array)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context ":configure_commands_and_paths" do
|
45
|
+
test "generates bolt key if none exists" do
|
46
|
+
config = {:commands=>[{'name'=>'c1', 'map_to'=>'s1'}]}
|
47
|
+
assert ! Lightning.configure_commands_and_paths(config)[:commands][0]['bolt_key'].nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
test "adds generated bolt key to config.paths if it didn't exist" do
|
51
|
+
config = {:commands=>[{'name'=>'c1', 'map_to'=>'s1', 'paths'=>['*']}]}
|
52
|
+
new_config = Lightning.configure_commands_and_paths(config)
|
53
|
+
bolt_key = new_config[:commands][0]['bolt_key']
|
54
|
+
assert new_config[:paths].has_key?(bolt_key)
|
55
|
+
end
|
56
|
+
|
57
|
+
test "adds reference to bolt key if command.paths is a string" do
|
58
|
+
config = {:commands=>[{'name'=>'c1', 'map_to'=>'s1', 'paths'=>'blah'}]}
|
59
|
+
assert_equal 'blah', Lightning.configure_commands_and_paths(config)[:commands][0]['bolt_key']
|
60
|
+
end
|
40
61
|
end
|
41
|
-
end
|
62
|
+
end
|
@@ -2,43 +2,29 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
class LightningPathMapTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
context "PathMap" do
|
6
|
-
|
7
|
-
|
8
|
-
def stub_dir_glob(path_hash)
|
5
|
+
context "PathMap" do
|
6
|
+
def create_map(path_hash)
|
9
7
|
Dir.stub!(:glob) { path_hash.values }
|
10
|
-
|
11
|
-
|
12
|
-
test "creates map only once when accessing same key multiple times" do
|
13
|
-
# @map.expects(:create_map).once.returns({})
|
14
|
-
called = 0
|
15
|
-
@map.stub!(:create_map) {|e| called += 1; {}}
|
16
|
-
@map['blah']
|
17
|
-
@map['blah']
|
18
|
-
assert called == 1
|
8
|
+
@path_map = Lightning::PathMap.new('blah')
|
19
9
|
end
|
20
10
|
|
21
11
|
test "creates basic map" do
|
22
12
|
expected_map = {"path1"=>"/dir1/path1", "path2"=>"/dir1/path2"}
|
23
|
-
|
24
|
-
assert_equal expected_map, @map
|
13
|
+
create_map(expected_map)
|
14
|
+
assert_equal expected_map, @path_map.map
|
25
15
|
end
|
26
16
|
|
27
17
|
test "ignores paths from Lightning.ignore_paths" do
|
28
18
|
Lightning.stub!(:ignore_paths, :return=>['path1'])
|
29
19
|
expected_map = {"path1"=>"/dir1/path1", "path2"=>"/dir1/path2"}
|
30
|
-
|
31
|
-
assert_equal expected_map.slice('path2'), @map
|
20
|
+
create_map(expected_map)
|
21
|
+
assert_equal expected_map.slice('path2'), @path_map.map
|
32
22
|
end
|
33
23
|
|
34
24
|
test "creates map with duplicates" do
|
35
25
|
expected_map = {"path1//dir3"=>"/dir3/path1", "path2"=>"/dir1/path2", "path1//dir1"=>"/dir1/path1", "path1//dir2"=>"/dir2/path1"}
|
36
|
-
|
37
|
-
assert_equal expected_map, @map
|
38
|
-
end
|
39
|
-
|
40
|
-
test "creates hash even for invalid key" do
|
41
|
-
@map.create_map('blah').is_a?(Hash)
|
42
|
-
end
|
26
|
+
create_map(expected_map)
|
27
|
+
assert_equal expected_map, @path_map.map
|
28
|
+
end
|
43
29
|
end
|
44
30
|
end
|
data/test/lightning_test.rb
CHANGED
@@ -18,7 +18,11 @@ class LightningTest < Test::Unit::TestCase
|
|
18
18
|
generated_command = <<-EOS.gsub(/^\s{6}/,'')
|
19
19
|
#open mac applications
|
20
20
|
oa () {
|
21
|
-
|
21
|
+
if [ -z "$1" ]; then
|
22
|
+
echo "No arguments given"
|
23
|
+
return
|
24
|
+
fi
|
25
|
+
FULL_PATH="`${LBIN_PATH}lightning-full_path oa $@`"
|
22
26
|
if [ $1 == '-test' ]; then
|
23
27
|
CMD="open -a '$FULL_PATH'"
|
24
28
|
echo $CMD
|
@@ -26,10 +30,29 @@ class LightningTest < Test::Unit::TestCase
|
|
26
30
|
open -a "$FULL_PATH"
|
27
31
|
fi
|
28
32
|
}
|
29
|
-
complete -o default -C "${LBIN_PATH}lightning-complete
|
33
|
+
complete -o default -C "${LBIN_PATH}lightning-complete oa" oa
|
30
34
|
EOS
|
31
35
|
output = File.read(@config_file)
|
32
36
|
assert output.include?(generated_command)
|
33
37
|
end
|
34
38
|
end
|
39
|
+
|
40
|
+
context "Lightning" do
|
41
|
+
test "complete() returns correctly for valid command" do
|
42
|
+
Lightning::Completion.stub!(:complete, :return=>'blah')
|
43
|
+
assert_equal 'blah', Lightning.complete('oa', 'blah')
|
44
|
+
end
|
45
|
+
|
46
|
+
test "complete() reports error for invalid command" do
|
47
|
+
assert ! Lightning.complete('invalid','invalid').grep(/Error/).empty?
|
48
|
+
end
|
49
|
+
|
50
|
+
test "translate() returns errorless for valid command" do
|
51
|
+
assert Lightning.translate('oa', 'blah').grep(/Error/).empty?
|
52
|
+
end
|
53
|
+
|
54
|
+
test "translate() reports error for invalid command" do
|
55
|
+
assert ! Lightning.translate('invalid', 'blah').grep(/Error/).empty?
|
56
|
+
end
|
57
|
+
end
|
35
58
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
|
-
require 'context' #gem
|
4
|
-
require 'stump' #gem
|
3
|
+
require 'context' #gem install jeremymcanally-context -s http://gems.github.com
|
4
|
+
require 'stump' #gem install jeremymcanally-stump -s http://gems.github.com
|
5
|
+
require 'pending' #gem install jeremymcanally-pending -s http://gems.github.com
|
5
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
6
7
|
require 'lightning'
|
7
8
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cldwalker-lightning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Horner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-16 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -33,6 +33,8 @@ files:
|
|
33
33
|
- bin/lightning-full_path
|
34
34
|
- bin/lightning-install
|
35
35
|
- lib/lightning
|
36
|
+
- lib/lightning/bolt.rb
|
37
|
+
- lib/lightning/bolts.rb
|
36
38
|
- lib/lightning/completion.rb
|
37
39
|
- lib/lightning/config.rb
|
38
40
|
- lib/lightning/core_extensions.rb
|
@@ -40,6 +42,7 @@ files:
|
|
40
42
|
- lib/lightning/path_map.rb
|
41
43
|
- lib/lightning.rb
|
42
44
|
- test/lightning.yml
|
45
|
+
- test/lightning_bolt_test.rb
|
43
46
|
- test/lightning_completion_test.rb
|
44
47
|
- test/lightning_config_test.rb
|
45
48
|
- test/lightning_path_map_test.rb
|