wycats-thor 0.11.2 → 0.11.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -166,16 +166,19 @@ class Thor
166
166
  shell.say task.description
167
167
  else
168
168
  list = (options[:short] ? tasks : all_tasks).map do |_, task|
169
- [ banner(task, options[:namespace]), task.short_description || '' ]
169
+ item = [ " " + banner(task, options[:namespace]) ]
170
+ item << if task.short_description
171
+ "\n # #{task.short_description}\n"
172
+ else
173
+ "\n"
174
+ end
170
175
  end
171
176
 
172
177
  if options[:short]
173
- shell.print_table(list, :emphasize_last => true)
178
+ shell.print_table(list)
174
179
  else
175
180
  shell.say "Tasks:"
176
- shell.print_table(list, :ident => 2, :emphasize_last => true)
177
- shell.say
178
-
181
+ shell.print_table(list)
179
182
  class_options_help(shell, "Class")
180
183
  end
181
184
  end
@@ -196,13 +199,19 @@ class Thor
196
199
  Thor
197
200
  end
198
201
 
199
- def valid_task?(meth) #:nodoc:
200
- @usage && @desc
201
- end
202
-
203
202
  def create_task(meth) #:nodoc:
204
- tasks[meth.to_s] = Thor::Task.new(meth, @desc, @usage, method_options)
205
- @usage, @desc, @method_options = nil
203
+ if @usage && @desc
204
+ tasks[meth.to_s] = Thor::Task.new(meth, @desc, @usage, method_options)
205
+ @usage, @desc, @method_options = nil
206
+ true
207
+ elsif self.all_tasks[meth.to_s] || meth.to_sym == :method_missing
208
+ true
209
+ else
210
+ puts "[WARNING] Attempted to create task #{meth.inspect} without usage or description. " <<
211
+ "Call desc if you want this method to be available as task or declare it inside a " <<
212
+ "no_tasks{} block. Invoked from #{caller[1].inspect}."
213
+ false
214
+ end
206
215
  end
207
216
 
208
217
  def initialize_added #:nodoc:
@@ -158,11 +158,34 @@ class Thor
158
158
  inside(@destination_stack.first) { yield }
159
159
  end
160
160
 
161
+ # Loads an external file and execute it in the instance binding.
162
+ #
163
+ # ==== Parameters
164
+ # path<String>:: The path to the file to execute. Can be a web address or
165
+ # a relative path from the source root.
166
+ #
167
+ # ==== Examples
168
+ #
169
+ # apply "http://gist.github.com/103208"
170
+ #
171
+ # apply "recipes/jquery.rb"
172
+ #
173
+ def apply(path, config={})
174
+ verbose = config.fetch(:verbose, true)
175
+ path = find_in_source_paths(path) unless path =~ /^http\:\/\//
176
+
177
+ say_status :apply, path, verbose
178
+ shell.padding += 1 if verbose
179
+ instance_eval(open(path).read)
180
+ shell.padding -= 1 if verbose
181
+ end
182
+
161
183
  # Executes a command.
162
184
  #
163
185
  # ==== Parameters
164
186
  # command<String>:: the command to be executed.
165
- # config<Hash>:: give :verbose => false to not log the status.
187
+ # config<Hash>:: give :verbose => false to not log the status. Specify :with
188
+ # to append an executable to command executation.
166
189
  #
167
190
  # ==== Example
168
191
  #
@@ -172,7 +195,16 @@ class Thor
172
195
  #
173
196
  def run(command, config={})
174
197
  return unless behavior == :invoke
175
- say_status :run, command, config.fetch(:verbose, true)
198
+
199
+ destination = relative_to_original_destination_root(destination_root, false)
200
+ desc = "#{command} from #{destination.inspect}"
201
+
202
+ if config[:with]
203
+ desc = "#{File.basename(config[:with].to_s)} #{desc}"
204
+ command = "#{config[:with]} #{command}"
205
+ end
206
+
207
+ say_status :run, desc, config.fetch(:verbose, true)
176
208
  `#{command}` unless options[:pretend]
177
209
  end
178
210
 
@@ -184,8 +216,7 @@ class Thor
184
216
  #
185
217
  def run_ruby_script(command, config={})
186
218
  return unless behavior == :invoke
187
- say_status File.basename(Thor::Util.ruby_command), command, config.fetch(:verbose, true)
188
- `#{Thor::Util.ruby_command} #{command}` unless options[:pretend]
219
+ run "#{command}", config.merge(:with => Thor::Util.ruby_command)
189
220
  end
190
221
 
191
222
  # Run a thor command. A hash of options can be given and it's converted to
@@ -213,8 +244,7 @@ class Thor
213
244
  args.push Thor::Options.to_switches(config)
214
245
  command = args.join(' ').strip
215
246
 
216
- say_status :thor, command, verbose
217
- run "thor #{command}", :verbose => false
247
+ run command, :with => :thor, :verbose => verbose
218
248
  end
219
249
 
220
250
  protected
@@ -189,6 +189,7 @@ class Thor
189
189
  say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true)
190
190
  ::FileUtils.rm_rf(path) if !options[:pretend] && File.exists?(path)
191
191
  end
192
+ alias :remove_dir :remove_file
192
193
 
193
194
  end
194
195
  end
@@ -9,7 +9,8 @@ require 'thor/util'
9
9
 
10
10
  class Thor
11
11
  HELP_MAPPINGS = %w(-h -? --help -D)
12
- THOR_RESERVED_WORDS = %w(invoke shell options behavior root destination_root relative_root)
12
+ THOR_RESERVED_WORDS = %w(invoke shell options behavior root destination_root relative_root
13
+ action add_file create_file in_root inside run run_ruby_script)
13
14
 
14
15
  module Base
