lightning 0.3.1 → 0.3.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/CHANGELOG.rdoc +5 -0
- data/README.rdoc +18 -5
- data/Rakefile +2 -2
- data/lib/lightning/commands/bolt.rb +17 -16
- data/lib/lightning/commands/core.rb +1 -1
- data/lib/lightning/commands/function.rb +9 -13
- data/lib/lightning/commands/shell_command.rb +11 -11
- data/lib/lightning/commands_util.rb +19 -19
- data/lib/lightning/generator.rb +3 -3
- data/lib/lightning/version.rb +1 -1
- data/man/lightning.1 +207 -0
- data/man/lightning.1.ronn +167 -0
- data/test/bolt_commands_test.rb +119 -0
- data/test/bolt_test.rb +8 -1
- data/test/builder_test.rb +5 -5
- data/test/commands_test.rb +19 -47
- data/test/completion_test.rb +3 -1
- data/test/core_commands_test.rb +59 -0
- data/test/function_commands_test.rb +122 -0
- data/test/function_test.rb +1 -1
- data/test/generator_test.rb +83 -51
- data/test/lightning.yml +4 -0
- data/test/shell_command_commands_test.rb +43 -0
- data/test/test_helper.rb +4 -0
- metadata +15 -5
@@ -0,0 +1,122 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
context "function command" do
|
4
|
+
def function(*args)
|
5
|
+
run_command :function, args
|
6
|
+
end
|
7
|
+
|
8
|
+
def command_should_print(action, fn)
|
9
|
+
mock(Commands).save_and_say("#{action} function '#{fn}'")
|
10
|
+
end
|
11
|
+
|
12
|
+
test "list lists functions" do
|
13
|
+
mock(Commands).puts Lightning.functions.keys.sort
|
14
|
+
function('list')
|
15
|
+
end
|
16
|
+
|
17
|
+
test "list lists functions with --bolt" do
|
18
|
+
mock(Commands).puts Lightning.functions.keys.sort
|
19
|
+
function('list', '--bolt=app')
|
20
|
+
end
|
21
|
+
|
22
|
+
test "list lists functions with --command" do
|
23
|
+
mock(Commands).puts ['less-app']
|
24
|
+
function('list', '--command=less')
|
25
|
+
end
|
26
|
+
|
27
|
+
context "create:" do
|
28
|
+
test "creates a function" do
|
29
|
+
command_should_print 'Created', 'cp-app'
|
30
|
+
function 'create', 'cp', 'app'
|
31
|
+
config.bolts['app']['functions'][-1].should == {'name'=>'cp-app', 'shell_command'=>'cp'}
|
32
|
+
end
|
33
|
+
|
34
|
+
test "creates a function with an aliased bolt" do
|
35
|
+
command_should_print 'Created', 'grep-w'
|
36
|
+
function 'create', 'grep', 'w'
|
37
|
+
config.bolts['wild_dir']['functions'][-1].should == 'grep'
|
38
|
+
end
|
39
|
+
|
40
|
+
test "creates a function with an aliased global command" do
|
41
|
+
command_should_print 'Created', 'v-w'
|
42
|
+
function 'create', 'vim', 'wild_dir'
|
43
|
+
config.bolts['wild_dir']['functions'][-1].should == 'vim'
|
44
|
+
end
|
45
|
+
|
46
|
+
test "creates a function similar to a global function" do
|
47
|
+
command_should_print 'Created', 'vapp'
|
48
|
+
function 'create', 'vim', 'app', 'vapp'
|
49
|
+
config.bolts['app']['functions'][-1].should == {"name"=>"vapp", "shell_command"=>"vim"}
|
50
|
+
end
|
51
|
+
|
52
|
+
test "creates a function with explicit function name" do
|
53
|
+
command_should_print 'Created', 'eap'
|
54
|
+
function 'create', 'emacs', 'app', 'eap'
|
55
|
+
config.bolts['app']['functions'][-1].should == {"name"=>"eap", "shell_command"=>"emacs"}
|
56
|
+
end
|
57
|
+
|
58
|
+
test "fails to generate a bolt and doesn't create a function" do
|
59
|
+
mock(Generator).run('bin', :once=>'bin') { false }
|
60
|
+
mock(Commands).create_function(anything, anything, anything).never
|
61
|
+
function 'create', 'less', 'bin'
|
62
|
+
end
|
63
|
+
|
64
|
+
test "generates a bolt and creates a function" do
|
65
|
+
mock(Generator).run('bin', :once=>'bin') { true }
|
66
|
+
mock(Commands).create_function(anything, anything, anything)
|
67
|
+
function 'create', 'less', 'bin'
|
68
|
+
end
|
69
|
+
|
70
|
+
test "prints error if trying to create a function with an existing name" do
|
71
|
+
mock(Commands).puts(/'less-app'.*exists/)
|
72
|
+
function 'create', 'less', 'app'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# deletes functions created in create context
|
77
|
+
context "delete:" do
|
78
|
+
# reloads bolts/functions
|
79
|
+
before_all { Lightning.functions = nil; Lightning.bolts.delete_if { true } }
|
80
|
+
|
81
|
+
def function_count(bolt)
|
82
|
+
config.bolts[bolt]['functions'].size
|
83
|
+
end
|
84
|
+
|
85
|
+
context "deletes" do
|
86
|
+
before { @previous_count = function_count('app') }
|
87
|
+
after { function_count('app').should == @previous_count - 1 }
|
88
|
+
|
89
|
+
test "a function" do
|
90
|
+
command_should_print 'Deleted', 'cp-app'
|
91
|
+
function 'delete', 'cp-app'
|
92
|
+
end
|
93
|
+
|
94
|
+
test "a function with an aliased global command" do
|
95
|
+
command_should_print 'Deleted', 'v-app'
|
96
|
+
function 'delete', 'v-app'
|
97
|
+
end
|
98
|
+
|
99
|
+
test "a function with explicit name" do
|
100
|
+
command_should_print 'Deleted', 'eap'
|
101
|
+
function 'delete', 'eap'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
test "deletes a function with an aliased bolt" do
|
106
|
+
@previous_count = function_count('wild_dir')
|
107
|
+
command_should_print 'Deleted', 'grep-w'
|
108
|
+
function 'delete', 'grep-w'
|
109
|
+
function_count('wild_dir').should == @previous_count - 1
|
110
|
+
end
|
111
|
+
|
112
|
+
test "prints error if global function" do
|
113
|
+
mock(Commands).puts /Can't.*'grep-app'/, anything
|
114
|
+
function 'delete', 'grep-app'
|
115
|
+
end
|
116
|
+
|
117
|
+
test "prints error for nonexistent function" do
|
118
|
+
mock(Commands).puts /Can't.*'zzz'/
|
119
|
+
function 'delete', 'zzz'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
data/test/function_test.rb
CHANGED
data/test/generator_test.rb
CHANGED
@@ -2,72 +2,104 @@ require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
2
|
|
3
3
|
context "Generator" do
|
4
4
|
|
5
|
-
def temporary_config_file
|
6
|
-
old_config = Lightning.config
|
7
|
-
old_config_file = Lightning::Config.config_file
|
8
|
-
new_config_file = File.dirname(__FILE__) + '/another_lightning.yml'
|
9
|
-
Lightning::Config.config_file = new_config_file
|
10
|
-
yield(new_config_file)
|
11
|
-
Lightning::Config.config_file = old_config_file
|
12
|
-
Lightning.config = old_config
|
13
|
-
FileUtils.rm_f new_config_file
|
14
|
-
end
|
15
|
-
|
16
5
|
def generate(*args)
|
17
|
-
|
18
|
-
Generator.run args, {}
|
6
|
+
Generator.run *args
|
19
7
|
end
|
20
8
|
|
21
|
-
|
22
|
-
|
23
|
-
|
9
|
+
context "#run" do
|
10
|
+
def temporary_config_file
|
11
|
+
old_config = config
|
12
|
+
old_config_file = Lightning::Config.config_file
|
13
|
+
new_config_file = File.dirname(__FILE__) + '/another_lightning.yml'
|
14
|
+
Lightning::Config.config_file = new_config_file
|
15
|
+
yield(new_config_file)
|
16
|
+
Lightning::Config.config_file = old_config_file
|
17
|
+
Lightning.config = old_config
|
18
|
+
FileUtils.rm_f new_config_file
|
19
|
+
end
|
20
|
+
|
21
|
+
test "generates default generators when none given" do
|
22
|
+
stub.instance_of(Generator).call_generator { [] }
|
23
|
+
temporary_config_file do |config_file|
|
24
|
+
generate
|
25
|
+
conf = YAML::load_file(config_file)
|
26
|
+
Generator::DEFAULT_GENERATORS.all? {|e| conf[:bolts].key?(e) }.should == true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
test "generates given generators" do
|
31
|
+
mock.instance_of(Generator).generate_bolts('gem'=>'gem')
|
32
|
+
generate ['gem']
|
33
|
+
end
|
34
|
+
|
35
|
+
test "handles unexpected error while generating bolts" do
|
36
|
+
mock.instance_of(Generator).generate_bolts(anything) { raise "Totally unexpected" }
|
37
|
+
mock($stderr).puts(/Error: Totally/)
|
24
38
|
generate
|
25
|
-
config = YAML::load_file(config_file)
|
26
|
-
Generator::DEFAULT_GENERATORS.all? {|e| config[:bolts].key?(e) }.should == true
|
27
39
|
end
|
28
40
|
end
|
29
41
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
42
|
+
context "#generate_bolts" do
|
43
|
+
test "prints error for invalid generator" do
|
44
|
+
mock($stdout).puts /'bad' failed.*exist/
|
45
|
+
generate ['bad']
|
46
|
+
end
|
34
47
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
test "handles valid and invalid generators" do
|
49
|
+
mock($stdout).puts /'bad' failed.*exist/
|
50
|
+
mock(config).save
|
51
|
+
generate ['wild', 'bad']
|
52
|
+
end
|
53
|
+
|
54
|
+
context "generates" do
|
55
|
+
before_all {
|
56
|
+
@old_bolts = config[:bolts]
|
57
|
+
config[:bolts]['overwrite'] = {'globs'=>['overwrite me']}
|
58
|
+
Generators.send(:define_method, :user_bolt) { ['glob1', 'glob2'] }
|
59
|
+
Generators.send(:define_method, :overwrite) { ['overwritten'] }
|
60
|
+
mock(config).save
|
61
|
+
generate ['wild', 'user_bolt', 'overwrite']
|
62
|
+
}
|
63
|
+
|
64
|
+
test "a default bolt" do
|
65
|
+
config[:bolts]['wild']['globs'].should == ['**/*']
|
66
|
+
end
|
67
|
+
|
68
|
+
test "a user-specified bolt" do
|
69
|
+
config[:bolts]['user_bolt']['globs'].should == ['glob1', 'glob2']
|
70
|
+
end
|
47
71
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
test "a default bolt" do
|
58
|
-
Lightning.config[:bolts]['wild']['globs'].should == ['**/*']
|
72
|
+
test "and overwrites existing bolts" do
|
73
|
+
config[:bolts]['overwrite']['globs'].should == ["overwritten"]
|
74
|
+
end
|
75
|
+
|
76
|
+
test "and preserves bolts that aren't being generated" do
|
77
|
+
config[:bolts]['app'].class.should == Hash
|
78
|
+
end
|
79
|
+
|
80
|
+
after_all { config[:bolts] = @old_bolts }
|
59
81
|
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "#run with :once" do
|
85
|
+
before_all { @old_bolts = config[:bolts] }
|
60
86
|
|
61
|
-
test "a
|
62
|
-
|
87
|
+
test "and :test generates a test run" do
|
88
|
+
mock($stdout).puts ['**/*']
|
89
|
+
generate 'wild', :once=>nil, :test=>true
|
63
90
|
end
|
64
91
|
|
65
|
-
test "
|
66
|
-
|
92
|
+
test "generates a valid bolt" do
|
93
|
+
mock($stdout).puts /Generated following/, [" **/*"]
|
94
|
+
mock(config).save
|
95
|
+
generate 'wild', :once=>nil
|
67
96
|
end
|
68
97
|
|
69
|
-
test "and
|
70
|
-
|
98
|
+
test "and explicit generator generates a valid bolt" do
|
99
|
+
mock($stdout).puts /Generated following/, [" **/*"]
|
100
|
+
mock(config).save
|
101
|
+
generate 'blah', :once=>'wild'
|
71
102
|
end
|
103
|
+
after_all { config[:bolts] = @old_bolts }
|
72
104
|
end
|
73
105
|
end
|
data/test/lightning.yml
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
context "shell_command command" do
|
4
|
+
def shell_command(*args)
|
5
|
+
run_command :shell_command, args
|
6
|
+
end
|
7
|
+
|
8
|
+
test "lists shell commands" do
|
9
|
+
mock(Commands).puts config.global_commands.sort
|
10
|
+
shell_command('list')
|
11
|
+
end
|
12
|
+
|
13
|
+
context "create" do
|
14
|
+
test "prints error if command alias already exists" do
|
15
|
+
mock(Commands).puts(/Alias/)
|
16
|
+
shell_command 'create', 'cd'
|
17
|
+
end
|
18
|
+
|
19
|
+
test "creates a shell command" do
|
20
|
+
mock(Commands).save_and_say /^Created.*'man'/
|
21
|
+
shell_command 'create', 'man'
|
22
|
+
config.shell_commands['man'].should == 'man'
|
23
|
+
end
|
24
|
+
|
25
|
+
test "creates a shell command with alias" do
|
26
|
+
mock(Commands).save_and_say /Created.*'man'/
|
27
|
+
shell_command 'create', 'man', 'm'
|
28
|
+
config.shell_commands['man'].should == 'm'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test "delete deletes a shell command" do
|
33
|
+
mock(Commands).save_and_say /Deleted.*'man'/
|
34
|
+
config.shell_commands['man'].should.not.be.empty
|
35
|
+
shell_command 'delete', 'man'
|
36
|
+
config.shell_commands['man'].should.be.nil
|
37
|
+
end
|
38
|
+
|
39
|
+
test "delete prints error if nonexistent shell command" do
|
40
|
+
mock(Commands).puts /Can't.*'doy'/
|
41
|
+
shell_command 'delete', 'doy'
|
42
|
+
end
|
43
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Gabriel Horner
|
@@ -14,11 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-13 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
21
|
-
description: Lightning is a commandline framework that
|
21
|
+
description: Lightning is a commandline framework that lets users wrap commands with shell functions that are able to refer to any filesystem path by its basename. To achieve this, a group of paths to be translated are defined with shell globs. These shell globs, known as a lightning _bolt_, are then applied to commands to produce functions. In addition to translating basenames to full paths, lightning _functions_ can autocomplete these basenames, resolve conflicts if they have the same name, leave any non-basename arguments untouched, and autocomplete directories above and below a basename.
|
22
22
|
email: gabriel.horner@gmail.com
|
23
23
|
executables:
|
24
24
|
- lightning
|
@@ -56,15 +56,21 @@ files:
|
|
56
56
|
- lib/lightning/generators/ruby.rb
|
57
57
|
- lib/lightning/util.rb
|
58
58
|
- lib/lightning/version.rb
|
59
|
+
- man/lightning.1
|
60
|
+
- man/lightning.1.ronn
|
61
|
+
- test/bolt_commands_test.rb
|
59
62
|
- test/bolt_test.rb
|
60
63
|
- test/builder_test.rb
|
61
64
|
- test/commands_test.rb
|
62
65
|
- test/completion_map_test.rb
|
63
66
|
- test/completion_test.rb
|
64
67
|
- test/config_test.rb
|
68
|
+
- test/core_commands_test.rb
|
69
|
+
- test/function_commands_test.rb
|
65
70
|
- test/function_test.rb
|
66
71
|
- test/generator_test.rb
|
67
72
|
- test/lightning.yml
|
73
|
+
- test/shell_command_commands_test.rb
|
68
74
|
- test/test_helper.rb
|
69
75
|
has_rdoc: yard
|
70
76
|
homepage: http://tagaholic.me/lightning
|
@@ -73,7 +79,7 @@ licenses: []
|
|
73
79
|
post_install_message:
|
74
80
|
rdoc_options:
|
75
81
|
- --title
|
76
|
-
- Lightning 0.3.
|
82
|
+
- Lightning 0.3.2 Documentation
|
77
83
|
require_paths:
|
78
84
|
- lib
|
79
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -98,12 +104,16 @@ signing_key:
|
|
98
104
|
specification_version: 3
|
99
105
|
summary: Lightning is a commandline framework that generates shell functions which wrap around commands to autocomplete and translate full paths by their basenames.
|
100
106
|
test_files:
|
107
|
+
- test/bolt_commands_test.rb
|
101
108
|
- test/bolt_test.rb
|
102
109
|
- test/builder_test.rb
|
103
110
|
- test/commands_test.rb
|
104
111
|
- test/completion_map_test.rb
|
105
112
|
- test/completion_test.rb
|
106
113
|
- test/config_test.rb
|
114
|
+
- test/core_commands_test.rb
|
115
|
+
- test/function_commands_test.rb
|
107
116
|
- test/function_test.rb
|
108
117
|
- test/generator_test.rb
|
118
|
+
- test/shell_command_commands_test.rb
|
109
119
|
- test/test_helper.rb
|