lightning 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +9 -0
- data/README.rdoc +53 -125
- data/Rakefile +14 -40
- data/bin/lightning +4 -0
- data/bin/lightning-complete +1 -10
- data/bin/lightning-translate +4 -0
- data/lib/lightning.rb +36 -50
- data/lib/lightning/bolt.rb +53 -26
- data/lib/lightning/builder.rb +87 -0
- data/lib/lightning/commands.rb +92 -69
- data/lib/lightning/commands/bolt.rb +63 -0
- data/lib/lightning/commands/core.rb +57 -0
- data/lib/lightning/commands/function.rb +76 -0
- data/lib/lightning/commands/shell_command.rb +38 -0
- data/lib/lightning/commands_util.rb +75 -0
- data/lib/lightning/completion.rb +72 -28
- data/lib/lightning/completion_map.rb +42 -39
- data/lib/lightning/config.rb +92 -57
- data/lib/lightning/function.rb +70 -0
- data/lib/lightning/generator.rb +77 -43
- data/lib/lightning/generators.rb +53 -0
- data/lib/lightning/generators/misc.rb +12 -0
- data/lib/lightning/generators/ruby.rb +32 -0
- data/lib/lightning/util.rb +70 -0
- data/lib/lightning/version.rb +3 -0
- data/test/bolt_test.rb +16 -28
- data/test/builder_test.rb +54 -0
- data/test/commands_test.rb +98 -0
- data/test/completion_map_test.rb +31 -54
- data/test/completion_test.rb +106 -36
- data/test/config_test.rb +22 -56
- data/test/function_test.rb +90 -0
- data/test/generator_test.rb +73 -0
- data/test/lightning.yml +26 -34
- data/test/test_helper.rb +80 -15
- metadata +42 -20
- data/VERSION.yml +0 -4
- data/bin/lightning-full_path +0 -18
- data/bin/lightning-install +0 -7
- data/lib/lightning/bolts.rb +0 -12
- data/lightning.yml.example +0 -87
- data/lightning_completions.example +0 -147
- data/test/lightning_test.rb +0 -58
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
context "Generator" do
|
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
|
+
def generate(*args)
|
17
|
+
args[-1].is_a?(Hash) ? args.pop : {}
|
18
|
+
Generator.run args, {}
|
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
|
+
config = YAML::load_file(config_file)
|
26
|
+
Generator::DEFAULT_GENERATORS.all? {|e| config[: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 "prints nonexistant generators while continuing with good generators" do
|
36
|
+
# stub.instance_of(Generator).underling.stub(send) { {} } #`
|
37
|
+
# capture_stdout {
|
38
|
+
# generate :gem, :bad
|
39
|
+
# }.should =~ /^Generator 'bad' failed/
|
40
|
+
# end
|
41
|
+
|
42
|
+
test "handles unexpected error while generating bolts" do
|
43
|
+
mock.instance_of(Generator).generate_bolts(anything) { raise "Totally unexpected" }
|
44
|
+
mock($stderr).puts(/Error: Totally/)
|
45
|
+
generate :gem
|
46
|
+
end
|
47
|
+
|
48
|
+
context "generates" do
|
49
|
+
before_all {
|
50
|
+
Lightning.config[:bolts]['overwrite'] = {'globs'=>['overwrite me']}
|
51
|
+
Generators.send(:define_method, :user_bolt) { ['glob1', 'glob2'] }
|
52
|
+
Generators.send(:define_method, :overwrite) { ['overwritten'] }
|
53
|
+
mock(Lightning.config).save
|
54
|
+
generate 'wild', 'user_bolt', 'overwrite'
|
55
|
+
}
|
56
|
+
|
57
|
+
test "a default bolt" do
|
58
|
+
Lightning.config[:bolts]['wild']['globs'].should == ['**/*']
|
59
|
+
end
|
60
|
+
|
61
|
+
test "a user-specified bolt" do
|
62
|
+
Lightning.config[:bolts]['user_bolt']['globs'].should == ['glob1', 'glob2']
|
63
|
+
end
|
64
|
+
|
65
|
+
test "and overwrites existing bolts" do
|
66
|
+
Lightning.config[:bolts]['overwrite']['globs'].should == ["overwritten"]
|
67
|
+
end
|
68
|
+
|
69
|
+
test "and preserves bolts that aren't being generated" do
|
70
|
+
Lightning.config[:bolts]['app'].class.should == Hash
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/test/lightning.yml
CHANGED
@@ -1,39 +1,31 @@
|
|
1
1
|
---
|
2
|
-
|
2
|
+
source_file: lightning_completions
|
3
3
|
|
4
4
|
ignore_paths:
|
5
|
-
|
6
|
-
|
5
|
+
- .DS_Store
|
6
|
+
- .git
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
bolts:
|
9
|
+
app:
|
10
|
+
global: true
|
11
|
+
functions:
|
12
|
+
- shell_command: more
|
13
|
+
name: bling
|
14
|
+
- less
|
15
|
+
- shell_command: cd
|
16
|
+
name : c
|
10
17
|
- name : oa
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
- /Library/Ruby/Site/1.8/**/
|
26
|
-
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/**/
|
27
|
-
|
28
|
-
paths:
|
29
|
-
# to obtain your own paths to your ruby gems:
|
30
|
-
# `gem environment path`.split(":").map {|e| e +"/gems/*" }
|
31
|
-
gem:
|
32
|
-
- /Users/bozo/.gem/ruby/1.8/gems/*
|
33
|
-
- /Library/Ruby/Gems/1.8/gems/*
|
34
|
-
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/*
|
35
|
-
|
36
|
-
gem_rdoc:
|
37
|
-
- /Users/bozo/.gem/ruby/1.8/doc/*
|
38
|
-
- /Library/Ruby/Gems/1.8/doc/*
|
39
|
-
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/doc/*
|
18
|
+
shell_command : open -a
|
19
|
+
desc : open mac applications
|
20
|
+
aliases:
|
21
|
+
a1: /dir/a1
|
22
|
+
a2: /dir/a2
|
23
|
+
path3: /dir/a3
|
24
|
+
desc: Desktop applications
|
25
|
+
globs:
|
26
|
+
- /Applications/*.app
|
27
|
+
- /Applications/Utilities/*.app
|
28
|
+
shell_commands:
|
29
|
+
vim: v
|
30
|
+
grep: grep
|
31
|
+
cd: cd
|
data/test/test_helper.rb
CHANGED
@@ -1,24 +1,89 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
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
|
6
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
1
|
+
require 'bacon'
|
2
|
+
require 'rr'
|
7
3
|
require 'lightning'
|
8
4
|
#set up valid global config file
|
9
|
-
Lightning::Config.config_file = File.join(File.dirname(__FILE__), 'lightning.yml')
|
5
|
+
Lightning::Config.config_file = File.join(File.dirname(__FILE__), 'lightning.yml')
|
6
|
+
include Lightning
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
assert_equal a1.map {|e| e.to_s}.sort, a2.map{|e| e.to_s}.sort
|
8
|
+
module Helpers
|
9
|
+
def run_command(command, args=[])
|
10
|
+
Commands.run([command] + args)
|
15
11
|
end
|
16
12
|
|
13
|
+
def assert_arrays_equal(a1, a2)
|
14
|
+
a1.map {|e| e.to_s}.sort.should == a2.map{|e| e.to_s}.sort
|
15
|
+
end
|
16
|
+
|
17
|
+
def capture_stdout(&block)
|
18
|
+
original_stdout = $stdout
|
19
|
+
$stdout = fake = StringIO.new
|
20
|
+
begin
|
21
|
+
yield
|
22
|
+
ensure
|
23
|
+
$stdout = original_stdout
|
24
|
+
end
|
25
|
+
fake.string
|
26
|
+
end
|
27
|
+
|
28
|
+
# from ActiveSupport
|
29
|
+
def slice_hash(*keys)
|
30
|
+
keys.shift.reject { |key,| !keys.include?(key) }
|
31
|
+
end
|
17
32
|
end
|
18
33
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
34
|
+
module BaconExtensions
|
35
|
+
def self.included(mod)
|
36
|
+
mod.module_eval do
|
37
|
+
# nested context methods automatically inherit methods from parent contexts
|
38
|
+
def describe(*args, &block)
|
39
|
+
context = Bacon::Context.new(args.join(' '), &block)
|
40
|
+
(parent_context = self).methods(false).each {|e|
|
41
|
+
class<<context; self end.send(:define_method, e) {|*args| parent_context.send(e, *args)}
|
42
|
+
}
|
43
|
+
@before.each { |b| context.before(&b) }
|
44
|
+
@after.each { |b| context.after(&b) }
|
45
|
+
context.run
|
46
|
+
end
|
47
|
+
end
|
23
48
|
end
|
49
|
+
|
50
|
+
def xtest(*args); end
|
51
|
+
def xcontext(*args); end
|
52
|
+
def before_all; yield; end
|
53
|
+
def after_all; yield; end
|
54
|
+
def assert(description, &block)
|
55
|
+
it(description) do
|
56
|
+
block.call.should == true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Bacon::Context
|
62
|
+
include Helpers
|
63
|
+
include BaconExtensions
|
64
|
+
|
65
|
+
# RR adapter
|
66
|
+
def self.silent?
|
67
|
+
@silent ||= class << Bacon; self; end.ancestors.include?(Bacon::TestUnitOutput)
|
68
|
+
end
|
69
|
+
include RR::Adapters::RRMethods
|
70
|
+
RR.trim_backtrace = true
|
71
|
+
alias_method :old_it, :it
|
72
|
+
def it(description)
|
73
|
+
old_it(description) do
|
74
|
+
# Add at least one requirement to ensure mock-only tests don't fail
|
75
|
+
Bacon::Counter[:requirements] += 1
|
76
|
+
yield
|
77
|
+
Bacon::Counter[:requirements] -= 1 if RR.double_injections.size.zero?
|
78
|
+
RR.verify unless self.class.silent?
|
79
|
+
RR.reset
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
alias_method :test, :it
|
84
|
+
alias_method :context, :describe
|
24
85
|
end
|
86
|
+
|
87
|
+
class <<self
|
88
|
+
alias_method :context, :describe
|
89
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Gabriel Horner
|
@@ -9,16 +14,16 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-04-09 00:00:00 -04:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
16
|
-
description: Lightning
|
21
|
+
description: Lightning is a commandline framework that changes how you use paths in your filesystem. Lightning generates shell functions which wrap any command with the ability to autocomplete and interpret paths simply by their basenames. With these functions you don't have to ever type the full path to any file for any command again.
|
17
22
|
email: gabriel.horner@gmail.com
|
18
23
|
executables:
|
24
|
+
- lightning
|
19
25
|
- lightning-complete
|
20
|
-
- lightning-
|
21
|
-
- lightning-install
|
26
|
+
- lightning-translate
|
22
27
|
extensions: []
|
23
28
|
|
24
29
|
extra_rdoc_files:
|
@@ -29,59 +34,76 @@ files:
|
|
29
34
|
- LICENSE.txt
|
30
35
|
- README.rdoc
|
31
36
|
- Rakefile
|
32
|
-
-
|
37
|
+
- bin/lightning
|
33
38
|
- bin/lightning-complete
|
34
|
-
- bin/lightning-
|
35
|
-
- bin/lightning-install
|
39
|
+
- bin/lightning-translate
|
36
40
|
- lib/lightning.rb
|
37
41
|
- lib/lightning/bolt.rb
|
38
|
-
- lib/lightning/
|
42
|
+
- lib/lightning/builder.rb
|
39
43
|
- lib/lightning/commands.rb
|
44
|
+
- lib/lightning/commands/bolt.rb
|
45
|
+
- lib/lightning/commands/core.rb
|
46
|
+
- lib/lightning/commands/function.rb
|
47
|
+
- lib/lightning/commands/shell_command.rb
|
48
|
+
- lib/lightning/commands_util.rb
|
40
49
|
- lib/lightning/completion.rb
|
41
50
|
- lib/lightning/completion_map.rb
|
42
51
|
- lib/lightning/config.rb
|
52
|
+
- lib/lightning/function.rb
|
43
53
|
- lib/lightning/generator.rb
|
44
|
-
- lightning.
|
45
|
-
-
|
54
|
+
- lib/lightning/generators.rb
|
55
|
+
- lib/lightning/generators/misc.rb
|
56
|
+
- lib/lightning/generators/ruby.rb
|
57
|
+
- lib/lightning/util.rb
|
58
|
+
- lib/lightning/version.rb
|
46
59
|
- test/bolt_test.rb
|
60
|
+
- test/builder_test.rb
|
61
|
+
- test/commands_test.rb
|
47
62
|
- test/completion_map_test.rb
|
48
63
|
- test/completion_test.rb
|
49
64
|
- test/config_test.rb
|
65
|
+
- test/function_test.rb
|
66
|
+
- test/generator_test.rb
|
50
67
|
- test/lightning.yml
|
51
|
-
- test/lightning_test.rb
|
52
68
|
- test/test_helper.rb
|
53
|
-
has_rdoc:
|
54
|
-
homepage: http://
|
69
|
+
has_rdoc: yard
|
70
|
+
homepage: http://tagaholic.me/lightning
|
55
71
|
licenses: []
|
56
72
|
|
57
73
|
post_install_message:
|
58
74
|
rdoc_options:
|
59
|
-
- --
|
75
|
+
- --title
|
76
|
+
- Lightning 0.3.0 Documentation
|
60
77
|
require_paths:
|
61
78
|
- lib
|
62
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
80
|
requirements:
|
64
81
|
- - ">="
|
65
82
|
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
66
85
|
version: "0"
|
67
|
-
version:
|
68
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
87
|
requirements:
|
70
88
|
- - ">="
|
71
89
|
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
72
92
|
version: "0"
|
73
|
-
version:
|
74
93
|
requirements: []
|
75
94
|
|
76
95
|
rubyforge_project: tagaholic
|
77
|
-
rubygems_version: 1.3.
|
96
|
+
rubygems_version: 1.3.6
|
78
97
|
signing_key:
|
79
98
|
specification_version: 3
|
80
|
-
summary:
|
99
|
+
summary: Lightning is a commandline framework that generates shell functions which wrap around commands to autocomplete and translate full paths by their basenames.
|
81
100
|
test_files:
|
82
101
|
- test/bolt_test.rb
|
102
|
+
- test/builder_test.rb
|
103
|
+
- test/commands_test.rb
|
83
104
|
- test/completion_map_test.rb
|
84
105
|
- test/completion_test.rb
|
85
106
|
- test/config_test.rb
|
86
|
-
- test/
|
107
|
+
- test/function_test.rb
|
108
|
+
- test/generator_test.rb
|
87
109
|
- test/test_helper.rb
|
data/VERSION.yml
DELETED
data/bin/lightning-full_path
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# == Description
|
4
|
-
# Used by path completion functions to return first possible full path which matches the given basename for the given command.
|
5
|
-
|
6
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "..","lib","lightning"))
|
7
|
-
|
8
|
-
command = ARGV.shift
|
9
|
-
if command.nil?
|
10
|
-
puts "No command given"
|
11
|
-
exit 1
|
12
|
-
end
|
13
|
-
if ARGV.empty?
|
14
|
-
puts "No arguments given"
|
15
|
-
exit 1
|
16
|
-
end
|
17
|
-
puts Lightning.translate(command, ARGV)
|
18
|
-
exit 0
|
data/bin/lightning-install
DELETED
data/lib/lightning/bolts.rb
DELETED
data/lightning.yml.example
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
---
|
2
|
-
generated_file: lightning_completions
|
3
|
-
|
4
|
-
ignore_paths:
|
5
|
-
- .DS_Store
|
6
|
-
- .git
|
7
|
-
|
8
|
-
# You'll notice that most commands have the format of "#{original_command_alias}-#{path_alias}"
|
9
|
-
# I recommend this for most of these commands as you can then easily autocomplete them for recall.
|
10
|
-
commands:
|
11
|
-
- name : c
|
12
|
-
map_to : cd
|
13
|
-
description : my code directories
|
14
|
-
paths:
|
15
|
-
- /Users/bozo/code/gems/*
|
16
|
-
- /Users/bozo/code/repo/*
|
17
|
-
- /Users/bozo/code/tds/gems/*
|
18
|
-
|
19
|
-
- name : cd-g
|
20
|
-
map_to : cd
|
21
|
-
paths: gem
|
22
|
-
|
23
|
-
- name : m-g
|
24
|
-
map_to : mate
|
25
|
-
paths: gem
|
26
|
-
|
27
|
-
- name : o-g
|
28
|
-
map_to : open
|
29
|
-
description : open gem's doc in browser
|
30
|
-
post_path : /rdoc/index.html
|
31
|
-
paths: gem_rdoc
|
32
|
-
|
33
|
-
- name : v-r
|
34
|
-
map_to : vim
|
35
|
-
description : ruby core files
|
36
|
-
paths:
|
37
|
-
#picked from $LOAD_PATH
|
38
|
-
- /Library/Ruby/Site/1.8/**/*.rb
|
39
|
-
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/**/*.rb
|
40
|
-
|
41
|
-
- name : cd-r
|
42
|
-
map_to : cd
|
43
|
-
description : ruby core directories
|
44
|
-
paths:
|
45
|
-
- /Library/Ruby/Site/1.8/**/
|
46
|
-
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/**/
|
47
|
-
aliases:
|
48
|
-
r1: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8
|
49
|
-
|
50
|
-
- name : oa
|
51
|
-
map_to : open -a
|
52
|
-
description : open mac applications
|
53
|
-
paths:
|
54
|
-
- /Applications/*.app
|
55
|
-
- /Applications/Utilities/*.app
|
56
|
-
|
57
|
-
- name : v-g
|
58
|
-
map_to : vim
|
59
|
-
description : open files when in the base directory of a ruby gem project
|
60
|
-
paths:
|
61
|
-
- lib/**/*.rb
|
62
|
-
- test/**/*.rb
|
63
|
-
- spec/**/*.rb
|
64
|
-
- bin/**
|
65
|
-
|
66
|
-
- name : v-rr
|
67
|
-
map_to : vim
|
68
|
-
description: open files when in the base directory of a rails project
|
69
|
-
paths:
|
70
|
-
- config/**/*.rb
|
71
|
-
- app/**/*.{rb,erb,rhtml}
|
72
|
-
- lib/**/*.rb
|
73
|
-
- test/**/*.rb
|
74
|
-
- spec/**/*.rb
|
75
|
-
|
76
|
-
paths:
|
77
|
-
# to obtain your own paths to your ruby gems:
|
78
|
-
# `gem environment path`.split(":").map {|e| e +"/gems/*" }
|
79
|
-
gem:
|
80
|
-
- /Users/bozo/.gem/ruby/1.8/gems/*
|
81
|
-
- /Library/Ruby/Gems/1.8/gems/*
|
82
|
-
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/*
|
83
|
-
|
84
|
-
gem_rdoc:
|
85
|
-
- /Users/bozo/.gem/ruby/1.8/doc/*
|
86
|
-
- /Library/Ruby/Gems/1.8/doc/*
|
87
|
-
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/doc/*
|