15
16
  attr_accessor :options
@@ -375,8 +376,16 @@ class Thor
375
376
  padding = options.collect{ |o| o.aliases.size }.max.to_i * 4
376
377
 
377
378
  options.each do |option|
378
- list << [ option.usage(padding), option.description || "" ]
379
- list << [ "", "Default: #{option.default}" ] if option.show_default?
379
+ item = [ option.usage(padding) ]
380
+
381
+ item << if option.description
382
+ "# #{option.description}"
383
+ else
384
+ ""
385
+ end
386
+
387
+ list << item
388
+ list << [ "", "# Default: #{option.default}" ] if option.show_default?
380
389
  end
381
390
 
382
391
  unless list.empty?
@@ -386,7 +395,7 @@ class Thor
386
395
  shell.say "Options:"
387
396
  end
388
397
 
389
- shell.print_table(list, :emphasize_last => true, :ident => 2)
398
+ shell.print_table(list, :ident => 2)
390
399
  shell.say ""
391
400
  end
392
401
  end
@@ -405,7 +414,7 @@ class Thor
405
414
  #
406
415
  def is_thor_reserved_word?(word, type)
407
416
  return false unless THOR_RESERVED_WORDS.include?(word.to_s)
408
- raise "'#{word}' is a Thor reserved word and cannot be defined as #{type}"
417
+ raise "#{word.inspect} is a Thor reserved word and cannot be defined as #{type}"
409
418
  end
410
419
 
411
420
  # Build an option and adds it to the given scope.
@@ -470,12 +479,10 @@ class Thor
470
479
  return unless public_instance_methods.include?(meth) ||
471
480
  public_instance_methods.include?(meth.to_sym)
472
481
 
473
- # Return if @no_tasks is enabled or it's not a valid task
474
- return if @no_tasks || !valid_task?(meth)
482
+ return if @no_tasks || !create_task(meth)
475
483
 
476
484
  is_thor_reserved_word?(meth, :task)
477
485
  Thor::Base.register_klass_file(self)
478
- create_task(meth)
479
486
  end
480
487
 
481
488
  # Retrieves a value from superclass. If it reaches the baseclass,
@@ -495,12 +502,6 @@ class Thor
495
502
  def baseclass #:nodoc:
496
503
  end
497
504
 
498
- # SIGNATURE: Defines if a given method is a valid_task?. This method is
499
- # called before a new method is added to the class.
500
- def valid_task?(meth) #:nodoc:
501
- true # unless otherwise given
502
- end
503
-
504
505
  # SIGNATURE: Creates a new task if valid_task? is true. This method is
505
506
  # called when a new method is added to the class.
506
507
  def create_task(meth) #:nodoc:
@@ -233,6 +233,7 @@ class Thor::Group
233
233
 
234
234
  def create_task(meth) #:nodoc:
235
235
  tasks[meth.to_s] = Thor::Task.new(meth, nil, nil, nil)
236
+ true
236
237
  end
237
238
  end
238
239
 
@@ -281,15 +281,11 @@ class Thor::Runner < Thor
281
281
  unless klass.tasks.empty?
282
282
  base = klass.namespace
283
283
 
284
- if base == "default"
285
- say "\033[1;35m#{base}\033[0m"
286
- else
287
- say "\033[1;34m#{base}\033[0m"
288
- end
284
+ color = base == "default" ? :magenta : :blue
285
+ say shell.set_color(base, color, true)
289
286
  say "-" * base.length
290
287
 
291
288
  klass.help(shell, :short => true, :namespace => true)
292
- say
293
289
  end
294
290
  end
295
291
  end
@@ -117,13 +117,6 @@ class Thor
117
117
  formats[0] = formats[0].insert(0, " " * options[:ident]) if options[:ident]
118
118
  formats << "%s"
119
119
 
120
- if options[:emphasize_last]
121
- table.each do |row|
122
- next if row[-1].empty?
123
- row[-1] = "# #{row[-1]}"
124
- end
125
- end
126
-
127
120
  table.each do |row|
128
121
  row.each_with_index do |column, i|
129
122
  $stdout.print formats[i] % column.to_s
@@ -175,11 +168,13 @@ class Thor
175
168
  $stderr.puts statement
176
169
  end
177
170
 
178
- protected
171
+ # Apply color to the given string with optional bold.
172
+ #
173
+ def set_color(string, color, bold=false)
174
+ string
175
+ end
179
176
 
180
- def set_color(string, color, bold=false)
181
- string
182
- end
177
+ protected
183
178
 
184
179
  def is?(value)
185
180
  value = value.to_s
@@ -44,17 +44,17 @@ class Thor
44
44
  # Set the terminal's background ANSI color to white.
45
45
  ON_WHITE = "\e[47m"
46
46
 
47
- protected
47
+ # Set color by using a string or one of the defined constants. Based
48
+ # on Highline implementation. CLEAR is automatically be embedded to
49
+ # the end of the returned String.
50
+ #
51
+ def set_color(string, color, bold=false)
52
+ color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
53
+ bold = bold ? BOLD : ""
54
+ "#{bold}#{color}#{string}#{CLEAR}"
55
+ end
48
56
 
49
- # Set color by using a string or one of the defined constants. Based
50
- # on Highline implementation. CLEAR is automatically be embedded to
51
- # the end of the returned String.
52
- #
53
- def set_color(string, color, bold=false)
54
- color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
55
- bold = bold ? BOLD : ""
56
- "#{bold}#{color}#{string}#{CLEAR}"
57
- end
57
+ protected
58
58
 
59
59
  # Overwrite show_diff to show diff with colors if Diff::LCS is
60
60
  # available.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wycats-thor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-16 00:00:00 -07:00
12
+ date: 2009-07-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15