josevalim-thor 0.10.6 → 0.10.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -72,10 +72,10 @@ class Thor
72
72
  end
73
73
  end
74
74
 
75
- # Shortcut to say_status base method.
75
+ # Shortcut to say_status shell method.
76
76
  #
77
77
  def say_status(status)
78
- base.send :say_status_if_log, status, relative_destination, @log_status
78
+ base.shell.say_status status, relative_destination, @log_status
79
79
  end
80
80
 
81
81
  # Adds the content to the file.
@@ -65,10 +65,8 @@ class Thor
65
65
  # Revokes the action.
66
66
  #
67
67
  def revoke!
68
- if exists?
69
- say_status :deleted, :green
70
- ::FileUtils.rm_rf(destination) unless pretend?
71
- end
68
+ say_status :remove, :green
69
+ ::FileUtils.rm_rf(destination) if !pretend? && exists?
72
70
  end
73
71
 
74
72
  protected
data/lib/thor/actions.rb CHANGED
@@ -151,7 +151,7 @@ class Thor
151
151
  #
152
152
  def chmod(path, mode, log_status=true)
153
153
  path = File.expand_path(path, root)
154
- say_status_if_log :chmod, relative_to_absolute_root(path), log_status
154
+ say_status :chmod, relative_to_absolute_root(path), log_status
155
155
  FileUtils.chmod_R(mode, path) unless options[:pretend]
156
156
  end
157
157
 
@@ -169,7 +169,7 @@ class Thor
169
169
  # end
170
170
  #
171
171
  def run(command, log_status=true)
172
- say_status_if_log :run, "#{command} from #{relative_to_absolute_root(root, false)}", log_status
172
+ say_status :run, "#{command} from #{relative_to_absolute_root(root, false)}", log_status
173
173
  `#{command}` unless options[:pretend]
174
174
  end
175
175
 
@@ -213,6 +213,25 @@ class Thor
213
213
  end
214
214
  end
215
215
 
216
+ # Removes a file at the given location.
217
+ #
218
+ # ==== Parameters
219
+ # path<String>:: path of the file to be changed
220
+ # log_status<Boolean>:: if false, does not log the status. True by default.
221
+ # If a symbol is given, uses it as the output color.
222
+ #
223
+ # ==== Example
224
+ #
225
+ # remove_file 'README'
226
+ # remove_file 'app/controllers/application_controller.rb'
227
+ #
228
+ def remove_file(path, log_status=true)
229
+ path = File.expand_path(path, root)
230
+ say_status :remove, relative_to_absolute_root(path), log_status
231
+
232
+ ::FileUtils.rm_rf(path) if !options[:pretend] && File.exists?(path)
233
+ end
234
+
216
235
  # Run a regular expression replacement on a file.
217
236
  #
218
237
  # ==== Parameters
@@ -234,7 +253,7 @@ class Thor
234
253
  log_status = args.last.is_a?(Symbol) || [ true, false ].include?(args.last) ? args.pop : true
235
254
 
236
255
  path = File.expand_path(path, root)
237
- say_status_if_log :gsub, relative_to_absolute_root(path), log_status
256
+ say_status :gsub, relative_to_absolute_root(path), log_status
238
257
 
239
258
  unless options[:pretend]
240
259
  content = File.read(path)
@@ -257,7 +276,7 @@ class Thor
257
276
  #
258
277
  def append_file(path, data=nil, log_status=true, &block)
259
278
  path = File.expand_path(path, root)
260
- say_status_if_log :append, relative_to_absolute_root(path), log_status
279
+ say_status :append, relative_to_absolute_root(path), log_status
261
280
 
262
281
  File.open(path, 'ab') { |file| file.write(data || block.call) } unless options[:pretend]
263
282
  end
@@ -276,7 +295,7 @@ class Thor
276
295
  #
277
296
  def prepend_file(path, data=nil, log_status=true, &block)
278
297
  path = File.expand_path(path, root)
279
- say_status_if_log :prepend, relative_to_absolute_root(path), log_status
298
+ say_status :prepend, relative_to_absolute_root(path), log_status
280
299
 
281
300
  unless options[:pretend]
282
301
  content = data || block.call
@@ -285,12 +304,5 @@ class Thor
285
304
  end
286
305
  end
287
306
 
288
- protected
289
-
290
- def say_status_if_log(status, message, log_status)
291
- color = log_status.is_a?(Symbol) ? log_status : :green
292
- shell.say_status status, message, color if log_status
293
- end
294
-
295
307
  end
296
308
  end
data/lib/thor/options.rb CHANGED
@@ -248,7 +248,7 @@ class Thor
248
248
  #
249
249
  def check_requirement!(switch, option)
250
250
  if option.input_required?
251
- raise RequiredArgumentMissingError, "no value provided for argument '#{switch}'" if peek.nil?
251
+ raise RequiredArgumentMissingError, "no value provided for required argument '#{switch}'" if peek.nil?
252
252
  raise MalformattedArgumentError, "cannot pass switch '#{peek}' as an argument" if switch?(peek)
253
253
  end
254
254
  end
@@ -257,8 +257,11 @@ class Thor
257
257
  #
258
258
  def check_validity!
259
259
  unless @non_assigned_required.empty?
260
- switch_names = @non_assigned_required.map{ |o| o.switch_name }.join(', ')
261
- raise RequiredArgumentMissingError, "no value provided for required arguments '#{switch_names}'"
260
+ names = @non_assigned_required.map do |o|
261
+ o.argument? ? o.human_name : o.switch_name
262
+ end.join("', '")
263
+
264
+ raise RequiredArgumentMissingError, "no value provided for required arguments '#{names}'"
262
265
  end
263
266
  end
264
267
 
@@ -33,12 +33,16 @@ class Thor
33
33
  end
34
34
  end
35
35
 
36
- # Say a status with the given color and appends the message.
37
- # It does not show the status if the base is set to quiet.
36
+ # Say a status with the given color and appends the message. Since this
37
+ # method is used frequently by actions, it allows nil or false to be given
38
+ # in log_status, avoiding the message from being shown. If a Symbol is
39
+ # given in log_status, it's used as the color.
38
40
  #
39
- def say_status(status, message, color=nil)
41
+ def say_status(status, message, log_status=true)
40
42
  return if base && base.options[:quiet]
41
- say "#{status.to_s.rjust(12)} #{message}", color, true
43
+
44
+ color = log_status.is_a?(Symbol) ? log_status : :green
45
+ say "#{status.to_s.rjust(12)} #{message}", color, true if log_status
42
46
  end
43
47
 
44
48
  # Make a question the to user and returns true if the user replies "y" or
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: josevalim-thor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.6
4
+ version: 0.10.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz