daemon-kit 0.1.8rc2 → 0.1.8rc3
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/Rakefile +1 -0
- data/daemon-kit.gemspec +36 -36
- data/lib/daemon_kit.rb +1 -1
- data/lib/daemon_kit/amqp.rb +1 -0
- data/lib/daemon_kit/cron.rb +16 -0
- data/lib/daemon_kit/deployment/capistrano.rb +34 -0
- data/lib/daemon_kit/error_handlers/hoptoad.rb +8 -2
- data/lib/daemon_kit/generators.rb +1 -1
- data/lib/daemon_kit/generators/base.rb +1 -1
- data/lib/daemon_kit/ruote_participants.rb +7 -1
- data/lib/daemon_kit/ruote_workitem.rb +30 -20
- data/lib/daemon_kit/tasks/environment.rake +1 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/CHANGELOG.rdoc +9 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/LICENSE +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/README.rdoc +65 -2
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/Thorfile +14 -9
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor.rb +10 -8
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions.rb +34 -12
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions/create_file.rb +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions/directory.rb +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions/empty_directory.rb +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions/file_manipulation.rb +1 -1
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions/inject_into_file.rb +9 -6
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/base.rb +45 -20
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/core_ext/file_binary_read.rb +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/core_ext/hash_with_indifferent_access.rb +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/core_ext/ordered_hash.rb +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/error.rb +3 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/group.rb +21 -21
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/invocation.rb +19 -17
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/parser.rb +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/parser/argument.rb +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/parser/arguments.rb +9 -4
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/parser/option.rb +0 -4
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/parser/options.rb +41 -14
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/rake_compat.rb +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/runner.rb +20 -9
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/shell.rb +8 -3
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/shell/basic.rb +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/shell/color.rb +0 -0
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/task.rb +24 -33
- data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/util.rb +9 -18
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/version.rb +3 -0
- data/lib/generators/daemon_kit/amqp/amqp_generator.rb +1 -1
- data/lib/generators/daemon_kit/amqp/templates/config/pre-daemonize/amqp.rb +1 -1
- data/lib/generators/daemon_kit/app/app_generator.rb +1 -1
- data/lib/generators/daemon_kit/app/templates/README.tt +58 -0
- data/lib/generators/daemon_kit/capistrano/capistrano_generator.rb +5 -0
- data/lib/generators/daemon_kit/cron/cron_generator.rb +1 -1
- data/lib/generators/daemon_kit/cron/templates/config/pre-daemonize/cron.rb +1 -1
- data/lib/generators/daemon_kit/nanite_agent/nanite_agent_generator.rb +1 -1
- data/lib/generators/daemon_kit/nanite_agent/templates/config/pre-daemonize/nanite_agent.rb +1 -1
- data/lib/generators/daemon_kit/ruote/ruote_generator.rb +2 -2
- data/lib/generators/daemon_kit/ruote/templates/config/pre-daemonize/ruote.rb +2 -2
- data/lib/generators/daemon_kit/xmpp/templates/config/pre-daemonize/xmpp.rb +1 -1
- data/lib/generators/daemon_kit/xmpp/xmpp_generator.rb +1 -1
- data/tasks/rspec.rake +6 -7
- metadata +77 -49
- data/lib/daemon_kit/vendor/thor-0.12.3/lib/thor/version.rb +0 -3
- data/lib/generators/daemon_kit/app/templates/README +0 -48
|
File without changes
|
|
@@ -145,7 +145,7 @@ When invoking the task one:
|
|
|
145
145
|
|
|
146
146
|
The output is "1 2 3", which means that the three task was invoked only once.
|
|
147
147
|
You can even invoke tasks from another class, so be sure to check the
|
|
148
|
-
documentation.
|
|
148
|
+
documentation[http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor.html].
|
|
149
149
|
|
|
150
150
|
== Thor::Group
|
|
151
151
|
|
|
@@ -227,7 +227,70 @@ To use them, you just need to include Thor::Actions in your Thor classes:
|
|
|
227
227
|
|
|
228
228
|
Some actions like copy file requires that a class method called source_root is
|
|
229
229
|
defined in your class. This is the directory where your templates should be
|
|
230
|
-
placed. Be sure to check the documentation.
|
|
230
|
+
placed. Be sure to check the documentation on actions[http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html].
|
|
231
|
+
|
|
232
|
+
== Generators
|
|
233
|
+
|
|
234
|
+
A great use for Thor is creating custom generators. Combining Thor::Group,
|
|
235
|
+
Thor::Actions and ERB templates makes this very easy. Here is an example:
|
|
236
|
+
|
|
237
|
+
class Newgem < Thor::Group
|
|
238
|
+
include Thor::Actions
|
|
239
|
+
|
|
240
|
+
# Define arguments and options
|
|
241
|
+
argument :name
|
|
242
|
+
class_option :test_framework, :default => :test_unit
|
|
243
|
+
|
|
244
|
+
def self.source_root
|
|
245
|
+
File.dirname(__FILE__)
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def create_lib_file
|
|
249
|
+
template('templates/newgem.tt', "#{name}/lib/#{name}.rb")
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def create_test_file
|
|
253
|
+
test = options[:test_framework] == "rspec" ? :spec : :test
|
|
254
|
+
create_file "#{name}/#{test}/#{name}_#{test}.rb"
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def copy_licence
|
|
258
|
+
if yes?("Use MIT license?")
|
|
259
|
+
# Make a copy of the MITLICENSE file at the source root
|
|
260
|
+
copy_file "MITLICENSE", "#{name}/MITLICENSE"
|
|
261
|
+
else
|
|
262
|
+
say "Shame on you…", :red
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
Doing a <tt>thor -T</tt> will show how to run our generator. It should read:
|
|
268
|
+
<tt>thor newgem NAME</tt>. This shows that we have to supply a NAME
|
|
269
|
+
argument for our generator to run.
|
|
270
|
+
|
|
271
|
+
The <tt>create_lib_file</tt> uses an ERB template. This is what it looks like:
|
|
272
|
+
|
|
273
|
+
class <%= name.capitalize %>
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
The arguments that you set in your generator will automatically be passed in
|
|
277
|
+
when <tt>template</tt> gets called. Be sure to read the documentation[http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html] for
|
|
278
|
+
more options.
|
|
279
|
+
|
|
280
|
+
Running the generator with <tt>thor newgem devise</tt> will
|
|
281
|
+
create two files: "devise/lib/devise.rb",
|
|
282
|
+
"devise/test/devise_test.rb". The user will then be prompt (with the
|
|
283
|
+
use of the method <tt>yes?</tt>) if he wants to copy the MITLICENSE. If you
|
|
284
|
+
want to change the test framework, you can add the option:
|
|
285
|
+
<tt>thor newgem devise --test-framework=rspec</tt>
|
|
286
|
+
This will generate: "devise/lib/devise.rb" and
|
|
287
|
+
"devise/spec/devise_spec.rb".
|
|
288
|
+
|
|
289
|
+
== Further Reading
|
|
290
|
+
|
|
291
|
+
Thor has many scripting possibilities beyond these examples. Be sure to read
|
|
292
|
+
through the documentation[http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor.html] and specs[http://github.com/wycats/thor/tree/master/spec/] to get a better understanding of all the
|
|
293
|
+
options Thor offers.
|
|
231
294
|
|
|
232
295
|
== License
|
|
233
296
|
|
|
@@ -4,7 +4,10 @@ require File.join(File.dirname(__FILE__), "lib", "thor", "version")
|
|
|
4
4
|
require 'rubygems'
|
|
5
5
|
require 'thor/rake_compat'
|
|
6
6
|
require 'spec/rake/spectask'
|
|
7
|
-
|
|
7
|
+
begin
|
|
8
|
+
require 'rdoc/task'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
end
|
|
8
11
|
|
|
9
12
|
GEM_NAME = 'thor'
|
|
10
13
|
EXTRA_RDOC_FILES = ["README.rdoc", "LICENSE", "CHANGELOG.rdoc", "VERSION", "Thorfile"]
|
|
@@ -26,13 +29,15 @@ class Default < Thor
|
|
|
26
29
|
t.rcov_dir = "rcov"
|
|
27
30
|
end
|
|
28
31
|
|
|
29
|
-
RDoc
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
if defined?(RDoc)
|
|
33
|
+
RDoc::Task.new do |rdoc|
|
|
34
|
+
rdoc.main = "README.rdoc"
|
|
35
|
+
rdoc.rdoc_dir = "rdoc"
|
|
36
|
+
rdoc.title = GEM_NAME
|
|
37
|
+
rdoc.rdoc_files.include(*EXTRA_RDOC_FILES)
|
|
38
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
39
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
|
40
|
+
end
|
|
36
41
|
end
|
|
37
42
|
|
|
38
43
|
begin
|
|
@@ -59,6 +64,6 @@ class Default < Thor
|
|
|
59
64
|
|
|
60
65
|
Jeweler::GemcutterTasks.new
|
|
61
66
|
rescue LoadError
|
|
62
|
-
puts "Jeweler, or one of its dependencies, is not available. Install it with:
|
|
67
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
|
|
63
68
|
end
|
|
64
69
|
end
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
require 'thor/base'
|
|
2
|
-
require 'thor/group'
|
|
3
|
-
require 'thor/actions'
|
|
4
2
|
|
|
5
3
|
# TODO: Update thor to allow for git-style CLI (git bisect run)
|
|
6
4
|
class Thor
|
|
@@ -122,8 +120,8 @@ class Thor
|
|
|
122
120
|
# script = MyScript.new(args, options, config)
|
|
123
121
|
# script.invoke(:task, first_arg, second_arg, third_arg)
|
|
124
122
|
#
|
|
125
|
-
def start(
|
|
126
|
-
super do
|
|
123
|
+
def start(original_args=ARGV, config={})
|
|
124
|
+
super do |given_args|
|
|
127
125
|
meth = normalize_task_name(given_args.shift)
|
|
128
126
|
task = all_tasks[meth]
|
|
129
127
|
|
|
@@ -147,8 +145,9 @@ class Thor
|
|
|
147
145
|
# task_name<String>
|
|
148
146
|
#
|
|
149
147
|
def task_help(shell, task_name)
|
|
150
|
-
|
|
151
|
-
|
|
148
|
+
meth = normalize_task_name(task_name)
|
|
149
|
+
task = all_tasks[meth]
|
|
150
|
+
handle_no_task_error(meth) unless task
|
|
152
151
|
|
|
153
152
|
shell.say "Usage:"
|
|
154
153
|
shell.say " #{banner(task)}"
|
|
@@ -185,6 +184,10 @@ class Thor
|
|
|
185
184
|
end
|
|
186
185
|
end
|
|
187
186
|
|
|
187
|
+
def handle_argument_error(task, error) #:nodoc:
|
|
188
|
+
raise InvocationError, "#{task.name.inspect} was called incorrectly. Call as #{task.formatted_usage(self, banner_base == "thor").inspect}."
|
|
189
|
+
end
|
|
190
|
+
|
|
188
191
|
protected
|
|
189
192
|
|
|
190
193
|
# The banner for this class. You can customize it if you are invoking the
|
|
@@ -193,8 +196,7 @@ class Thor
|
|
|
193
196
|
# the namespace should be displayed as arguments.
|
|
194
197
|
#
|
|
195
198
|
def banner(task)
|
|
196
|
-
|
|
197
|
-
"#{base} #{task.formatted_usage(self, base == "thor")}"
|
|
199
|
+
"#{banner_base} #{task.formatted_usage(self, banner_base == "thor")}"
|
|
198
200
|
end
|
|
199
201
|
|
|
200
202
|
def baseclass #:nodoc:
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'fileutils'
|
|
2
|
+
require 'uri'
|
|
2
3
|
require 'thor/core_ext/file_binary_read'
|
|
3
4
|
|
|
4
5
|
Dir[File.join(File.dirname(__FILE__), "actions", "*.rb")].each do |action|
|
|
@@ -19,7 +20,13 @@ class Thor
|
|
|
19
20
|
# inherited paths and the source root.
|
|
20
21
|
#
|
|
21
22
|
def source_paths
|
|
22
|
-
@
|
|
23
|
+
@_source_paths ||= []
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Stores and return the source root for this class
|
|
27
|
+
def source_root(path=nil)
|
|
28
|
+
@_source_root = path if path
|
|
29
|
+
@_source_root
|
|
23
30
|
end
|
|
24
31
|
|
|
25
32
|
# Returns the source paths in the following order:
|
|
@@ -31,7 +38,7 @@ class Thor
|
|
|
31
38
|
def source_paths_for_search
|
|
32
39
|
paths = []
|
|
33
40
|
paths += self.source_paths
|
|
34
|
-
paths << self.source_root if self.
|
|
41
|
+
paths << self.source_root if self.source_root
|
|
35
42
|
paths += from_superclass(:source_paths, [])
|
|
36
43
|
paths
|
|
37
44
|
end
|
|
@@ -115,7 +122,7 @@ class Thor
|
|
|
115
122
|
@source_paths ||= self.class.source_paths_for_search
|
|
116
123
|
end
|
|
117
124
|
|
|
118
|
-
# Receives a file or directory and search for it in the source paths.
|
|
125
|
+
# Receives a file or directory and search for it in the source paths.
|
|
119
126
|
#
|
|
120
127
|
def find_in_source_paths(file)
|
|
121
128
|
relative_root = relative_to_original_destination_root(destination_root, false)
|
|
@@ -125,12 +132,19 @@ class Thor
|
|
|
125
132
|
return source_file if File.exists?(source_file)
|
|
126
133
|
end
|
|
127
134
|
|
|
135
|
+
message = "Could not find #{file.inspect} in any of your source paths. "
|
|
136
|
+
|
|
137
|
+
unless self.class.source_root
|
|
138
|
+
message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "
|
|
139
|
+
end
|
|
140
|
+
|
|
128
141
|
if source_paths.empty?
|
|
129
|
-
|
|
130
|
-
"you can define a source_root in your class."
|
|
142
|
+
message << "Currently you have no source paths."
|
|
131
143
|
else
|
|
132
|
-
|
|
144
|
+
message << "Your current source paths are: \n#{source_paths.join("\n")}"
|
|
133
145
|
end
|
|
146
|
+
|
|
147
|
+
raise Error, message
|
|
134
148
|
end
|
|
135
149
|
|
|
136
150
|
# Do something in the root or on a provided subfolder. If a relative path
|
|
@@ -180,11 +194,18 @@ class Thor
|
|
|
180
194
|
|
|
181
195
|
say_status :apply, path, verbose
|
|
182
196
|
shell.padding += 1 if verbose
|
|
183
|
-
|
|
197
|
+
|
|
198
|
+
if URI(path).is_a?(URI::HTTP)
|
|
199
|
+
contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read }
|
|
200
|
+
else
|
|
201
|
+
contents = open(path) {|io| io.read }
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
instance_eval(contents, path)
|
|
184
205
|
shell.padding -= 1 if verbose
|
|
185
206
|
end
|
|
186
207
|
|
|
187
|
-
# Executes a command.
|
|
208
|
+
# Executes a command returning the contents of the command.
|
|
188
209
|
#
|
|
189
210
|
# ==== Parameters
|
|
190
211
|
# command<String>:: the command to be executed.
|
|
@@ -209,7 +230,7 @@ class Thor
|
|
|
209
230
|
end
|
|
210
231
|
|
|
211
232
|
say_status :run, desc, config.fetch(:verbose, true)
|
|
212
|
-
|
|
233
|
+
`#{command}` unless options[:pretend]
|
|
213
234
|
end
|
|
214
235
|
|
|
215
236
|
# Executes a ruby script (taking into account WIN32 platform quirks).
|
|
@@ -220,10 +241,10 @@ class Thor
|
|
|
220
241
|
#
|
|
221
242
|
def run_ruby_script(command, config={})
|
|
222
243
|
return unless behavior == :invoke
|
|
223
|
-
run
|
|
244
|
+
run command, config.merge(:with => Thor::Util.ruby_command)
|
|
224
245
|
end
|
|
225
246
|
|
|
226
|
-
# Run a thor command. A hash of options can be given and it's converted to
|
|
247
|
+
# Run a thor command. A hash of options can be given and it's converted to
|
|
227
248
|
# switches.
|
|
228
249
|
#
|
|
229
250
|
# ==== Parameters
|
|
@@ -243,12 +264,13 @@ class Thor
|
|
|
243
264
|
def thor(task, *args)
|
|
244
265
|
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
245
266
|
verbose = config.key?(:verbose) ? config.delete(:verbose) : true
|
|
267
|
+
pretend = config.key?(:pretend) ? config.delete(:pretend) : false
|
|
246
268
|
|
|
247
269
|
args.unshift task
|
|
248
270
|
args.push Thor::Options.to_switches(config)
|
|
249
271
|
command = args.join(' ').strip
|
|
250
272
|
|
|
251
|
-
run command, :with => :thor, :verbose => verbose
|
|
273
|
+
run command, :with => :thor, :verbose => verbose, :pretend => pretend
|
|
252
274
|
end
|
|
253
275
|
|
|
254
276
|
protected
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions/file_manipulation.rb
RENAMED
|
@@ -48,7 +48,7 @@ class Thor
|
|
|
48
48
|
#
|
|
49
49
|
def get(source, destination=nil, config={}, &block)
|
|
50
50
|
source = File.expand_path(find_in_source_paths(source.to_s)) unless source =~ /^http\:\/\//
|
|
51
|
-
render =
|
|
51
|
+
render = open(source) {|input| input.binmode.read }
|
|
52
52
|
|
|
53
53
|
destination ||= if block_given?
|
|
54
54
|
block.arity == 1 ? block.call(render) : block.call
|
|
@@ -10,7 +10,8 @@ class Thor
|
|
|
10
10
|
# destination<String>:: Relative path to the destination root
|
|
11
11
|
# data<String>:: Data to add to the file. Can be given as a block.
|
|
12
12
|
# config<Hash>:: give :verbose => false to not log the status and the flag
|
|
13
|
-
# for injection (:after or :before)
|
|
13
|
+
# for injection (:after or :before) or :force => true for
|
|
14
|
+
# insert two or more times the same content.
|
|
14
15
|
#
|
|
15
16
|
# ==== Examples
|
|
16
17
|
#
|
|
@@ -55,7 +56,7 @@ class Thor
|
|
|
55
56
|
replacement + '\0'
|
|
56
57
|
end
|
|
57
58
|
|
|
58
|
-
replace!(/#{flag}/, content)
|
|
59
|
+
replace!(/#{flag}/, content, config[:force])
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
def revoke!
|
|
@@ -69,7 +70,7 @@ class Thor
|
|
|
69
70
|
/(#{Regexp.escape(replacement)})(.*)(#{flag})/m
|
|
70
71
|
end
|
|
71
72
|
|
|
72
|
-
replace!(regexp, content)
|
|
73
|
+
replace!(regexp, content, true)
|
|
73
74
|
end
|
|
74
75
|
|
|
75
76
|
protected
|
|
@@ -88,11 +89,13 @@ class Thor
|
|
|
88
89
|
|
|
89
90
|
# Adds the content to the file.
|
|
90
91
|
#
|
|
91
|
-
def replace!(regexp, string)
|
|
92
|
+
def replace!(regexp, string, force)
|
|
92
93
|
unless base.options[:pretend]
|
|
93
94
|
content = File.binread(destination)
|
|
94
|
-
content.
|
|
95
|
-
|
|
95
|
+
if force || !content.include?(replacement)
|
|
96
|
+
content.gsub!(regexp, string)
|
|
97
|
+
File.open(destination, 'wb') { |file| file.write(content) }
|
|
98
|
+
end
|
|
96
99
|
end
|
|
97
100
|
end
|
|
98
101
|
|
|
@@ -8,6 +8,9 @@ require 'thor/task'
|
|
|
8
8
|
require 'thor/util'
|
|
9
9
|
|
|
10
10
|
class Thor
|
|
11
|
+
autoload :Actions, 'thor/actions'
|
|
12
|
+
autoload :RakeCompat, 'thor/rake_compat'
|
|
13
|
+
|
|
11
14
|
# Shortcuts for help.
|
|
12
15
|
HELP_MAPPINGS = %w(-h -? --help -D)
|
|
13
16
|
|
|
@@ -35,9 +38,8 @@ class Thor
|
|
|
35
38
|
# config<Hash>:: Configuration for this Thor class.
|
|
36
39
|
#
|
|
37
40
|
def initialize(args=[], options={}, config={})
|
|
38
|
-
Thor::Arguments.parse(self.class.arguments, args)
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
+
args = Thor::Arguments.parse(self.class.arguments, args)
|
|
42
|
+
args.each { |key, value| send("#{key}=", value) }
|
|
41
43
|
|
|
42
44
|
parse_options = self.class.class_options
|
|
43
45
|
|
|
@@ -49,9 +51,9 @@ class Thor
|
|
|
49
51
|
array_options, hash_options = [], options
|
|
50
52
|
end
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
self.options =
|
|
54
|
-
self.
|
|
54
|
+
opts = Thor::Options.new(parse_options, hash_options)
|
|
55
|
+
self.options = opts.parse(array_options)
|
|
56
|
+
opts.check_unknown! if self.class.check_unknown_options?
|
|
55
57
|
end
|
|
56
58
|
|
|
57
59
|
class << self
|
|
@@ -94,6 +96,28 @@ class Thor
|
|
|
94
96
|
module ClassMethods
|
|
95
97
|
attr_accessor :debugging
|
|
96
98
|
|
|
99
|
+
def attr_reader(*) #:nodoc:
|
|
100
|
+
no_tasks { super }
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def attr_writer(*) #:nodoc:
|
|
104
|
+
no_tasks { super }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def attr_accessor(*) #:nodoc:
|
|
108
|
+
no_tasks { super }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# If you want to raise an error for unknown options, call check_unknown_options!
|
|
112
|
+
# This is disabled by default to allow dynamic invocations.
|
|
113
|
+
def check_unknown_options!
|
|
114
|
+
@check_unknown_options = true
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def check_unknown_options? #:nodoc:
|
|
118
|
+
@check_unknown_options || false
|
|
119
|
+
end
|
|
120
|
+
|
|
97
121
|
# Adds an argument to the class and creates an attr_accessor for it.
|
|
98
122
|
#
|
|
99
123
|
# Arguments are different from options in several aspects. The first one
|
|
@@ -340,7 +364,7 @@ class Thor
|
|
|
340
364
|
def namespace(name=nil)
|
|
341
365
|
case name
|
|
342
366
|
when nil
|
|
343
|
-
@namespace ||= Thor::Util.namespace_from_thor_class(self
|
|
367
|
+
@namespace ||= Thor::Util.namespace_from_thor_class(self)
|
|
344
368
|
else
|
|
345
369
|
@namespace = name.to_s
|
|
346
370
|
end
|
|
@@ -351,14 +375,18 @@ class Thor
|
|
|
351
375
|
def start(given_args=ARGV, config={})
|
|
352
376
|
self.debugging = given_args.include?("--debug")
|
|
353
377
|
config[:shell] ||= Thor::Base.shell.new
|
|
354
|
-
yield
|
|
378
|
+
yield(given_args.dup)
|
|
355
379
|
rescue Thor::Error => e
|
|
356
|
-
|
|
357
|
-
|
|
380
|
+
debugging ? (raise e) : config[:shell].error(e.message)
|
|
381
|
+
exit(1) if exit_on_failure?
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def handle_no_task_error(task) #:nodoc:
|
|
385
|
+
if self.banner_base == "thor"
|
|
386
|
+
raise UndefinedTaskError, "Could not find task #{task.inspect} in #{namespace.inspect} namespace."
|
|
358
387
|
else
|
|
359
|
-
|
|
388
|
+
raise UndefinedTaskError, "Could not find task #{task.inspect}."
|
|
360
389
|
end
|
|
361
|
-
exit(1) if exit_on_failure?
|
|
362
390
|
end
|
|
363
391
|
|
|
364
392
|
protected
|
|
@@ -404,7 +432,6 @@ class Thor
|
|
|
404
432
|
end
|
|
405
433
|
|
|
406
434
|
# Raises an error if the word given is a Thor reserved word.
|
|
407
|
-
#
|
|
408
435
|
def is_thor_reserved_word?(word, type) #:nodoc:
|
|
409
436
|
return false unless THOR_RESERVED_WORDS.include?(word.to_s)
|
|
410
437
|
raise "#{word.inspect} is a Thor reserved word and cannot be defined as #{type}"
|
|
@@ -415,7 +442,6 @@ class Thor
|
|
|
415
442
|
# ==== Parameters
|
|
416
443
|
# name<Symbol>:: The name of the argument.
|
|
417
444
|
# options<Hash>:: Described in both class_option and method_option.
|
|
418
|
-
#
|
|
419
445
|
def build_option(name, options, scope) #:nodoc:
|
|
420
446
|
scope[name] = Thor::Option.new(name, options[:desc], options[:required],
|
|
421
447
|
options[:type], options[:default], options[:banner],
|
|
@@ -429,7 +455,6 @@ class Thor
|
|
|
429
455
|
#
|
|
430
456
|
# ==== Parameters
|
|
431
457
|
# Hash[Symbol => Object]
|
|
432
|
-
#
|
|
433
458
|
def build_options(options, scope) #:nodoc:
|
|
434
459
|
options.each do |key, value|
|
|
435
460
|
scope[key] = Thor::Option.parse(key, value)
|
|
@@ -439,7 +464,6 @@ class Thor
|
|
|
439
464
|
# Finds a task with the given name. If the task belongs to the current
|
|
440
465
|
# class, just return it, otherwise dup it and add the fresh copy to the
|
|
441
466
|
# current task hash.
|
|
442
|
-
#
|
|
443
467
|
def find_and_refresh_task(name) #:nodoc:
|
|
444
468
|
task = if task = tasks[name.to_s]
|
|
445
469
|
task
|
|
@@ -452,14 +476,12 @@ class Thor
|
|
|
452
476
|
|
|
453
477
|
# Everytime someone inherits from a Thor class, register the klass
|
|
454
478
|
# and file into baseclass.
|
|
455
|
-
#
|
|
456
479
|
def inherited(klass)
|
|
457
480
|
Thor::Base.register_klass_file(klass)
|
|
458
481
|
end
|
|
459
482
|
|
|
460
483
|
# Fire this callback whenever a method is added. Added methods are
|
|
461
484
|
# tracked as tasks by invoking the create_task method.
|
|
462
|
-
#
|
|
463
485
|
def method_added(meth)
|
|
464
486
|
meth = meth.to_s
|
|
465
487
|
|
|
@@ -480,7 +502,6 @@ class Thor
|
|
|
480
502
|
|
|
481
503
|
# Retrieves a value from superclass. If it reaches the baseclass,
|
|
482
504
|
# returns default.
|
|
483
|
-
#
|
|
484
505
|
def from_superclass(method, default=nil)
|
|
485
506
|
if self == baseclass || !superclass.respond_to?(method, true)
|
|
486
507
|
default
|
|
@@ -491,11 +512,15 @@ class Thor
|
|
|
491
512
|
end
|
|
492
513
|
|
|
493
514
|
# A flag that makes the process exit with status 1 if any error happens.
|
|
494
|
-
#
|
|
495
515
|
def exit_on_failure?
|
|
496
516
|
false
|
|
497
517
|
end
|
|
498
518
|
|
|
519
|
+
# Returns the base for banner.
|
|
520
|
+
def banner_base
|
|
521
|
+
@banner_base ||= $thor_runner ? "thor" : File.basename($0.split(" ").first)
|
|
522
|
+
end
|
|
523
|
+
|
|
499
524
|
# SIGNATURE: Sets the baseclass. This is where the superclass lookup
|
|
500
525
|
# finishes.
|
|
501
526
|
def baseclass #:nodoc:
|