summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-02-13 06:14:16 +0000
committerThe Bundler Bot <bot@bundler.io>2017-02-13 06:14:16 +0000
commit09358d459565c39314eea933020c8f848b3cfce0 (patch)
treed66cf701f4a9ac30e4fe2bc6dfa78097bd197f6e
parentd8f3732f686d27d321fe2e6396706b0265354ab8 (diff)
parent128427c467071d2300dacc4636fbe30bfb109b9a (diff)
downloadbundler-09358d459565c39314eea933020c8f848b3cfce0.tar.gz
Auto merge of #5221 - bundler:seg-update-thor, r=indirect
[Thor] Update to v0.19.4 Closes #4876 @rafaelfranca
-rw-r--r--lib/bundler/cli.rb3
-rw-r--r--lib/bundler/vendor/thor/lib/thor.rb54
-rw-r--r--lib/bundler/vendor/thor/lib/thor/actions.rb43
-rw-r--r--lib/bundler/vendor/thor/lib/thor/actions/create_file.rb2
-rw-r--r--lib/bundler/vendor/thor/lib/thor/actions/create_link.rb2
-rw-r--r--lib/bundler/vendor/thor/lib/thor/actions/directory.rb4
-rw-r--r--lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb16
-rw-r--r--lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb35
-rw-r--r--lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb24
-rw-r--r--lib/bundler/vendor/thor/lib/thor/base.rb60
-rw-r--r--lib/bundler/vendor/thor/lib/thor/command.rb18
-rw-r--r--lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb10
-rw-r--r--lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb12
-rw-r--r--lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb157
-rw-r--r--lib/bundler/vendor/thor/lib/thor/error.rb6
-rw-r--r--lib/bundler/vendor/thor/lib/thor/group.rb24
-rw-r--r--lib/bundler/vendor/thor/lib/thor/invocation.rb9
-rw-r--r--lib/bundler/vendor/thor/lib/thor/parser/argument.rb11
-rw-r--r--lib/bundler/vendor/thor/lib/thor/parser/arguments.rb32
-rw-r--r--lib/bundler/vendor/thor/lib/thor/parser/option.rb59
-rw-r--r--lib/bundler/vendor/thor/lib/thor/parser/options.rb12
-rw-r--r--lib/bundler/vendor/thor/lib/thor/runner.rb50
-rw-r--r--lib/bundler/vendor/thor/lib/thor/shell.rb2
-rw-r--r--lib/bundler/vendor/thor/lib/thor/shell/basic.rb67
-rw-r--r--lib/bundler/vendor/thor/lib/thor/shell/color.rb2
-rw-r--r--lib/bundler/vendor/thor/lib/thor/shell/html.rb8
-rw-r--r--lib/bundler/vendor/thor/lib/thor/util.rb15
-rw-r--r--lib/bundler/vendor/thor/lib/thor/version.rb2
28 files changed, 416 insertions, 323 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index d6e811b41a..208f21c74b 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -85,6 +85,9 @@ module Bundler
end
end
+ # Ensure `bundle help --no-color` is valid
+ all_commands["help"].disable_class_options = false
+
def self.handle_no_command_error(command, has_namespace = $thor_runner)
if Bundler.feature_flag.plugins? && Bundler::Plugin.command?(command)
return Bundler::Plugin.exec_command(command, ARGV[1..-1])
diff --git a/lib/bundler/vendor/thor/lib/thor.rb b/lib/bundler/vendor/thor/lib/thor.rb
index 9ed67a44e2..563e361bd3 100644
--- a/lib/bundler/vendor/thor/lib/thor.rb
+++ b/lib/bundler/vendor/thor/lib/thor.rb
@@ -1,7 +1,7 @@
require "set"
require "bundler/vendor/thor/lib/thor/base"
-class Bundler::Thor # rubocop:disable ClassLength
+class Bundler::Thor
class << self
# Allows for custom "Command" package naming.
#
@@ -9,7 +9,7 @@ class Bundler::Thor # rubocop:disable ClassLength
# name<String>
# options<Hash>
#
- def package_name(name, options = {})
+ def package_name(name, _ = {})
@package_name = name.nil? || name == "" ? nil : name
end
@@ -57,7 +57,9 @@ class Bundler::Thor # rubocop:disable ClassLength
command.usage = usage if usage
command.description = description if description
else
- @usage, @desc, @hide = usage, description, options[:hide] || false
+ @usage = usage
+ @desc = description
+ @hide = options[:hide] || false
end
end
@@ -156,6 +158,10 @@ class Bundler::Thor # rubocop:disable ClassLength
end
alias_method :option, :method_option
+ def disable_class_options
+ @disable_class_options = true
+ end
+
# Prints help information for the given command.
#
# ==== Parameters
@@ -170,7 +176,7 @@ class Bundler::Thor # rubocop:disable ClassLength
shell.say "Usage:"
shell.say " #{banner(command)}"
shell.say
- class_options_help(shell, nil => command.options.map { |_, o| o })
+ class_options_help(shell, nil => command.options.values)
if command.long_description
shell.say "Description:"
shell.print_wrapped(command.long_description, :indent => 2)
@@ -231,8 +237,9 @@ class Bundler::Thor # rubocop:disable ClassLength
define_method(subcommand) do |*args|
args, opts = Bundler::Thor::Arguments.split(args)
- args.unshift("help") if opts.include? "--help" or opts.include? "-h"
- invoke subcommand_class, args, opts, :invoked_via_subcommand => true, :class_options => options
+ invoke_args = [args, opts, {:invoked_via_subcommand => true, :class_options => options}]
+ invoke_args.unshift "help" if opts.delete("--help") || opts.delete("-h")
+ invoke subcommand_class, *invoke_args
end
end
alias_method :subtask, :subcommand
@@ -320,6 +327,7 @@ class Bundler::Thor # rubocop:disable ClassLength
end
protected
+
def stop_on_unknown_option #:nodoc:
@stop_on_unknown_option ||= Set.new
end
@@ -345,12 +353,14 @@ class Bundler::Thor # rubocop:disable ClassLength
opts.clear
end
else
- args, opts = given_args, nil
+ args = given_args
+ opts = nil
command = dynamic_command_class.new(meth)
end
opts = given_opts || opts || []
- config.merge!(:current_command => command, :command_options => command.options)
+ config[:current_command] = command
+ config[:command_options] = command.options
instance = new(args, opts, config)
yield instance if block_given?
@@ -380,17 +390,18 @@ class Bundler::Thor # rubocop:disable ClassLength
@usage ||= nil
@desc ||= nil
@long_desc ||= nil
+ @disable_class_options ||= nil
if @usage && @desc
base_class = @hide ? Bundler::Thor::HiddenCommand : Bundler::Thor::Command
- commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
- @usage, @desc, @long_desc, @method_options, @hide = nil
+ commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options, @disable_class_options)
+ @usage, @desc, @long_desc, @method_options, @hide, @disable_class_options = nil
true
elsif all_commands[meth] || meth == "method_missing"
true
else
- puts "[WARNING] Attempted to create command #{meth.inspect} without usage or description. " <<
- "Call desc if you want this method to be available as command or declare it inside a " <<
+ puts "[WARNING] Attempted to create command #{meth.inspect} without usage or description. " \
+ "Call desc if you want this method to be available as command or declare it inside a " \
"no_commands{} block. Invoked from #{caller[1].inspect}."
false
end
@@ -405,11 +416,7 @@ class Bundler::Thor # rubocop:disable ClassLength
# Retrieve the command name from given args.
def retrieve_command_name(args) #:nodoc:
meth = args.first.to_s unless args.empty?
- if meth && (map[meth] || meth !~ /^\-/)
- args.shift
- else
- nil
- end
+ args.shift if meth && (map[meth] || meth !~ /^\-/)
end
alias_method :retrieve_task_name, :retrieve_command_name
@@ -421,20 +428,20 @@ class Bundler::Thor # rubocop:disable ClassLength
# +normalize_command_name+ also converts names like +animal-prison+
# into +animal_prison+.
def normalize_command_name(meth) #:nodoc:
- return default_command.to_s.gsub("-", "_") unless meth
+ return default_command.to_s.tr("-", "_") unless meth
possibilities = find_command_possibilities(meth)
- if possibilities.size > 1
- fail AmbiguousTaskError, "Ambiguous command #{meth} matches [#{possibilities.join(', ')}]"
- elsif possibilities.size < 1
- meth = meth || default_command
+ raise AmbiguousTaskError, "Ambiguous command #{meth} matches [#{possibilities.join(', ')}]" if possibilities.size > 1
+
+ if possibilities.empty?
+ meth ||= default_command
elsif map[meth]
meth = map[meth]
else
meth = possibilities.first
end
- meth.to_s.gsub("-", "_") # treat foo-bar as foo_bar
+ meth.to_s.tr("-", "_") # treat foo-bar as foo_bar
end
alias_method :normalize_task_name, :normalize_command_name
@@ -470,6 +477,7 @@ class Bundler::Thor # rubocop:disable ClassLength
map HELP_MAPPINGS => :help
desc "help [COMMAND]", "Describe available commands or one specific command"
+ disable_class_options
def help(command = nil, subcommand = false)
if command
if self.class.subcommands.include? command
diff --git a/lib/bundler/vendor/thor/lib/thor/actions.rb b/lib/bundler/vendor/thor/lib/thor/actions.rb
index 5a82dfd45f..9f1c9f23e8 100644
--- a/lib/bundler/vendor/thor/lib/thor/actions.rb
+++ b/lib/bundler/vendor/thor/lib/thor/actions.rb
@@ -73,14 +73,15 @@ class Bundler::Thor
#
def initialize(args = [], options = {}, config = {})
self.behavior = case config[:behavior].to_s
- when "force", "skip"
- _cleanup_options_and_set(options, config[:behavior])
- :invoke
- when "revoke"
- :revoke
- else
- :invoke
- end
+ when "force", "skip"
+ _cleanup_options_and_set(options, config[:behavior])
+ :invoke
+ when "revoke"
+ :revoke
+ else
+ :invoke
+ end
+
super
self.destination_root = config[:destination_root]
end
@@ -129,7 +130,7 @@ class Bundler::Thor
# Receives a file or directory and search for it in the source paths.
#
- def find_in_source_paths(file) # rubocop:disable MethodLength
+ def find_in_source_paths(file)
possible_files = [file, file + TEMPLATE_EXTNAME]
relative_root = relative_to_original_destination_root(destination_root, false)
@@ -146,13 +147,13 @@ class Bundler::Thor
message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "
end
- if source_paths.empty?
- message << "Currently you have no source paths."
- else
- message << "Your current source paths are: \n#{source_paths.join("\n")}"
- end
+ message << if source_paths.empty?
+ "Currently you have no source paths."
+ else
+ "Your current source paths are: \n#{source_paths.join("\n")}"
+ end
- fail Error, message
+ raise Error, message
end
# Do something in the root or on a provided subfolder. If a relative path
@@ -214,10 +215,10 @@ class Bundler::Thor
say_status :apply, path, verbose
shell.padding += 1 if verbose
- if is_uri
- contents = open(path, "Accept" => "application/x-thor-template") { |io| io.read }
+ contents = if is_uri
+ open(path, "Accept" => "application/x-thor-template", &:read)
else
- contents = open(path) { |io| io.read }
+ open(path, &:read)
end
instance_eval(contents, path)
@@ -250,9 +251,7 @@ class Bundler::Thor
say_status :run, desc, config.fetch(:verbose, true)
- unless options[:pretend]
- config[:capture] ? `#{command}` : system("#{command}")
- end
+ !options[:pretend] && config[:capture] ? `#{command}` : system(command.to_s)
end
# Executes a ruby script (taking into account WIN32 platform quirks).
@@ -308,7 +307,7 @@ class Bundler::Thor
def _cleanup_options_and_set(options, key) #:nodoc:
case options
when Array
- %w[--force -f --skip -s].each { |i| options.delete(i) }
+ %w(--force -f --skip -s).each { |i| options.delete(i) }
options << "--#{key}"
when Hash
[:force, :skip, "force", "skip"].each { |i| options.delete(i) }
diff --git a/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb b/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb
index a0f5640333..ade3f85bde 100644
--- a/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb
+++ b/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb
@@ -84,7 +84,7 @@ class Bundler::Thor
def force_or_skip_or_conflict(force, skip, &block)
if force
say_status :force, :yellow
- block.call unless pretend?
+ yield unless pretend?
elsif skip
say_status :skip, :yellow
else
diff --git a/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb b/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
index be437922b6..7577d12533 100644
--- a/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
+++ b/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
@@ -14,7 +14,7 @@ class Bundler::Thor
#
# create_link "config/apache.conf", "/etc/apache.conf"
#
- def create_link(destination, *args, &block)
+ def create_link(destination, *args)
config = args.last.is_a?(Hash) ? args.pop : {}
source = args.first
action CreateLink.new(self, destination, source, config)
diff --git a/lib/bundler/vendor/thor/lib/thor/actions/directory.rb b/lib/bundler/vendor/thor/lib/thor/actions/directory.rb
index 1a2e25da2f..f555f7b7e0 100644
--- a/lib/bundler/vendor/thor/lib/thor/actions/directory.rb
+++ b/lib/bundler/vendor/thor/lib/thor/actions/directory.rb
@@ -72,7 +72,7 @@ class Bundler::Thor
protected
- def execute! # rubocop:disable MethodLength
+ def execute!
lookup = Util.escape_globs(source)
lookup = config[:recursive] ? File.join(lookup, "**") : lookup
lookup = file_level_lookup(lookup)
@@ -85,7 +85,7 @@ class Bundler::Thor
case file_source
when /\.empty_directory$/
- dirname = File.dirname(file_destination).gsub(/\/\.$/, "")
+ dirname = File.dirname(file_destination).gsub(%r{/\.$}, "")
next if dirname == given_destination
base.empty_directory(dirname, config)
when /#{TEMPLATE_EXTNAME}$/
diff --git a/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb b/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb
index cdc3768b4c..309cb31d9d 100644
--- a/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb
+++ b/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb
@@ -32,7 +32,8 @@ class Bundler::Thor
# config<Hash>:: give :verbose => false to not log the status.
#
def initialize(base, destination, config = {})
- @base, @config = base, {:verbose => true}.merge(config)
+ @base = base
+ @config = {:verbose => true}.merge(config)
self.destination = destination
end
@@ -80,11 +81,10 @@ class Bundler::Thor
# given_destination #=> baz
#
def destination=(destination)
- if destination
- @given_destination = convert_encoded_instructions(destination.to_s)
- @destination = ::File.expand_path(@given_destination, base.destination_root)
- @relative_destination = base.relative_to_original_destination_root(@destination)
- end
+ return unless destination
+ @given_destination = convert_encoded_instructions(destination.to_s)
+ @destination = ::File.expand_path(@given_destination, base.destination_root)
+ @relative_destination = base.relative_to_original_destination_root(@destination)
end
# Filenames in the encoded form are converted. If you have a file:
@@ -113,7 +113,7 @@ class Bundler::Thor
on_conflict_behavior(&block)
else
say_status :create, :green
- block.call unless pretend?
+ yield unless pretend?
end
destination
@@ -121,7 +121,7 @@ class Bundler::Thor
# What to do when the destination file already exists.
#
- def on_conflict_behavior(&block)
+ def on_conflict_behavior
say_status :exist, :blue
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 2bdc78f578..54272fc0c6 100644
--- a/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb
+++ b/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb
@@ -26,7 +26,7 @@ class Bundler::Thor
create_file destination, nil, config do
content = File.binread(source)
- content = block.call(content) if block
+ content = yield(content) if block
content
end
if config[:mode] == :preserve
@@ -49,7 +49,7 @@ class Bundler::Thor
#
# link_file "doc/README"
#
- def link_file(source, *args, &block)
+ def link_file(source, *args)
config = args.last.is_a?(Hash) ? args.pop : {}
destination = args.first || source
source = File.expand_path(find_in_source_paths(source.to_s))
@@ -82,7 +82,7 @@ class Bundler::Thor
render = open(source) { |input| input.binmode.read }
destination ||= if block_given?
- block.arity == 1 ? block.call(render) : block.call
+ block.arity == 1 ? yield(render) : yield
else
File.basename(source)
end
@@ -110,11 +110,11 @@ class Bundler::Thor
destination = args.first || source.sub(/#{TEMPLATE_EXTNAME}$/, "")
source = File.expand_path(find_in_source_paths(source.to_s))
- context = instance_eval("binding")
+ context = config.delete(:context) || instance_eval("binding")
create_file destination, nil, config do
- content = ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
- content = block.call(content) if block
+ content = CapturableERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
+ content = yield(content) if block
content
end
end
@@ -154,7 +154,7 @@ class Bundler::Thor
#
def prepend_to_file(path, *args, &block)
config = args.last.is_a?(Hash) ? args.pop : {}
- config.merge!(:after => /\A/)
+ config[:after] = /\A/
insert_into_file(path, *(args << config), &block)
end
alias_method :prepend_file, :prepend_to_file
@@ -176,7 +176,7 @@ class Bundler::Thor
#
def append_to_file(path, *args, &block)
config = args.last.is_a?(Hash) ? args.pop : {}
- config.merge!(:before => /\z/)
+ config[:before] = /\z/
insert_into_file(path, *(args << config), &block)
end
alias_method :append_file, :append_to_file
@@ -200,7 +200,7 @@ class Bundler::Thor
#
def inject_into_class(path, klass, *args, &block)
config = args.last.is_a?(Hash) ? args.pop : {}
- config.merge!(:after => /class #{klass}\n|class #{klass} .*\n/)
+ config[:after] = /class #{klass}\n|class #{klass} .*\n/
insert_into_file(path, *(args << config), &block)
end
@@ -285,7 +285,7 @@ class Bundler::Thor
#
def remove_file(path, config = {})
return unless behavior == :invoke
- path = File.expand_path(path, destination_root)
+ path = File.expand_path(path, destination_root)
say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true)
::FileUtils.rm_rf(path) if !options[:pretend] && File.exist?(path)
@@ -301,8 +301,8 @@ class Bundler::Thor
@output_buffer.concat(string)
end
- def capture(*args, &block)
- with_output_buffer { block.call(*args) }
+ def capture(*args)
+ with_output_buffer { yield(*args) }
end
def with_output_buffer(buf = "") #:nodoc:
@@ -312,5 +312,16 @@ class Bundler::Thor
ensure
self.output_buffer = old_buffer
end
+
+ # Bundler::Thor::Actions#capture depends on what kind of buffer is used in ERB.
+ # Thus CapturableERB fixes ERB to use String buffer.
+ class CapturableERB < ERB
+ def set_eoutvar(compiler, eoutvar = "_erbout")
+ compiler.put_cmd = "#{eoutvar}.concat"
+ compiler.insert_cmd = "#{eoutvar}.concat"
+ compiler.pre_cmd = ["#{eoutvar} = ''"]
+ compiler.post_cmd = [eoutvar]
+ end
+ end
end
end
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 91ab245ae1..781ee63140 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
@@ -22,11 +22,8 @@ class Bundler::Thor
# end
#
def insert_into_file(destination, *args, &block)
- if block_given?
- data, config = block, args.shift
- else
- data, config = args.shift, args.shift
- end
+ data = block_given? ? block : args.shift
+ config = args.shift
action InjectIntoFile.new(self, destination, data, config)
end
alias_method :inject_into_file, :insert_into_file
@@ -39,9 +36,9 @@ class Bundler::Thor
@behavior, @flag = if @config.key?(:after)
[:after, @config.delete(:after)]
- else
- [:before, @config.delete(:before)]
- end
+ else
+ [:before, @config.delete(:before)]
+ end
@replacement = data.is_a?(Proc) ? data.call : data
@flag = Regexp.escape(@flag) unless @flag.is_a?(Regexp)
@@ -94,12 +91,11 @@ class Bundler::Thor
# Adds the content to the file.
#
def replace!(regexp, string, force)
- unless base.options[:pretend]
- content = File.binread(destination)
- if force || !content.include?(replacement)
- content.gsub!(regexp, string)
- File.open(destination, "wb") { |file| file.write(content) }
- end
+ return if base.options[:pretend]
+ content = File.binread(destination)
+ if force || !content.include?(replacement)
+ content.gsub!(regexp, string)
+ File.open(destination, "wb") { |file| file.write(content) }
end
end
end
diff --git a/lib/bundler/vendor/thor/lib/thor/base.rb b/lib/bundler/vendor/thor/lib/thor/base.rb
index c3667521a5..a95974a62d 100644
--- a/lib/bundler/vendor/thor/lib/thor/base.rb
+++ b/lib/bundler/vendor/thor/lib/thor/base.rb
@@ -14,11 +14,11 @@ class Bundler::Thor
autoload :Group, "bundler/vendor/thor/lib/thor/group"
# Shortcuts for help.
- HELP_MAPPINGS = %w[-h -? --help -D]
+ HELP_MAPPINGS = %w(-h -? --help -D)
# Bundler::Thor methods that should not be overwritten by the user.
- THOR_RESERVED_WORDS = %w[invoke shell options behavior root destination_root relative_root
- action add_file create_file in_root inside run run_ruby_script]
+ THOR_RESERVED_WORDS = %w(invoke shell options behavior root destination_root relative_root
+ action add_file create_file in_root inside run run_ruby_script)
TEMPLATE_EXTNAME = ".tt"
@@ -41,8 +41,8 @@ class Bundler::Thor
#
# config<Hash>:: Configuration for this Bundler::Thor class.
#
- def initialize(args = [], local_options = {}, config = {}) # rubocop:disable MethodLength
- parse_options = self.class.class_options
+ def initialize(args = [], local_options = {}, config = {})
+ parse_options = config[:current_command] && config[:current_command].disable_class_options ? {} : self.class.class_options
# The start method splits inbound arguments at the first argument
# that looks like an option (starts with - or --). It then calls
@@ -52,11 +52,13 @@ class Bundler::Thor
command_options = config.delete(:command_options) # hook for start
parse_options = parse_options.merge(command_options) if command_options
if local_options.is_a?(Array)
- array_options, hash_options = local_options, {}
+ array_options = local_options
+ hash_options = {}
else
# Handle the case where the class was explicitly instantiated
# with pre-parsed options.
- array_options, hash_options = [], local_options
+ array_options = []
+ hash_options = local_options
end
# Let Bundler::Thor::Options parse the options first, so it can remove
@@ -205,7 +207,7 @@ class Bundler::Thor
# ==== Errors
# ArgumentError:: Raised if you supply a required argument after a non required one.
#
- def argument(name, options = {}) # rubocop:disable MethodLength
+ def argument(name, options = {})
is_thor_reserved_word?(name, :argument)
no_commands { attr_accessor name }
@@ -219,11 +221,13 @@ class Bundler::Thor
remove_argument name
- arguments.each do |argument|
- next if argument.required?
- fail ArgumentError, "You cannot have #{name.to_s.inspect} as required argument after " <<
- "the non-required argument #{argument.human_name.inspect}."
- end if required
+ if required
+ arguments.each do |argument|
+ next if argument.required?
+ raise ArgumentError, "You cannot have #{name.to_s.inspect} as required argument after " \
+ "the non-required argument #{argument.human_name.inspect}."
+ end
+ end
options[:required] = required
@@ -343,7 +347,7 @@ class Bundler::Thor
#
def all_commands
@all_commands ||= from_superclass(:all_commands, Bundler::Thor::CoreExt::OrderedHash.new)
- @all_commands.merge(commands)
+ @all_commands.merge!(commands)
end
alias_method :all_tasks, :all_commands
@@ -467,11 +471,8 @@ class Bundler::Thor
alias_method :public_task, :public_command
def handle_no_command_error(command, has_namespace = $thor_runner) #:nodoc:
- if has_namespace
- fail UndefinedCommandError, "Could not find command #{command.inspect} in #{namespace.inspect} namespace."
- else
- fail UndefinedCommandError, "Could not find command #{command.inspect}."
- end
+ raise UndefinedCommandError, "Could not find command #{command.inspect} in #{namespace.inspect} namespace." if has_namespace
+ raise UndefinedCommandError, "Could not find command #{command.inspect}."
end
alias_method :handle_no_task_error, :handle_no_command_error
@@ -480,7 +481,7 @@ class Bundler::Thor
msg << "no arguments" if args.empty?
msg << "arguments " << args.inspect unless args.empty?
msg << "\nUsage: #{banner(command).inspect}"
- fail InvocationError, msg
+ raise InvocationError, msg
end
protected
@@ -513,14 +514,13 @@ class Bundler::Thor
padding = options.map { |o| o.aliases.size }.max.to_i * 4
options.each do |option|
- unless option.hide
- item = [option.usage(padding)]
- item.push(option.description ? "# #{option.description}" : "")
+ next if option.hide
+ item = [option.usage(padding)]
+ item.push(option.description ? "# #{option.description}" : "")
- list << item
- list << ["", "# Default: #{option.default}"] if option.show_default?
- list << ["", "# Possible values: #{option.enum.join(', ')}"] if option.enum
- end
+ list << item
+ list << ["", "# Default: #{option.default}"] if option.show_default?
+ list << ["", "# Possible values: #{option.enum.join(', ')}"] if option.enum
end
shell.say(group_name ? "#{group_name} options:" : "Options:")
@@ -531,7 +531,7 @@ class Bundler::Thor
# Raises an error if the word given is a Bundler::Thor reserved word.
def is_thor_reserved_word?(word, type) #:nodoc:
return false unless THOR_RESERVED_WORDS.include?(word.to_s)
- fail "#{word.inspect} is a Bundler::Thor reserved word and cannot be defined as #{type}"
+ raise "#{word.inspect} is a Bundler::Thor reserved word and cannot be defined as #{type}"
end
# Build an option and adds it to the given scope.
@@ -566,7 +566,7 @@ class Bundler::Thor
elsif command = all_commands[name.to_s] # rubocop:disable AssignmentInCondition
commands[name.to_s] = command.clone
else
- fail ArgumentError, "You supplied :for => #{name.inspect}, but the command #{name.inspect} could not be found."
+ raise ArgumentError, "You supplied :for => #{name.inspect}, but the command #{name.inspect} could not be found."
end
end
alias_method :find_and_refresh_task, :find_and_refresh_command
@@ -649,7 +649,7 @@ class Bundler::Thor
# SIGNATURE: The hook invoked by start.
def dispatch(command, given_args, given_opts, config) #:nodoc:
- fail NotImplementedError
+ raise NotImplementedError
end
end
end
diff --git a/lib/bundler/vendor/thor/lib/thor/command.rb b/lib/bundler/vendor/thor/lib/thor/command.rb
index 72c8348cb6..aacf2ef719 100644
--- a/lib/bundler/vendor/thor/lib/thor/command.rb
+++ b/lib/bundler/vendor/thor/lib/thor/command.rb
@@ -1,9 +1,9 @@
class Bundler::Thor
- class Command < Struct.new(:name, :description, :long_description, :usage, :options)
+ class Command < Struct.new(:name, :description, :long_description, :usage, :options, :disable_class_options)
FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/
- def initialize(name, description, long_description, usage, options = nil)
- super(name.to_s, description, long_description, usage, options || {})
+ def initialize(name, description, long_description, usage, options = nil, disable_class_options = false)
+ super(name.to_s, description, long_description, usage, options || {}, disable_class_options)
end
def initialize_copy(other) #:nodoc:
@@ -33,7 +33,7 @@ class Bundler::Thor
rescue ArgumentError => e
handle_argument_error?(instance, e, caller) ? instance.class.handle_argument_error(self, e, args, arity) : (raise e)
rescue NoMethodError => e
- handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_command_error(name) : (fail e)
+ handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_command_error(name) : (raise e)
end
# Returns the formatted usage by injecting given required arguments
@@ -50,7 +50,7 @@ class Bundler::Thor
# Add usage with required arguments
formatted << if klass && !klass.arguments.empty?
usage.to_s.gsub(/^#{name}/) do |match|
- match << " " << klass.arguments.map { |a| a.usage }.compact.join(" ")
+ match << " " << klass.arguments.map(&:usage).compact.join(" ")
end
else
usage.to_s
@@ -88,7 +88,7 @@ class Bundler::Thor
end
def sans_backtrace(backtrace, caller) #:nodoc:
- saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) || (frame =~ /^kernel\// && RUBY_ENGINE =~ /rbx/) }
+ saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) || (frame =~ %r{^kernel/} && RUBY_ENGINE =~ /rbx/) }
saned - caller
end
@@ -105,7 +105,7 @@ class Bundler::Thor
error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/
end
end
- Task = Command # rubocop:disable ConstantName
+ Task = Command
# A command that is hidden in help messages but still invocable.
class HiddenCommand < Command
@@ -113,7 +113,7 @@ class Bundler::Thor
true
end
end
- HiddenTask = HiddenCommand # rubocop:disable ConstantName
+ HiddenTask = HiddenCommand
# A dynamic command that handles method missing scenarios.
class DynamicCommand < Command
@@ -129,5 +129,5 @@ class Bundler::Thor
end
end
end
- DynamicTask = DynamicCommand # rubocop:disable ConstantName
+ DynamicTask = DynamicCommand
end
diff --git a/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb b/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb
index 6cf61db812..de8c4713b4 100644
--- a/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb
+++ b/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb
@@ -28,6 +28,14 @@ class Bundler::Thor
super(convert_key(key))
end
+ def fetch(key, *args)
+ super(convert_key(key), *args)
+ end
+
+ def key?(key)
+ super(convert_key(key))
+ end
+
def values_at(*indices)
indices.map { |key| self[convert_key(key)] }
end
@@ -60,7 +68,7 @@ class Bundler::Thor
# options.shebang # => "/usr/lib/local/ruby"
# options.test_framework?(:rspec) # => options[:test_framework] == :rspec
#
- def method_missing(method, *args, &block)
+ def method_missing(method, *args)
method = method.to_s
if method =~ /^(\w+)\?$/
if args.empty?
diff --git a/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb b/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb
index 19f3c3d43e..0f6e2e0af2 100644
--- a/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb
+++ b/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb
@@ -1,10 +1,12 @@
class IO #:nodoc:
class << self
- def binread(file, *args)
- fail ArgumentError, "wrong number of arguments (#{1 + args.size} for 1..3)" unless args.size < 3
- File.open(file, "rb") do |f|
- f.read(*args)
+ unless method_defined? :binread
+ def binread(file, *args)
+ raise ArgumentError, "wrong number of arguments (#{1 + args.size} for 1..3)" unless args.size < 3
+ File.open(file, "rb") do |f|
+ f.read(*args)
+ end
end
- end unless method_defined? :binread
+ end
end
end
diff --git a/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb b/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb
index 7e80672a07..76f1e43c65 100644
--- a/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb
+++ b/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb
@@ -1,96 +1,127 @@
class Bundler::Thor
- module CoreExt #:nodoc:
- if RUBY_VERSION >= "1.9"
- class OrderedHash < ::Hash
- end
- else
- # This class is based on the Ruby 1.9 ordered hashes.
- #
- # It keeps the semantics and most of the efficiency of normal hashes
- # while also keeping track of the order in which elements were set.
- #
- class OrderedHash #:nodoc:
- include Enumerable
-
- Node = Struct.new(:key, :value, :next, :prev)
-
- def initialize
- @hash = {}
+ module CoreExt
+ class OrderedHash < ::Hash
+ if RUBY_VERSION < "1.9"
+ def initialize(*args, &block)
+ super
+ @keys = []
end
- def [](key)
- @hash[key] && @hash[key].value
+ def initialize_copy(other)
+ super
+ # make a deep copy of keys
+ @keys = other.keys
end
def []=(key, value)
- if node = @hash[key] # rubocop:disable AssignmentInCondition
- node.value = value
- else
- node = Node.new(key, value)
-
- if !defined?(@first) || @first.nil?
- @first = @last = node
- else
- node.prev = @last
- @last.next = node
- @last = node
- end
- end
-
- @hash[key] = node
- value
+ @keys << key unless key?(key)
+ super
end
def delete(key)
- if node = @hash[key] # rubocop:disable AssignmentInCondition
- prev_node = node.prev
- next_node = node.next
+ if key? key
+ index = @keys.index(key)
+ @keys.delete_at index
+ end
+ super
+ end
- next_node.prev = prev_node if next_node
- prev_node.next = next_node if prev_node
+ def delete_if
+ super
+ sync_keys!
+ self
+ end
- @first = next_node if @first == node
- @last = prev_node if @last == node
+ alias_method :reject!, :delete_if
- value = node.value
- end
-
- @hash.delete(key)
- value
+ def reject(&block)
+ dup.reject!(&block)
end
def keys
- map { |k, v| k }
+ @keys.dup
end
def values
- map { |k, v| v }
+ @keys.map { |key| self[key] }
+ end
+
+ def to_hash
+ self
+ end
+
+ def to_a
+ @keys.map { |key| [key, self[key]] }
+ end
+
+ def each_key
+ return to_enum(:each_key) unless block_given?
+ @keys.each { |key| yield(key) }
+ self
+ end
+
+ def each_value
+ return to_enum(:each_value) unless block_given?
+ @keys.each { |key| yield(self[key]) }
+ self
end
def each
- return unless defined?(@first) && @first
- yield [@first.key, @first.value]
- node = @first
- yield [node.key, node.value] while node = node.next # rubocop:disable AssignmentInCondition
+ return to_enum(:each) unless block_given?
+ @keys.each { |key| yield([key, self[key]]) }
self
end
- def merge(other)
- hash = self.class.new
+ def each_pair
+ return to_enum(:each_pair) unless block_given?
+ @keys.each { |key| yield(key, self[key]) }
+ self
+ end
- each do |key, value|
- hash[key] = value
- end
+ alias_method :select, :find_all
+
+ def clear
+ super
+ @keys.clear
+ self
+ end
+
+ def shift
+ k = @keys.first
+ v = delete(k)
+ [k, v]
+ end
- other.each do |key, value|
- hash[key] = value
+ def merge!(other_hash)
+ if block_given?
+ other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
+ else
+ other_hash.each { |k, v| self[k] = v }
end
+ self
+ end
+
+ alias_method :update, :merge!
+
+ def merge(other_hash, &block)
+ dup.merge!(other_hash, &block)
+ end
- hash
+ # When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
+ def replace(other)
+ super
+ @keys = other.keys
+ self
end
- def empty?
- @hash.empty?
+ def inspect
+ "#<#{self.class} #{super}>"
+ end
+
+ private
+
+ def sync_keys!
+ @keys.delete_if { |k| !key?(k) }
end
end
end
diff --git a/lib/bundler/vendor/thor/lib/thor/error.rb b/lib/bundler/vendor/thor/lib/thor/error.rb
index fc34c11268..2f816081f3 100644
--- a/lib/bundler/vendor/thor/lib/thor/error.rb
+++ b/lib/bundler/vendor/thor/lib/thor/error.rb
@@ -3,7 +3,7 @@ class Bundler::Thor
# errors have their backtrace suppressed and are nicely shown to the user.
#
# Errors that are caused by the developer, like declaring a method which
- # overwrites a thor keyword, it SHOULD NOT raise a Bundler::Thor::Error. This way, we
+ # overwrites a thor keyword, SHOULD NOT raise a Bundler::Thor::Error. This way, we
# ensure that developer errors are shown with full backtrace.
class Error < StandardError
end
@@ -11,11 +11,11 @@ class Bundler::Thor
# Raised when a command was not found.
class UndefinedCommandError < Error
end
- UndefinedTaskError = UndefinedCommandError # rubocop:disable ConstantName
+ UndefinedTaskError = UndefinedCommandError
class AmbiguousCommandError < Error
end
- AmbiguousTaskError = AmbiguousCommandError # rubocop:disable ConstantName
+ AmbiguousTaskError = AmbiguousCommandError
# Raised when a command was found, but not invoked properly.
class InvocationError < Error
diff --git a/lib/bundler/vendor/thor/lib/thor/group.rb b/lib/bundler/vendor/thor/lib/thor/group.rb
index 13d168ad62..c95b708caa 100644
--- a/lib/bundler/vendor/thor/lib/thor/group.rb
+++ b/lib/bundler/vendor/thor/lib/thor/group.rb
@@ -4,7 +4,7 @@ require "bundler/vendor/thor/lib/thor/base"
# is that it invokes all commands at once. It also include some methods that allows
# invocations to be done at the class method, which are not available to Bundler::Thor
# commands.
-class Bundler::Thor::Group # rubocop:disable ClassLength
+class Bundler::Thor::Group
class << self
# The description for this Bundler::Thor::Group. If none is provided, but a source root
# exists, tries to find the USAGE one folder above it, otherwise searches
@@ -53,7 +53,7 @@ class Bundler::Thor::Group # rubocop:disable ClassLength
# The namespace/class given will have its options showed on the help
# usage. Check invoke_from_option for more information.
#
- def invoke(*names, &block) # rubocop:disable MethodLength
+ def invoke(*names, &block)
options = names.last.is_a?(Hash) ? names.pop : {}
verbose = options.fetch(:verbose, true)
@@ -62,7 +62,7 @@ class Bundler::Thor::Group # rubocop:disable ClassLength
invocation_blocks[name] = block if block_given?
class_eval <<-METHOD, __FILE__, __LINE__
- def _invoke_#{name.to_s.gsub(/\W/, "_")}
+ def _invoke_#{name.to_s.gsub(/\W/, '_')}
klass, command = self.class.prepare_for_invocation(nil, #{name.inspect})
if klass
@@ -107,21 +107,21 @@ class Bundler::Thor::Group # rubocop:disable ClassLength
# invoked. The block receives two parameters, an instance of the current
# class and the klass to be invoked.
#
- def invoke_from_option(*names, &block) # rubocop:disable MethodLength
+ def invoke_from_option(*names, &block)
options = names.last.is_a?(Hash) ? names.pop : {}
verbose = options.fetch(:verbose, :white)
names.each do |name|
unless class_options.key?(name)
- fail ArgumentError, "You have to define the option #{name.inspect} " <<
- "before setting invoke_from_option."
+ raise ArgumentError, "You have to define the option #{name.inspect} " \
+ "before setting invoke_from_option."
end
invocations[name] = true
invocation_blocks[name] = block if block_given?
class_eval <<-METHOD, __FILE__, __LINE__
- def _invoke_from_option_#{name.to_s.gsub(/\W/, "_")}
+ def _invoke_from_option_#{name.to_s.gsub(/\W/, '_')}
return unless options[#{name.inspect}]
value = options[#{name.inspect}]
@@ -188,7 +188,7 @@ class Bundler::Thor::Group # rubocop:disable ClassLength
group_options[human_name] ||= []
group_options[human_name] += klass.class_options.values.select do |class_option|
base_options[class_option.name.to_sym].nil? && class_option.group.nil? &&
- !group_options.values.flatten.any? { |i| i.name == class_option.name }
+ !group_options.values.flatten.any? { |i| i.name == class_option.name }
end
yield klass if block_given?
@@ -204,11 +204,11 @@ class Bundler::Thor::Group # rubocop:disable ClassLength
end
alias_method :printable_tasks, :printable_commands
- def handle_argument_error(command, error, args, arity) #:nodoc:
+ def handle_argument_error(command, error, _args, arity) #:nodoc:
msg = "#{basename} #{command.name} takes #{arity} argument"
msg << "s" if arity > 1
msg << ", but it should not."
- fail error, msg
+ raise error, msg
end
protected
@@ -267,9 +267,9 @@ protected
if block
case block.arity
when 3
- block.call(self, klass, command)
+ yield(self, klass, command)
when 2
- block.call(self, klass)
+ yield(self, klass)
when 1
instance_exec(klass, &block)
end
diff --git a/lib/bundler/vendor/thor/lib/thor/invocation.rb b/lib/bundler/vendor/thor/lib/thor/invocation.rb
index 684df2c616..866d2212a7 100644
--- a/lib/bundler/vendor/thor/lib/thor/invocation.rb
+++ b/lib/bundler/vendor/thor/lib/thor/invocation.rb
@@ -108,8 +108,8 @@ class Bundler::Thor
command, args, opts, config = args
klass, command = _retrieve_class_and_command(name, command)
- fail "Missing Bundler::Thor class for invoke #{name}" unless klass
- fail "Expected Bundler::Thor class, got #{klass}" unless klass <= Bundler::Thor::Base
+ raise "Missing Bundler::Thor class for invoke #{name}" unless klass
+ raise "Expected Bundler::Thor class, got #{klass}" unless klass <= Bundler::Thor::Base
args, opts, config = _parse_initialization_options(args, opts, config)
klass.send(:dispatch, command, args, opts, config) do |instance|
@@ -150,10 +150,9 @@ class Bundler::Thor
# use the given name and return self as class. Otherwise, call
# prepare_for_invocation in the current class.
def _retrieve_class_and_command(name, sent_command = nil) #:nodoc:
- case
- when name.nil?
+ if name.nil?
[self.class, nil]
- when self.class.all_commands[name.to_s]
+ elsif self.class.all_commands[name.to_s]
[self.class, name.to_s]
else
klass, command = self.class.prepare_for_invocation(nil, name)
diff --git a/lib/bundler/vendor/thor/lib/thor/parser/argument.rb b/lib/bundler/vendor/thor/lib/thor/parser/argument.rb
index 84957903cd..dfe7398583 100644
--- a/lib/bundler/vendor/thor/lib/thor/parser/argument.rb
+++ b/lib/bundler/vendor/thor/lib/thor/parser/argument.rb
@@ -10,8 +10,8 @@ class Bundler::Thor
type = options[:type]
- fail ArgumentError, "#{class_name} name can't be nil." if name.nil?
- fail ArgumentError, "Type :#{type} is not valid for #{class_name.downcase}s." if type && !valid_type?(type)
+ raise ArgumentError, "#{class_name} name can't be nil." if name.nil?
+ raise ArgumentError, "Type :#{type} is not valid for #{class_name.downcase}s." if type && !valid_type?(type)
@name = name.to_s
@description = options[:desc]
@@ -44,11 +44,8 @@ class Bundler::Thor
protected
def validate!
- if required? && !default.nil?
- fail ArgumentError, "An argument cannot be required and have default value."
- elsif @enum && !@enum.is_a?(Array)
- fail ArgumentError, "An argument cannot have an enum other than an array."
- end
+ raise ArgumentError, "An argument cannot be required and have default value." if required? && !default.nil?
+ raise ArgumentError, "An argument cannot have an enum other than an array." if @enum && !@enum.is_a?(Array)
end
def valid_type?(type)
diff --git a/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb b/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb
index c7bb648e31..1fd790f4b7 100644
--- a/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb
+++ b/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb
@@ -1,6 +1,6 @@
class Bundler::Thor
class Arguments #:nodoc: # rubocop:disable ClassLength
- NUMERIC = /(\d*\.\d+|\d+)/
+ NUMERIC = /[-+]?(\d*\.\d+|\d+)/
# Receives an array of args and returns two arrays, one with arguments
# and one with switches.
@@ -24,7 +24,8 @@ class Bundler::Thor
# Takes an array of Bundler::Thor::Argument objects.
#
def initialize(arguments = [])
- @assigns, @non_assigned_required = {}, []
+ @assigns = {}
+ @non_assigned_required = []
@switches = arguments
arguments.each do |argument|
@@ -49,7 +50,7 @@ class Bundler::Thor
@assigns
end
- def remaining # rubocop:disable TrivialAccessors
+ def remaining
@pile
end
@@ -73,7 +74,7 @@ class Bundler::Thor
end
def unshift(arg)
- if arg.kind_of?(Array)
+ if arg.is_a?(Array)
@pile = arg + @pile
else
@pile.unshift(arg)
@@ -99,6 +100,7 @@ class Bundler::Thor
while current_is_value? && peek.include?(":")
key, value = shift.split(":", 2)
+ raise MalformattedArgumentError, "You can't specify '#{key}' more than once in option '#{name}'; got #{key}:#{hash[key]} and #{key}:#{value}" if hash.include? key
hash[key] = value
end
hash
@@ -128,13 +130,13 @@ class Bundler::Thor
return shift if peek.is_a?(Numeric)
unless peek =~ NUMERIC && $& == peek
- fail MalformattedArgumentError, "Expected numeric value for '#{name}'; got #{peek.inspect}"
+ raise MalformattedArgumentError, "Expected numeric value for '#{name}'; got #{peek.inspect}"
end
value = $&.index(".") ? shift.to_f : shift.to_i
if @switches.is_a?(Hash) && switch = @switches[name]
if switch.enum && !switch.enum.include?(value)
- fail MalformattedArgumentError, "Expected '#{name}' to be one of #{switch.enum.join(', ')}; got #{value}"
+ raise MalformattedArgumentError, "Expected '#{name}' to be one of #{switch.enum.join(', ')}; got #{value}"
end
end
value
@@ -150,9 +152,9 @@ class Bundler::Thor
nil
else
value = shift
- if @switches.is_a?(Hash) && switch = @switches[name] # rubocop:disable AssignmentInCondition
+ if @switches.is_a?(Hash) && switch = @switches[name]
if switch.enum && !switch.enum.include?(value)
- fail MalformattedArgumentError, "Expected '#{name}' to be one of #{switch.enum.join(', ')}; got #{value}"
+ raise MalformattedArgumentError, "Expected '#{name}' to be one of #{switch.enum.join(', ')}; got #{value}"
end
end
value
@@ -162,14 +164,12 @@ class Bundler::Thor
# Raises an error if @non_assigned_required array is not empty.
#
def check_requirement!
- unless @non_assigned_required.empty?
- names = @non_assigned_required.map do |o|
- o.respond_to?(:switch_name) ? o.switch_name : o.human_name
- end.join("', '")
-
- class_name = self.class.name.split("::").last.downcase
- fail RequiredArgumentMissingError, "No value provided for required #{class_name} '#{names}'"
- end
+ return if @non_assigned_required.empty?
+ names = @non_assigned_required.map do |o|
+ o.respond_to?(:switch_name) ? o.switch_name : o.human_name
+ end.join("', '")
+ class_name = self.class.name.split("::").last.downcase
+ raise RequiredArgumentMissingError, "No value provided for required #{class_name} '#{names}'"
end
end
end
diff --git a/lib/bundler/vendor/thor/lib/thor/parser/option.rb b/lib/bundler/vendor/thor/lib/thor/parser/option.rb
index eb893617f4..032493075d 100644
--- a/lib/bundler/vendor/thor/lib/thor/parser/option.rb
+++ b/lib/bundler/vendor/thor/lib/thor/parser/option.rb
@@ -40,31 +40,33 @@ class Bundler::Thor
#
# By default all options are optional, unless :required is given.
#
- def self.parse(key, value) # rubocop:disable MethodLength
+ def self.parse(key, value)
if key.is_a?(Array)
name, *aliases = key
else
- name, aliases = key, []
+ name = key
+ aliases = []
end
name = name.to_s
default = value
type = case value
- when Symbol
- default = nil
- if VALID_TYPES.include?(value)
- value
- elsif required = (value == :required) # rubocop:disable AssignmentInCondition
- :string
- end
- when TrueClass, FalseClass
- :boolean
- when Numeric
- :numeric
- when Hash, Array, String
- value.class.name.downcase.to_sym
- end
+ when Symbol
+ default = nil
+ if VALID_TYPES.include?(value)
+ value
+ elsif required = (value == :required) # rubocop:disable AssignmentInCondition
+ :string
+ end
+ when TrueClass, FalseClass
+ :boolean
+ when Numeric
+ :numeric
+ when Hash, Array, String
+ value.class.name.downcase.to_sym
+ end
+
new(name.to_s, :required => required, :type => type, :default => default, :aliases => aliases)
end
@@ -86,7 +88,7 @@ class Bundler::Thor
sample = "[#{sample}]" unless required?
if boolean?
- sample << ", [#{dasherize("no-" + human_name)}]" unless name == "force"
+ sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.start_with?("no-")
end
if aliases.empty?
@@ -107,7 +109,26 @@ class Bundler::Thor
protected
def validate!
- fail ArgumentError, "An option cannot be boolean and required." if boolean? && required?
+ raise ArgumentError, "An option cannot be boolean and required." if boolean? && required?
+ validate_default_type!
+ end
+
+ def validate_default_type!
+ default_type = case @default
+ when nil
+ return
+ when TrueClass, FalseClass
+ required? ? :string : :boolean
+ when Numeric
+ :numeric
+ when Symbol
+ :string
+ when Hash, Array, String
+ @default.class.name.downcase.to_sym
+ end
+
+ # TODO: This should raise an ArgumentError in a future version of Bundler::Thor
+ warn "Expected #{@type} default value for '#{switch_name}'; got #{@default.inspect} (#{default_type})" unless default_type == @type
end
def dasherized?
@@ -119,7 +140,7 @@ class Bundler::Thor
end
def dasherize(str)
- (str.length > 1 ? "--" : "-") + str.gsub("_", "-")
+ (str.length > 1 ? "--" : "-") + str.tr("_", "-")
end
end
end
diff --git a/lib/bundler/vendor/thor/lib/thor/parser/options.rb b/lib/bundler/vendor/thor/lib/thor/parser/options.rb
index deac6a0c16..3ce8f55f94 100644
--- a/lib/bundler/vendor/thor/lib/thor/parser/options.rb
+++ b/lib/bundler/vendor/thor/lib/thor/parser/options.rb
@@ -14,7 +14,7 @@ class Bundler::Thor
when true
"--#{key}"
when Array
- "--#{key} #{value.map { |v| v.inspect }.join(' ')}"
+ "--#{key} #{value.map(&:inspect).join(' ')}"
when Hash
"--#{key} #{value.map { |k, v| "#{k}:#{v}" }.join(' ')}"
when nil, false
@@ -40,7 +40,9 @@ class Bundler::Thor
@non_assigned_required.delete(hash_options[key])
end
- @shorts, @switches, @extra = {}, {}, []
+ @shorts = {}
+ @switches = {}
+ @extra = []
options.each do |option|
@switches[option.switch_name] = option
@@ -52,7 +54,7 @@ class Bundler::Thor
end
end
- def remaining # rubocop:disable TrivialAccessors
+ def remaining
@extra
end
@@ -119,7 +121,7 @@ class Bundler::Thor
def check_unknown!
# an unknown option starts with - or -- and has no more --'s afterward.
unknown = @extra.select { |str| str =~ /^--?(?:(?!--).)*$/ }
- fail UnknownArgumentError, "Unknown switches '#{unknown.join(', ')}'" unless unknown.empty?
+ raise UnknownArgumentError, "Unknown switches '#{unknown.join(', ')}'" unless unknown.empty?
end
protected
@@ -207,7 +209,7 @@ class Bundler::Thor
elsif option.lazy_default
return option.lazy_default
else
- fail MalformattedArgumentError, "No value provided for option '#{switch}'"
+ raise MalformattedArgumentError, "No value provided for option '#{switch}'"
end
end
diff --git a/lib/bundler/vendor/thor/lib/thor/runner.rb b/lib/bundler/vendor/thor/lib/thor/runner.rb
index f0d7bfe2e0..4e96f7730a 100644
--- a/lib/bundler/vendor/thor/lib/thor/runner.rb
+++ b/lib/bundler/vendor/thor/lib/thor/runner.rb
@@ -11,10 +11,18 @@ require "pathname"
class Bundler::Thor::Runner < Bundler::Thor #:nodoc: # rubocop:disable ClassLength
map "-T" => :list, "-i" => :install, "-u" => :update, "-v" => :version
+ def self.banner(command, all = false, subcommand = false)
+ "thor " + command.formatted_usage(self, all, subcommand)
+ end
+
+ def self.exit_on_failure?
+ true
+ end
+
# Override Bundler::Thor#help so it can give information about any class and any method.
#
def help(meth = nil)
- if meth && !self.respond_to?(meth)
+ if meth && !respond_to?(meth)
initialize_thorfiles(meth)
klass, command = Bundler::Thor::Util.find_class_and_command_by_namespace(meth)
self.class.handle_no_command_error(command, false) if klass.nil?
@@ -45,16 +53,18 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: # rubocop:disable ClassLeng
# command in said directory.
begin
if File.directory?(File.expand_path(name))
- base, package = File.join(name, "main.thor"), :directory
- contents = open(base) { |input| input.read }
+ base = File.join(name, "main.thor")
+ package = :directory
+ contents = open(base, &:read)
else
- base, package = name, :file
- contents = open(name) { |input| input.read }
+ base = name
+ package = :file
+ contents = open(name, &:read)
end
rescue OpenURI::HTTPError
raise Error, "Error opening URI '#{name}'"
rescue Errno::ENOENT
- fail Error, "Error opening file '#{name}'"
+ raise Error, "Error opening file '#{name}'"
end
say "Your Bundler::Thorfile contains:"
@@ -108,9 +118,9 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: # rubocop:disable ClassLeng
desc "uninstall NAME", "Uninstall a named Bundler::Thor module"
def uninstall(name)
- fail Error, "Can't find module '#{name}'" unless thor_yaml[name]
+ raise Error, "Can't find module '#{name}'" unless thor_yaml[name]
say "Uninstalling #{name}."
- FileUtils.rm_rf(File.join(thor_root, "#{thor_yaml[name][:filename]}"))
+ FileUtils.rm_rf(File.join(thor_root, (thor_yaml[name][:filename]).to_s))
thor_yaml.delete(name)
save_yaml(thor_yaml)
@@ -120,7 +130,7 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: # rubocop:disable ClassLeng
desc "update NAME", "Update a Bundler::Thor file from its original location"
def update(name)
- fail Error, "Can't find module '#{name}'" if !thor_yaml[name] || !thor_yaml[name][:location]
+ raise Error, "Can't find module '#{name}'" if !thor_yaml[name] || !thor_yaml[name][:location]
say "Updating '#{name}' from #{thor_yaml[name][:location]}"
@@ -138,9 +148,7 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: # rubocop:disable ClassLeng
filename = install(thor_yaml[name][:location])
end
- unless filename == old_filename
- File.delete(File.join(thor_root, old_filename))
- end
+ File.delete(File.join(thor_root, old_filename)) unless filename == old_filename
end
desc "installed", "List the installed Bundler::Thor modules and commands"
@@ -168,10 +176,6 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: # rubocop:disable ClassLeng
private
- def self.banner(command, all = false, subcommand = false)
- "thor " + command.formatted_usage(self, all, subcommand)
- end
-
def thor_root
Bundler::Thor::Util.thor_root
end
@@ -198,10 +202,6 @@ private
File.open(yaml_file, "w") { |f| f.puts yaml.to_yaml }
end
- def self.exit_on_failure?
- true
- end
-
# Load the Bundler::Thorfiles. If relevant_to is supplied, looks for specific files
# in the thor_root instead of loading them all.
#
@@ -263,11 +263,11 @@ private
def thorfiles_relevant_to(meth)
lookup = [meth, meth.split(":")[0...-1].join(":")]
- files = thor_yaml.select do |k, v|
+ files = thor_yaml.select do |_, v|
v[:namespaces] && !(v[:namespaces] & lookup).empty?
end
- files.map { |k, v| File.join(thor_root, "#{v[:filename]}") }
+ files.map { |_, v| File.join(thor_root, (v[:filename]).to_s) }
end
# Display information about the given klasses. If with_module is given,
@@ -276,7 +276,7 @@ private
def display_klasses(with_modules = false, show_internal = false, klasses = Bundler::Thor::Base.subclasses)
klasses -= [Bundler::Thor, Bundler::Thor::Runner, Bundler::Thor::Group] unless show_internal
- fail Error, "No Bundler::Thor commands available" if klasses.empty?
+ raise Error, "No Bundler::Thor commands available" if klasses.empty?
show_modules if with_modules && !thor_yaml.empty?
list = Hash.new { |h, k| h[k] = [] }
@@ -306,8 +306,8 @@ private
alias_method :display_tasks, :display_commands
def show_modules #:nodoc:
- info = []
- labels = %w[Modules Namespaces]
+ info = []
+ labels = %w(Modules Namespaces)
info << labels
info << ["-" * labels[0].size, "-" * labels[1].size]
diff --git a/lib/bundler/vendor/thor/lib/thor/shell.rb b/lib/bundler/vendor/thor/lib/thor/shell.rb
index 91afdce2aa..e945549324 100644
--- a/lib/bundler/vendor/thor/lib/thor/shell.rb
+++ b/lib/bundler/vendor/thor/lib/thor/shell.rb
@@ -9,7 +9,7 @@ class Bundler::Thor
# it will use a colored log, otherwise it will use a basic one without color.
#
def shell
- @shell ||= if ENV["THOR_SHELL"] && ENV["THOR_SHELL"].size > 0
+ @shell ||= if ENV["THOR_SHELL"] && !ENV["THOR_SHELL"].empty?
Bundler::Thor::Shell.const_get(ENV["THOR_SHELL"])
elsif RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ && !ENV["ANSICON"]
Bundler::Thor::Shell::Basic
diff --git a/lib/bundler/vendor/thor/lib/thor/shell/basic.rb b/lib/bundler/vendor/thor/lib/thor/shell/basic.rb
index 278ffa3df0..52b6dfd225 100644
--- a/lib/bundler/vendor/thor/lib/thor/shell/basic.rb
+++ b/lib/bundler/vendor/thor/lib/thor/shell/basic.rb
@@ -3,14 +3,17 @@ require "io/console" if RUBY_VERSION > "1.9.2"
class Bundler::Thor
module Shell
- class Basic # rubocop:disable ClassLength
+ class Basic
attr_accessor :base
attr_reader :padding
# Initialize base, mute and padding to nil.
#
def initialize #:nodoc:
- @base, @mute, @padding, @always_force = nil, false, 0, false
+ @base = nil
+ @mute = false
+ @padding = 0
+ @always_force = false
end
# Mute everything that's inside given block
@@ -24,7 +27,7 @@ class Bundler::Thor
# Check if base is muted
#
- def mute? # rubocop:disable TrivialAccessors
+ def mute?
@mute
end
@@ -34,6 +37,15 @@ class Bundler::Thor
@padding = [0, value].max
end
+ # Sets the output padding while executing a block and resets it.
+ #
+ def indent(count = 1)
+ orig_padding = padding
+ self.padding = padding + count
+ yield
+ self.padding = orig_padding
+ end
+
# Asks something to the user and receives a response.
#
# If asked to limit the correct responses, you can pass in an
@@ -148,7 +160,9 @@ class Bundler::Thor
def print_table(array, options = {}) # rubocop:disable MethodLength
return if array.empty?
- formats, indent, colwidth = [], options[:indent].to_i, options[:colwidth]
+ formats = []
+ indent = options[:indent].to_i
+ colwidth = options[:colwidth]
options[:truncate] = terminal_width if options[:truncate] == true
formats << "%-#{colwidth + 2}s" if colwidth
@@ -161,12 +175,12 @@ class Bundler::Thor
start.upto(colcount - 1) do |index|
maxima = array.map { |row| row[index] ? row[index].to_s.size : 0 }.max
maximas << maxima
- if index == colcount - 1
- # Don't output 2 trailing spaces when printing the last column
- formats << "%-s"
- else
- formats << "%-#{maxima + 2}s"
- end
+ formats << if index == colcount - 1
+ # Don't output 2 trailing spaces when printing the last column
+ "%-s"
+ else
+ "%-#{maxima + 2}s"
+ end
end
formats[0] = formats[0].insert(0, " " * indent)
@@ -178,15 +192,15 @@ class Bundler::Thor
row.each_with_index do |column, index|
maxima = maximas[index]
- if column.is_a?(Numeric)
+ f = if column.is_a?(Numeric)
if index == row.size - 1
# Don't output 2 trailing spaces when printing the last column
- f = "%#{maxima}s"
+ "%#{maxima}s"
else
- f = "%#{maxima}s "
+ "%#{maxima}s "
end
else
- f = formats[index]
+ formats[index]
end
sentence << f % column.to_s
end
@@ -211,7 +225,7 @@ class Bundler::Thor
paras = message.split("\n\n")
paras.map! do |unwrapped|
- unwrapped.strip.gsub(/\n/, " ").squeeze(" ").gsub(/.{1,#{width}}(?:\s|\Z)/) { ($& + 5.chr).gsub(/\n\005/, "\n").gsub(/\005/, "\n") }
+ unwrapped.strip.tr("\n", " ").squeeze(" ").gsub(/.{1,#{width}}(?:\s|\Z)/) { ($& + 5.chr).gsub(/\n\005/, "\n").gsub(/\005/, "\n") }
end
paras.each do |para|
@@ -230,7 +244,7 @@ class Bundler::Thor
# destination<String>:: the destination file to solve conflicts
# block<Proc>:: an optional block that returns the value to be used in diff
#
- def file_collision(destination) # rubocop:disable MethodLength
+ def file_collision(destination)
return true if @always_force
options = block_given? ? "[Ynaqdh]" : "[Ynaqh]"
@@ -249,7 +263,7 @@ class Bundler::Thor
return @always_force = true
when is?(:quit)
say "Aborting..."
- fail SystemExit
+ raise SystemExit
when is?(:diff)
show_diff(destination, yield) if block_given?
say "Retrying..."
@@ -262,10 +276,10 @@ class Bundler::Thor
# This code was copied from Rake, available under MIT-LICENSE
# Copyright (c) 2003, 2004 Jim Weirich
def terminal_width
- if ENV["THOR_COLUMNS"]
- result = ENV["THOR_COLUMNS"].to_i
+ result = if ENV["THOR_COLUMNS"]
+ ENV["THOR_COLUMNS"].to_i
else
- result = unix? ? dynamic_width : 80
+ unix? ? dynamic_width : 80
end
result < 10 ? 80 : result
rescue
@@ -284,7 +298,7 @@ class Bundler::Thor
# Apply color to the given string with optional bold. Disabled in the
# Bundler::Thor::Shell::Basic class.
#
- def set_color(string, *args) #:nodoc:
+ def set_color(string, *) #:nodoc:
string
end
@@ -353,11 +367,11 @@ class Bundler::Thor
end
def dynamic_width_stty
- %x(stty size 2>/dev/null).split[1].to_i
+ `stty size 2>/dev/null`.split[1].to_i
end
def dynamic_width_tput
- %x(tput cols 2>/dev/null).to_i
+ `tput cols 2>/dev/null`.to_i
end
def unix?
@@ -370,7 +384,7 @@ class Bundler::Thor
if chars.length <= width
chars.join
else
- ( chars[0, width - 3].join) + "..."
+ chars[0, width - 3].join + "..."
end
end
end
@@ -381,7 +395,8 @@ class Bundler::Thor
end
else
def as_unicode
- old, $KCODE = $KCODE, "U"
+ old = $KCODE
+ $KCODE = "U"
yield
ensure
$KCODE = old
@@ -391,7 +406,7 @@ class Bundler::Thor
def ask_simply(statement, color, options)
default = options[:default]
message = [statement, ("(#{default})" if default), nil].uniq.join(" ")
- message = prepare_message(message, color)
+ message = prepare_message(message, *color)
result = Bundler::Thor::LineEditor.readline(message, options)
return unless result
diff --git a/lib/bundler/vendor/thor/lib/thor/shell/color.rb b/lib/bundler/vendor/thor/lib/thor/shell/color.rb
index 1e2d26cfc5..da289cb50c 100644
--- a/lib/bundler/vendor/thor/lib/thor/shell/color.rb
+++ b/lib/bundler/vendor/thor/lib/thor/shell/color.rb
@@ -134,7 +134,7 @@ class Bundler::Thor
# for diff.
#
def diff_lcs_loaded? #:nodoc:
- return true if defined?(Diff::LCS)
+ return true if defined?(Diff::LCS)
return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
@diff_lcs_loaded = begin
diff --git a/lib/bundler/vendor/thor/lib/thor/shell/html.rb b/lib/bundler/vendor/thor/lib/thor/shell/html.rb
index e1ea0de599..83d2054988 100644
--- a/lib/bundler/vendor/thor/lib/thor/shell/html.rb
+++ b/lib/bundler/vendor/thor/lib/thor/shell/html.rb
@@ -51,13 +51,13 @@ class Bundler::Thor
def set_color(string, *colors)
if colors.all? { |color| color.is_a?(Symbol) || color.is_a?(String) }
html_colors = colors.map { |color| lookup_color(color) }
- "<span style=\"#{html_colors.join("; ")};\">#{string}</span>"
+ "<span style=\"#{html_colors.join('; ')};\">#{string}</span>"
else
color, bold = colors
html_color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
styles = [html_color]
styles << BOLD if bold
- "<span style=\"#{styles.join("; ")};\">#{string}</span>"
+ "<span style=\"#{styles.join('; ')};\">#{string}</span>"
end
end
@@ -68,7 +68,7 @@ class Bundler::Thor
#
# TODO: Implement #ask for Bundler::Thor::Shell::HTML
def ask(statement, color = nil)
- fail NotImplementedError, "Implement #ask for Bundler::Thor::Shell::HTML"
+ raise NotImplementedError, "Implement #ask for Bundler::Thor::Shell::HTML"
end
protected
@@ -111,7 +111,7 @@ class Bundler::Thor
# for diff.
#
def diff_lcs_loaded? #:nodoc:
- return true if defined?(Diff::LCS)
+ return true if defined?(Diff::LCS)
return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
@diff_lcs_loaded = begin
diff --git a/lib/bundler/vendor/thor/lib/thor/util.rb b/lib/bundler/vendor/thor/lib/thor/util.rb
index f4e98fc19f..5d03177a28 100644
--- a/lib/bundler/vendor/thor/lib/thor/util.rb
+++ b/lib/bundler/vendor/thor/lib/thor/util.rb
@@ -64,7 +64,7 @@ class Bundler::Thor
new_constants = Bundler::Thor::Base.subclasses.dup
Bundler::Thor::Base.subclasses.replace(old_constants)
- new_constants.map! { |c| c.namespace }
+ new_constants.map!(&:namespace)
new_constants.compact!
new_constants
end
@@ -72,7 +72,7 @@ class Bundler::Thor
# Returns the thor classes declared inside the given class.
#
def thor_classes_in(klass)
- stringfied_constants = klass.constants.map { |c| c.to_s }
+ stringfied_constants = klass.constants.map(&:to_s)
Bundler::Thor::Base.subclasses.select do |subclass|
next unless subclass.name
stringfied_constants.include?(subclass.name.gsub("#{klass.name}::", ""))
@@ -103,7 +103,7 @@ class Bundler::Thor
#
def camel_case(str)
return str if str !~ /_/ && str =~ /[A-Z]+.*/
- str.split("_").map { |i| i.capitalize }.join
+ str.split("_").map(&:capitalize).join
end
# Receives a namespace and tries to retrieve a Bundler::Thor or Bundler::Thor::Group class
@@ -135,7 +135,8 @@ class Bundler::Thor
klass = Bundler::Thor::Util.find_by_namespace(pieces.join(":"))
end
unless klass # look for a Bundler::Thor::Group with the right name
- klass, command = Bundler::Thor::Util.find_by_namespace(namespace), nil
+ klass = Bundler::Thor::Util.find_by_namespace(namespace)
+ command = nil
end
if !klass && fallback # try a command in the default namespace
command = namespace
@@ -163,7 +164,7 @@ class Bundler::Thor
end
end
- def user_home # rubocop:disable MethodLength
+ def user_home
@@user_home ||= if ENV["HOME"]
ENV["HOME"]
elsif ENV["USERPROFILE"]
@@ -188,7 +189,7 @@ class Bundler::Thor
# Returns the root where thor files are located, depending on the OS.
#
def thor_root
- File.join(user_home, ".thor").gsub(/\\/, "/")
+ File.join(user_home, ".thor").tr('\\', "/")
end
# Returns the files in the thor root. On Windows thor_root will be something
@@ -216,7 +217,7 @@ class Bundler::Thor
# Return the path to the ruby interpreter taking into account multiple
# installations and windows extensions.
#
- def ruby_command # rubocop:disable MethodLength
+ def ruby_command
@ruby_command ||= begin
ruby_name = RbConfig::CONFIG["ruby_install_name"]
ruby = File.join(RbConfig::CONFIG["bindir"], ruby_name)
diff --git a/lib/bundler/vendor/thor/lib/thor/version.rb b/lib/bundler/vendor/thor/lib/thor/version.rb
index 74b020a5ab..a6d838b103 100644
--- a/lib/bundler/vendor/thor/lib/thor/version.rb
+++ b/lib/bundler/vendor/thor/lib/thor/version.rb
@@ -1,3 +1,3 @@
class Bundler::Thor
- VERSION = "0.19.1"
+ VERSION = "0.19.4"
end