rake-repl 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +58 -0
- data/bin/rake-repl +138 -0
- metadata +53 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Vincent Roy
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Rake REPL
|
2
|
+
|
3
|
+
Interactive prompt for Rake.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
gem install rake-repl
|
8
|
+
|
9
|
+
### Recommended
|
10
|
+
|
11
|
+
If you have rlwrap installed you'll get the full benefits of readline: history, reverse searches, etc.
|
12
|
+
|
13
|
+
Custom prompt/colors support via the colorize gem:
|
14
|
+
|
15
|
+
gem install colorize
|
16
|
+
export RAKE_REPL_PROMPT="[red:rake][blue: >>][ ]"
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Simply replace `rake` with `rake-repl`.
|
21
|
+
|
22
|
+
### The REPL
|
23
|
+
|
24
|
+
Example run against the test Rakefile included in the project.
|
25
|
+
|
26
|
+
$ rake-repl
|
27
|
+
rake >> list
|
28
|
+
coordinates[x,y]
|
29
|
+
env:is:reset
|
30
|
+
list
|
31
|
+
|
32
|
+
rake >> coordinates[1,2]
|
33
|
+
Draw pixel at [1,2]
|
34
|
+
|
35
|
+
rake >> coordinates[1,2] env:is:reset
|
36
|
+
Draw pixel at [1,2]
|
37
|
+
ENV['STEP']: 0
|
38
|
+
|
39
|
+
rake >> env:is:reset STEP=2
|
40
|
+
ENV['STEP']: 2
|
41
|
+
|
42
|
+
rake >> env:is:reset
|
43
|
+
ENV['STEP']: 0
|
44
|
+
|
45
|
+
rake >> exit
|
46
|
+
Use Ctrl-D (i.e. EOF) to exit
|
47
|
+
|
48
|
+
## TODO
|
49
|
+
|
50
|
+
* Running -T does not work - for some reason, when the tasks aren't loaded with `rake`, the comments are not loaded properly.
|
51
|
+
|
52
|
+
## Credit
|
53
|
+
|
54
|
+
* Chris Wanstrath for a nice implementation of a [REPL](https://github.com/defunkt/repl) that I heavily based myself on.
|
55
|
+
|
56
|
+
## Author
|
57
|
+
|
58
|
+
Vincent Roy :: vince@vroy.ca
|
data/bin/rake-repl
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Rake REPL (read-eval-print loop)
|
4
|
+
#
|
5
|
+
# Load your Rake environment once and get an interactive program to execute multiple tasks easily.
|
6
|
+
|
7
|
+
# If rlwrap exists, wrap our REPL to get all the nice benefits of readline.
|
8
|
+
if !ENV['__REPL_WRAPPED'] && system("which rlwrap > /dev/null 2> /dev/null")
|
9
|
+
ENV['__REPL_WRAPPED'] = '0'
|
10
|
+
exec "rlwrap #$0 #{ARGV.join(' ')}"
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'rubygems'
|
15
|
+
gem 'rake'
|
16
|
+
rescue LoadError
|
17
|
+
end
|
18
|
+
|
19
|
+
require "rake"
|
20
|
+
|
21
|
+
Rake.application.init
|
22
|
+
Rake.application.load_rakefile
|
23
|
+
|
24
|
+
task :list do
|
25
|
+
Rake.application.tasks.each do |task|
|
26
|
+
puts "#{task.name_with_args}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Rake
|
31
|
+
class Application
|
32
|
+
def reset_options
|
33
|
+
@options = OpenStruct.new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def invoke_two(input)
|
39
|
+
# Save the current environment
|
40
|
+
tmp_env = { }
|
41
|
+
ENV.each{|k, v| tmp_env[k] = v }
|
42
|
+
|
43
|
+
cmd = %(ARGV = #{input.split(" ").inspect})
|
44
|
+
|
45
|
+
# Update stderr so that when we run the eval command and dynamically assign a
|
46
|
+
# constant, we don't get a message in the REPL.
|
47
|
+
silence = $stderr
|
48
|
+
$stderr = File.open("/dev/null", "w")
|
49
|
+
eval(cmd)
|
50
|
+
$stderr = silence
|
51
|
+
|
52
|
+
Rake.application.reset_options
|
53
|
+
Rake.application.init
|
54
|
+
Rake.application.tasks.each do |task|
|
55
|
+
task.reenable
|
56
|
+
end
|
57
|
+
Rake.application.top_level
|
58
|
+
|
59
|
+
# Reset the environment to what was saved before
|
60
|
+
ENV.each{|k, v| ENV.delete(k) }
|
61
|
+
tmp_env.each{|k, v| ENV[k] = v }
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
# Set the prompt string to "rake >> " or the string defined by ENV["RAKE_REPL_PROMPT"]
|
66
|
+
# An example of ENV["RAKE_REPL_PROMPT"]
|
67
|
+
# "[red:rake][blue: >>][ ]"
|
68
|
+
|
69
|
+
$prompt_string = "rake >> "
|
70
|
+
if ENV["RAKE_REPL_PROMPT"]
|
71
|
+
begin
|
72
|
+
require "colorize"
|
73
|
+
|
74
|
+
$prompt_string = ""
|
75
|
+
ENV["RAKE_REPL_PROMPT"].scan(/\[((\w+):)?([^\[]*)\]/).each do |color_wrapper, color, text|
|
76
|
+
$prompt_string << ((color.nil?) ? text : "#{text.send(color)}")
|
77
|
+
end
|
78
|
+
rescue LoadError
|
79
|
+
puts "Couldn't require colorize, please run `gem install colorize` for a custom RAKE_REPL_PROMPT."
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
loop do
|
84
|
+
print $prompt_string
|
85
|
+
|
86
|
+
begin
|
87
|
+
line = $stdin.gets.chomp
|
88
|
+
rescue NoMethodError, Interrupt
|
89
|
+
exit
|
90
|
+
end
|
91
|
+
|
92
|
+
next if line.empty?
|
93
|
+
|
94
|
+
if line =~ /^(exit|quit)$/
|
95
|
+
puts "Use Ctrl-D (i.e. EOF) to exit"
|
96
|
+
next
|
97
|
+
end
|
98
|
+
|
99
|
+
begin
|
100
|
+
invoke_two(line)
|
101
|
+
puts
|
102
|
+
rescue SystemExit => e
|
103
|
+
# ignore exit's from rake's command, like the exit on -H
|
104
|
+
rescue Exception => e
|
105
|
+
puts "#{e.class} - #{e}"
|
106
|
+
puts e.backtrace
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
__END__
|
114
|
+
=begin
|
115
|
+
# A nicer way to handle invoking the task, but this would require us to parse
|
116
|
+
# the arguments ourselves. Simulating Rake.application.run without the
|
117
|
+
# load_rakefile seems like a better option to be Rake compatible as much as
|
118
|
+
# possible.
|
119
|
+
def invoke_task(input)
|
120
|
+
parts = input.split(" ")
|
121
|
+
task = parts.shift
|
122
|
+
|
123
|
+
tmp_env = {}
|
124
|
+
parts.each do |e|
|
125
|
+
key, value = e.split("=")
|
126
|
+
tmp_env[key] = ENV[key]
|
127
|
+
ENV[key] = value
|
128
|
+
end
|
129
|
+
|
130
|
+
Rake::Task[task].reenable
|
131
|
+
Rake::Task[task].invoke
|
132
|
+
|
133
|
+
# Cleanup ENV from this rake task run.
|
134
|
+
tmp_env.each do |key, value|
|
135
|
+
ENV.delete(key)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
=end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rake-repl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vincent Roy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-09 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'Load your Rake environment once and get an interactive program to
|
15
|
+
execute
|
16
|
+
|
17
|
+
multiple tasks easily.
|
18
|
+
|
19
|
+
'
|
20
|
+
email: vince@vroy.ca
|
21
|
+
executables:
|
22
|
+
- rake-repl
|
23
|
+
extensions: []
|
24
|
+
extra_rdoc_files: []
|
25
|
+
files:
|
26
|
+
- README.md
|
27
|
+
- LICENSE
|
28
|
+
- bin/rake-repl
|
29
|
+
homepage: http://github.com/exploid/rake-repl
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.15
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Interactive prompt for Rake.
|
53
|
+
test_files: []
|