ruby-changes:58759
From: Hiroshi <ko1@a...>
Date: Wed, 13 Nov 2019 10:20:13 +0900 (JST)
Subject: [ruby-changes:58759] bb9ecd026a (master): Merge Bundler 2.1.0.pre3 released version
https://git.ruby-lang.org/ruby.git/commit/?id=bb9ecd026a From bb9ecd026a6cadd5d0f85ac061649216806ed935 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA <hsbt@r...> Date: Wed, 13 Nov 2019 07:57:02 +0900 Subject: Merge Bundler 2.1.0.pre3 released version diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index 81872b9..46a6643 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -1,6 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/gem_helper.rb#L1 # frozen_string_literal: true -require_relative "vendored_thor" unless defined?(Thor) require_relative "../bundler" require "shellwords" diff --git a/lib/bundler/vendor/thor/lib/thor.rb b/lib/bundler/vendor/thor/lib/thor.rb index 395fad2..f2a0338 100644 --- a/lib/bundler/vendor/thor/lib/thor.rb +++ b/lib/bundler/vendor/thor/lib/thor.rb @@ -175,7 +175,7 @@ class Bundler::Thor https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor.rb#L175 handle_no_command_error(meth) unless command shell.say "Usage:" - shell.say " #{banner(command)}" + shell.say " #{banner(command).split("\n").join("\n ")}" shell.say class_options_help(shell, nil => command.options.values) if command.long_description @@ -398,7 +398,10 @@ class Bundler::Thor https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor.rb#L398 # the namespace should be displayed as arguments. # def banner(command, namespace = nil, subcommand = false) - "#{basename} #{command.formatted_usage(self, $thor_runner, subcommand)}" + $thor_runner ||= false + command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |formatted_usage| + "#{basename} #{formatted_usage}" + end.join("\n") end def baseclass #:nodoc: diff --git a/lib/bundler/vendor/thor/lib/thor/actions.rb b/lib/bundler/vendor/thor/lib/thor/actions.rb index 5681d5a..39ce67e 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions.rb @@ -12,6 +12,7 @@ class Bundler::Thor https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/actions.rb#L12 attr_accessor :behavior def self.included(base) #:nodoc: + super(base) base.extend ClassMethods end diff --git a/lib/bundler/vendor/thor/lib/thor/actions/directory.rb b/lib/bundler/vendor/thor/lib/thor/actions/directory.rb index 03c97bf..d37327a 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/directory.rb @@ -56,7 +56,7 @@ class Bundler::Thor https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/actions/directory.rb#L56 attr_reader :source def initialize(base, source, destination = nil, config = {}, &block) - @source = File.expand_path(base.find_in_source_paths(source.to_s)) + @source = File.expand_path(Dir[Util.escape_globs(base.find_in_source_paths(source.to_s))].first) @block = block super(base, destination, {:recursive => true}.merge(config)) end @@ -96,22 +96,12 @@ class Bundler::Thor https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/actions/directory.rb#L96 end end - if RUBY_VERSION < "2.0" - def file_level_lookup(previous_lookup) - File.join(previous_lookup, "{*,.[a-z]*}") - end - - def files(lookup) - Dir[lookup] - end - else - def file_level_lookup(previous_lookup) - File.join(previous_lookup, "*") - end + def file_level_lookup(previous_lookup) + File.join(previous_lookup, "*") + end - def files(lookup) - Dir.glob(lookup, File::FNM_DOTMATCH) - end + def files(lookup) + Dir.glob(lookup, File::FNM_DOTMATCH) end end end diff --git a/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb b/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb index cc29db0..afdbd53 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb @@ -23,14 +23,14 @@ class Bundler::Thor https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb#L23 destination = args.first || source source = File.expand_path(find_in_source_paths(source.to_s)) - create_file destination, nil, config do + resulting_destination = create_file destination, nil, config do content = File.binread(source) content = yield(content) if block content end if config[:mode] == :preserve mode = File.stat(source).mode - chmod(destination, mode, config) + chmod(resulting_destination, mode, config) end end @@ -80,14 +80,14 @@ class Bundler::Thor https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb#L80 config = args.last.is_a?(Hash) ? args.pop : {} destination = args.first - if source =~ %r{^https?\://} + render = if source =~ %r{^https?\://} require "open-uri" + URI.send(:open, source) { |input| input.binmode.read } else source = File.expand_path(find_in_source_paths(source.to_s)) + open(source) { |input| input.binmode.read } end - render = open(source) { |input| input.binmode.read } - destination ||= if block_given? block.arity == 1 ? yield(render) : yield else 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 cf651a4..09ce086 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 https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb#L21 # 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 https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb#L50 end def invoke! - say_status :invoke - content = if @behavior == :after '\0' + replacement else @@ -54,7 +57,11 @@ class Bundler::Thor https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb#L57 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 https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb#L85 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 https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb#L94 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 https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb#L109 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/base.rb b/lib/bundler/vendor/thor/lib/thor/base.rb index 7d7cd3b..6089fd3 100644 --- a/lib/bundler/vendor/thor/lib/thor/base.rb +++ b/lib/bundler/vendor/thor/lib/thor/base.rb @@ -1,6 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/base.rb#L1 require_relative "command" require_relative "core_ext/hash_with_indifferent_access" -require_relative "core_ext/ordered_hash" require_relative "error" require_relative "invocation" require_relative "parser" @@ -89,6 +88,7 @@ class Bundler::Thor https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/base.rb#L88 class << self def included(base) #:nodoc: + super(base) base.extend ClassMethods base.send :include, Invocation base.send :include, Shell @@ -353,22 +353,22 @@ class Bundler::Thor https://github.com/ruby/ruby/blob/trunk/lib/bundler/vendor/thor/lib/thor/base.rb#L353 # Returns the commands for this Bundler::Thor class. # # ==== Returns - # OrderedHash:: An ordered hash with commands names as keys and Bundler::Thor::Command - # objects as values. + # Hash:: An ordered hash with commands names as keys and Bundler::Thor::Command + # objects as (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/