Update vendored thor to 1.3.2

This commit is contained in:
David Rodríguez 2024-11-11 20:45:08 +01:00 committed by Hiroshi SHIBATA
parent 99c35edae1
commit 7ece47e0de
12 changed files with 48 additions and 46 deletions

View File

@ -439,6 +439,17 @@ class Bundler::Thor
command && disable_required_check.include?(command.name.to_sym) command && disable_required_check.include?(command.name.to_sym)
end end
# Checks if a specified command exists.
#
# ==== Parameters
# command_name<String>:: The name of the command to check for existence.
#
# ==== Returns
# Boolean:: +true+ if the command exists, +false+ otherwise.
def command_exists?(command_name) #:nodoc:
commands.keys.include?(normalize_command_name(command_name))
end
protected protected
# Returns this class exclusive options array set. # Returns this class exclusive options array set.

View File

@ -10,7 +10,6 @@ class Bundler::Thor
# destination<String>:: the relative path to the destination root. # destination<String>:: the relative path to the destination root.
# config<Hash>:: give :verbose => false to not log the status, and # config<Hash>:: give :verbose => false to not log the status, and
# :mode => :preserve, to preserve the file mode from the source. # :mode => :preserve, to preserve the file mode from the source.
# #
# ==== Examples # ==== Examples
# #
@ -275,9 +274,8 @@ class Bundler::Thor
end end
end end
# Uncomment all lines matching a given regex. It will leave the space # Uncomment all lines matching a given regex. Preserves indentation before
# which existed before the comment hash in tact but will remove any spacing # the comment hash and removes the hash and any immediate following space.
# between the comment hash and the beginning of the line.
# #
# ==== Parameters # ==== Parameters
# path<String>:: path of the file to be changed # path<String>:: path of the file to be changed
@ -291,7 +289,7 @@ class Bundler::Thor
def uncomment_lines(path, flag, *args) def uncomment_lines(path, flag, *args)
flag = flag.respond_to?(:source) ? flag.source : flag flag = flag.respond_to?(:source) ? flag.source : flag
gsub_file(path, /^(\s*)#[[:blank:]]*(.*#{flag})/, '\1\2', *args) gsub_file(path, /^(\s*)#[[:blank:]]?(.*#{flag})/, '\1\2', *args)
end end
# Comment all lines matching a given regex. It will leave the space # Comment all lines matching a given regex. It will leave the space

View File

@ -211,6 +211,17 @@ class Bundler::Thor::Group
raise error, msg raise error, msg
end end
# Checks if a specified command exists.
#
# ==== Parameters
# command_name<String>:: The name of the command to check for existence.
#
# ==== Returns
# Boolean:: +true+ if the command exists, +false+ otherwise.
def command_exists?(command_name) #:nodoc:
commands.keys.include?(command_name)
end
protected protected
# The method responsible for dispatching given the args. # The method responsible for dispatching given the args.

View File

@ -26,10 +26,7 @@ class Bundler::Thor
def print_default def print_default
if @type == :array and @default.is_a?(Array) if @type == :array and @default.is_a?(Array)
@default.map { |x| @default.map(&:dump).join(" ")
p = x.gsub('"','\\"')
"\"#{p}\""
}.join(" ")
else else
@default @default
end end

View File

@ -89,8 +89,8 @@ class Bundler::Thor
sample = "[#{sample}]".dup unless required? sample = "[#{sample}]".dup unless required?
if boolean? if boolean? && name != "force" && !name.match(/\A(no|skip)[\-_]/)
sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.match(/\Ano[\-_]/) sample << ", [#{dasherize('no-' + human_name)}], [#{dasherize('skip-' + human_name)}]"
end end
aliases_for_usage.ljust(padding) + sample aliases_for_usage.ljust(padding) + sample

View File

@ -250,7 +250,8 @@ class Bundler::Thor
@parsing_options @parsing_options
end end
# Parse boolean values which can be given as --foo=true, --foo or --no-foo. # Parse boolean values which can be given as --foo=true or --foo for true values, or
# --foo=false, --no-foo or --skip-foo for false values.
# #
def parse_boolean(switch) def parse_boolean(switch)
if current_is_value? if current_is_value?

View File

@ -67,15 +67,15 @@ class Bundler::Thor
# Readline. # Readline.
# #
# ==== Example # ==== Example
# ask("What is your name?") # ask("What is your name?")
# #
# ask("What is the planet furthest from the sun?", :default => "Pluto") # ask("What is the planet furthest from the sun?", :default => "Neptune")
# #
# ask("What is your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"]) # ask("What is your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])
# #
# ask("What is your password?", :echo => false) # ask("What is your password?", :echo => false)
# #
# ask("Where should the file be saved?", :path => true) # ask("Where should the file be saved?", :path => true)
# #
def ask(statement, *args) def ask(statement, *args)
options = args.last.is_a?(Hash) ? args.pop : {} options = args.last.is_a?(Hash) ? args.pop : {}
@ -93,7 +93,7 @@ class Bundler::Thor
# are passed straight to puts (behavior got from Highline). # are passed straight to puts (behavior got from Highline).
# #
# ==== Example # ==== Example
# say("I know you knew that.") # say("I know you knew that.")
# #
def say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/)) def say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/))
return if quiet? return if quiet?
@ -110,7 +110,7 @@ class Bundler::Thor
# are passed straight to puts (behavior got from Highline). # are passed straight to puts (behavior got from Highline).
# #
# ==== Example # ==== Example
# say_error("error: something went wrong") # say_error("error: something went wrong")
# #
def say_error(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/)) def say_error(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/))
return if quiet? return if quiet?
@ -143,14 +143,14 @@ class Bundler::Thor
stdout.flush stdout.flush
end end
# Make a question the to user and returns true if the user replies "y" or # Asks the user a question and returns true if the user replies "y" or
# "yes". # "yes".
# #
def yes?(statement, color = nil) def yes?(statement, color = nil)
!!(ask(statement, color, add_to_history: false) =~ is?(:yes)) !!(ask(statement, color, add_to_history: false) =~ is?(:yes))
end end
# Make a question the to user and returns true if the user replies "n" or # Asks the user a question and returns true if the user replies "n" or
# "no". # "no".
# #
def no?(statement, color = nil) def no?(statement, color = nil)

