diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-11-06 17:01:11 +0100 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-11-06 17:01:11 +0100 |
commit | b6c2a327ccd08926f859afb1d24831674f8d207e (patch) | |
tree | f8f6c9d0c2208535478074543d13bd44d76a7da1 | |
parent | 0a05b9629cbbe835863e271435055296924e18ca (diff) | |
download | bundler-bump_thor_to_latest_master.tar.gz |
And againbump_thor_to_latest_master
-rw-r--r-- | lib/bundler/vendor/thor/lib/thor.rb | 1 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb | 25 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/lib/thor/shell/color.rb | 6 |
3 files changed, 24 insertions, 8 deletions
diff --git a/lib/bundler/vendor/thor/lib/thor.rb b/lib/bundler/vendor/thor/lib/thor.rb index 97c58b39af..f2a03388cc 100644 --- a/lib/bundler/vendor/thor/lib/thor.rb +++ b/lib/bundler/vendor/thor/lib/thor.rb @@ -398,6 +398,7 @@ class Bundler::Thor # the namespace should be displayed as arguments. # def banner(command, namespace = nil, subcommand = false) + $thor_runner ||= false command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |formatted_usage| "#{basename} #{formatted_usage}" end.join("\n") diff --git a/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb b/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb index cf651a4e78..09ce0864f0 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb @@ -21,9 +21,14 @@ class Bundler::Thor # gems.split(" ").map{ |gem| " config.gem :#{gem}" }.join("\n") # end # + WARNINGS = { unchanged_no_flag: 'File unchanged! The supplied flag value not found!' } + def insert_into_file(destination, *args, &block) data = block_given? ? block : args.shift - config = args.shift + + config = args.shift || {} + config[:after] = /\z/ unless config.key?(:before) || config.key?(:after) + action InjectIntoFile.new(self, destination, data, config) end alias_method :inject_into_file, :insert_into_file @@ -45,8 +50,6 @@ class Bundler::Thor end def invoke! - say_status :invoke - content = if @behavior == :after '\0' + replacement else @@ -54,7 +57,11 @@ class Bundler::Thor end if exists? - replace!(/#{flag}/, content, config[:force]) + if replace!(/#{flag}/, content, config[:force]) + say_status(:invoke) + else + say_status(:unchanged, warning: WARNINGS[:unchanged_no_flag], color: :red) + end else unless pretend? raise Bundler::Thor::Error, "The file #{ destination } does not appear to exist" @@ -78,7 +85,7 @@ class Bundler::Thor protected - def say_status(behavior) + def say_status(behavior, warning: nil, color: nil) status = if behavior == :invoke if flag == /\A/ :prepend @@ -87,11 +94,13 @@ class Bundler::Thor else :insert end + elsif warning + warning else :subtract end - super(status, config[:verbose]) + super(status, (color || config[:verbose])) end # Adds the content to the file. @@ -100,8 +109,10 @@ class Bundler::Thor return if pretend? content = File.read(destination) if force || !content.include?(replacement) - content.gsub!(regexp, string) + success = content.gsub!(regexp, string) + File.open(destination, "wb") { |file| file.write(content) } + success end end end diff --git a/lib/bundler/vendor/thor/lib/thor/shell/color.rb b/lib/bundler/vendor/thor/lib/thor/shell/color.rb index 6c821d4a09..29f280202d 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell/color.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell/color.rb @@ -97,7 +97,11 @@ class Bundler::Thor protected def can_display_colors? - stdout.tty? + stdout.tty? && !are_colors_disabled? + end + + def are_colors_disabled? + !ENV['NO_COLOR'].nil? end # Overwrite show_diff to show diff with colors if Diff::LCS is |