thor 1.3.2 → 1.4.0
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.
- checksums.yaml +4 -4
- data/lib/thor/actions/file_manipulation.rb +42 -6
- data/lib/thor/parser/options.rb +1 -1
- data/lib/thor/runner.rb +1 -1
- data/lib/thor/shell/basic.rb +3 -7
- data/lib/thor/version.rb +1 -1
- metadata +5 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50c78a27ef16cfc96930bc60d8637e86acd69c94b932cc745bb2ed5c3e1605c8
|
4
|
+
data.tar.gz: 00b8a88f938047a55fe3ffadb6bd019666d82813ff584209a338bd8e6d3f16a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86fb64f2b698f06f5c7a0bd14523338802b374ae3d42879d71f94d542598216595176ce744b9ea84196d87657ec4cdaa9f73954ad15124b89109ee87a304eadc
|
7
|
+
data.tar.gz: 81f3b4ce1bca3d43efe2aecf00c88372b6673e3a82706e75ef018cc17badf3b3f2a267fe926b86225b112bbe1bd6e0257115327aa006984c89d8ddc434b88d56
|
@@ -242,6 +242,35 @@ class Thor
|
|
242
242
|
insert_into_file(path, *(args << config), &block)
|
243
243
|
end
|
244
244
|
|
245
|
+
# Run a regular expression replacement on a file, raising an error if the
|
246
|
+
# contents of the file are not changed.
|
247
|
+
#
|
248
|
+
# ==== Parameters
|
249
|
+
# path<String>:: path of the file to be changed
|
250
|
+
# flag<Regexp|String>:: the regexp or string to be replaced
|
251
|
+
# replacement<String>:: the replacement, can be also given as a block
|
252
|
+
# config<Hash>:: give :verbose => false to not log the status, and
|
253
|
+
# :force => true, to force the replacement regardless of runner behavior.
|
254
|
+
#
|
255
|
+
# ==== Example
|
256
|
+
#
|
257
|
+
# gsub_file! 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
|
258
|
+
#
|
259
|
+
# gsub_file! 'README', /rake/, :green do |match|
|
260
|
+
# match << " no more. Use thor!"
|
261
|
+
# end
|
262
|
+
#
|
263
|
+
def gsub_file!(path, flag, *args, &block)
|
264
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
265
|
+
|
266
|
+
return unless behavior == :invoke || config.fetch(:force, false)
|
267
|
+
|
268
|
+
path = File.expand_path(path, destination_root)
|
269
|
+
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
|
270
|
+
|
271
|
+
actually_gsub_file(path, flag, args, true, &block) unless options[:pretend]
|
272
|
+
end
|
273
|
+
|
245
274
|
# Run a regular expression replacement on a file.
|
246
275
|
#
|
247
276
|
# ==== Parameters
|
@@ -267,11 +296,7 @@ class Thor
|
|
267
296
|
path = File.expand_path(path, destination_root)
|
268
297
|
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
|
269
298
|
|
270
|
-
unless options[:pretend]
|
271
|
-
content = File.binread(path)
|
272
|
-
content.gsub!(flag, *args, &block)
|
273
|
-
File.open(path, "wb") { |file| file.write(content) }
|
274
|
-
end
|
299
|
+
actually_gsub_file(path, flag, args, false, &block) unless options[:pretend]
|
275
300
|
end
|
276
301
|
|
277
302
|
# Uncomment all lines matching a given regex. Preserves indentation before
|
@@ -348,7 +373,7 @@ class Thor
|
|
348
373
|
end
|
349
374
|
|
350
375
|
def with_output_buffer(buf = "".dup) #:nodoc:
|
351
|
-
raise ArgumentError, "Buffer
|
376
|
+
raise ArgumentError, "Buffer cannot be a frozen object" if buf.frozen?
|
352
377
|
old_buffer = output_buffer
|
353
378
|
self.output_buffer = buf
|
354
379
|
yield
|
@@ -357,6 +382,17 @@ class Thor
|
|
357
382
|
self.output_buffer = old_buffer
|
358
383
|
end
|
359
384
|
|
385
|
+
def actually_gsub_file(path, flag, args, error_on_no_change, &block)
|
386
|
+
content = File.binread(path)
|
387
|
+
success = content.gsub!(flag, *args, &block)
|
388
|
+
|
389
|
+
if success.nil? && error_on_no_change
|
390
|
+
raise Thor::Error, "The content of #{path} did not change"
|
391
|
+
end
|
392
|
+
|
393
|
+
File.open(path, "wb") { |file| file.write(content) }
|
394
|
+
end
|
395
|
+
|
360
396
|
# Thor::Actions#capture depends on what kind of buffer is used in ERB.
|
361
397
|
# Thus CapturableERB fixes ERB to use String buffer.
|
362
398
|
class CapturableERB < ERB
|
data/lib/thor/parser/options.rb
CHANGED
@@ -144,7 +144,7 @@ class Thor
|
|
144
144
|
def check_exclusive!
|
145
145
|
opts = @assigns.keys
|
146
146
|
# When option A and B are exclusive, if A and B are given at the same time,
|
147
|
-
# the
|
147
|
+
# the difference of argument array size will decrease.
|
148
148
|
found = @exclusives.find{ |ex| (ex - opts).size < ex.size - 1 }
|
149
149
|
if found
|
150
150
|
names = names_to_switch_names(found & opts).map{|n| "'#{n}'"}
|
data/lib/thor/runner.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "../thor"
|
2
2
|
require_relative "group"
|
3
3
|
|
4
|
-
require "yaml"
|
5
4
|
require "digest/sha2"
|
6
5
|
require "pathname"
|
7
6
|
|
@@ -195,6 +194,7 @@ private
|
|
195
194
|
def thor_yaml
|
196
195
|
@thor_yaml ||= begin
|
197
196
|
yaml_file = File.join(thor_root, "thor.yml")
|
197
|
+
require "yaml"
|
198
198
|
yaml = YAML.load_file(yaml_file) if File.exist?(yaml_file)
|
199
199
|
yaml || {}
|
200
200
|
end
|
data/lib/thor/shell/basic.rb
CHANGED
@@ -314,7 +314,7 @@ class Thor
|
|
314
314
|
diff_cmd = ENV["THOR_DIFF"] || ENV["RAILS_DIFF"] || "diff -u"
|
315
315
|
|
316
316
|
require "tempfile"
|
317
|
-
Tempfile.open(File.basename(destination), File.dirname(destination)) do |temp|
|
317
|
+
Tempfile.open(File.basename(destination), File.dirname(destination), binmode: true) do |temp|
|
318
318
|
temp.write content
|
319
319
|
temp.rewind
|
320
320
|
system %(#{diff_cmd} "#{destination}" "#{temp.path}")
|
@@ -372,16 +372,12 @@ class Thor
|
|
372
372
|
Tempfile.open([File.basename(destination), File.extname(destination)], File.dirname(destination)) do |temp|
|
373
373
|
temp.write content
|
374
374
|
temp.rewind
|
375
|
-
system
|
375
|
+
system(merge_tool, temp.path, destination)
|
376
376
|
end
|
377
377
|
end
|
378
378
|
|
379
379
|
def merge_tool #:nodoc:
|
380
|
-
@merge_tool ||= ENV["THOR_MERGE"] ||
|
381
|
-
end
|
382
|
-
|
383
|
-
def git_merge_tool #:nodoc:
|
384
|
-
`git config merge.tool`.rstrip rescue ""
|
380
|
+
@merge_tool ||= ENV["THOR_MERGE"] || "git difftool --no-index"
|
385
381
|
end
|
386
382
|
end
|
387
383
|
end
|
data/lib/thor/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yehuda Katz
|
8
8
|
- José Valim
|
9
|
-
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
@@ -85,12 +84,11 @@ licenses:
|
|
85
84
|
- MIT
|
86
85
|
metadata:
|
87
86
|
bug_tracker_uri: https://github.com/rails/thor/issues
|
88
|
-
changelog_uri: https://github.com/rails/thor/releases/tag/v1.
|
87
|
+
changelog_uri: https://github.com/rails/thor/releases/tag/v1.4.0
|
89
88
|
documentation_uri: http://whatisthor.com/
|
90
|
-
source_code_uri: https://github.com/rails/thor/tree/v1.
|
89
|
+
source_code_uri: https://github.com/rails/thor/tree/v1.4.0
|
91
90
|
wiki_uri: https://github.com/rails/thor/wiki
|
92
91
|
rubygems_mfa_required: 'true'
|
93
|
-
post_install_message:
|
94
92
|
rdoc_options: []
|
95
93
|
require_paths:
|
96
94
|
- lib
|
@@ -105,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
103
|
- !ruby/object:Gem::Version
|
106
104
|
version: 1.3.5
|
107
105
|
requirements: []
|
108
|
-
rubygems_version: 3.
|
109
|
-
signing_key:
|
106
|
+
rubygems_version: 3.6.7
|
110
107
|
specification_version: 4
|
111
108
|
summary: Thor is a toolkit for building powerful command-line interfaces.
|
112
109
|
test_files: []
|