View File

@ -64,7 +64,7 @@ class Bundler::Thor
# Ask something to the user and receives a response. # Ask something to the user and receives a response.
# #
# ==== Example # ==== Example
# ask("What is your name?") # ask("What is your name?")
# #
# TODO: Implement #ask for Bundler::Thor::Shell::HTML # TODO: Implement #ask for Bundler::Thor::Shell::HTML
def ask(statement, color = nil) def ask(statement, color = nil)

View File

@ -102,33 +102,17 @@ class Bundler::Thor
def truncate(string) def truncate(string)
return string unless @truncate return string unless @truncate
as_unicode do chars = string.chars.to_a
chars = string.chars.to_a if chars.length <= @truncate
if chars.length <= @truncate chars.join
chars.join else
else chars[0, @truncate - 3 - @indent].join + "..."
chars[0, @truncate - 3 - @indent].join + "..."
end
end end
end end
def indentation def indentation
" " * @indent " " * @indent
end end
if "".respond_to?(:encode)
def as_unicode
yield
end
else
def as_unicode
old = $KCODE # rubocop:disable Style/GlobalVars
$KCODE = "U" # rubocop:disable Style/GlobalVars
yield
ensure
$KCODE = old # rubocop:disable Style/GlobalVars
end
end
end end
end end
end end

View File

@ -133,7 +133,7 @@ class Bundler::Thor
*pieces, command = namespace.split(":") *pieces, command = namespace.split(":")
namespace = pieces.join(":") namespace = pieces.join(":")
namespace = "default" if namespace.empty? namespace = "default" if namespace.empty?
klass = Bundler::Thor::Base.subclasses.detect { |thor| thor.namespace == namespace && thor.commands.keys.include?(command) } klass = Bundler::Thor::Base.subclasses.detect { |thor| thor.namespace == namespace && thor.command_exists?(command) }
end end
unless klass # look for a Bundler::Thor::Group with the right name unless klass # look for a Bundler::Thor::Group with the right name
klass = Bundler::Thor::Util.find_by_namespace(namespace) klass = Bundler::Thor::Util.find_by_namespace(namespace)

View File

@ -1,3 +1,3 @@
class Bundler::Thor class Bundler::Thor
VERSION = "1.3.0" VERSION = "1.3.2"
end end

View File

@ -12,6 +12,6 @@ gem "pub_grub", github: "jhawthorn/pub_grub"
gem "resolv", "0.5.0" gem "resolv", "0.5.0"
gem "securerandom", "0.3.2" gem "securerandom", "0.3.2"
gem "timeout", "0.4.2" gem "timeout", "0.4.2"
gem "thor", "1.3.0" gem "thor", "1.3.2"
gem "tsort", "0.2.0" gem "tsort", "0.2.0"
gem "uri", "1.0.1" gem "uri", "1.0.1"