diff options
-rw-r--r-- | lib/bundler/vendor/thor.rb | 70 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/actions/create_link.rb | 2 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/actions/file_manipulation.rb | 2 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/base.rb | 34 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/group.rb | 14 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/invocation.rb | 4 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/parser/arguments.rb | 4 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/parser/options.rb | 20 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/rake_compat.rb | 21 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/runner.rb | 2 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/shell.rb | 2 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/shell/basic.rb | 4 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/task.rb | 20 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/version.rb | 2 |
14 files changed, 60 insertions, 141 deletions
diff --git a/lib/bundler/vendor/thor.rb b/lib/bundler/vendor/thor.rb index c7ba3e15..92b24342 100644 --- a/lib/bundler/vendor/thor.rb +++ b/lib/bundler/vendor/thor.rb @@ -5,7 +5,7 @@ class Thor # Sets the default task when thor is executed without an explicit task to be called. # # ==== Parameters - # meth<Symbol>:: name of the default task + # meth<Symbol>:: name of the defaut task # def default_task(meth=nil) case meth @@ -108,8 +108,6 @@ class Thor @method_options end - alias options method_options - # Adds an option to the set of method options. If :for is given as option, # it allows you to change the options from a previous defined task. # @@ -145,8 +143,6 @@ class Thor build_option(name, options, scope) end - alias option method_option - # Prints help information for the given task. # # ==== Parameters @@ -206,11 +202,7 @@ class Thor def subcommand(subcommand, subcommand_class) self.subcommands << subcommand.to_s subcommand_class.subcommand_help subcommand - - define_method(subcommand) do |*args| - args, opts = Thor::Arguments.split(args) - invoke subcommand_class, args, opts - end + define_method(subcommand) { |*args| invoke subcommand_class, args } end # Extend check unknown options to accept a hash of conditions. @@ -267,11 +259,8 @@ class Thor opts = given_opts || opts || [] config.merge!(:current_task => task, :task_options => task.options) - instance = new(args, opts, config) - yield instance if block_given? - args = instance.args trailing = args[Range.new(arguments.size, -1)] - instance.invoke_task(task, trailing || []) + new(args, opts, config).invoke_task(task, trailing || []) end # The banner for this class. You can customize it if you are invoking the @@ -311,6 +300,7 @@ class Thor # Retrieve the task name from given args. def retrieve_task_name(args) #:nodoc: meth = args.first.to_s unless args.empty? + if meth && (map[meth] || meth !~ /^\-/) args.shift else @@ -318,45 +308,35 @@ class Thor end end - # receives a (possibly nil) task name and returns a name that is in - # the tasks hash. In addition to normalizing aliases, this logic - # will determine if a shortened command is an unambiguous prefix of - # a task or alias. - # - # +normalize_task_name+ also converts names like +animal-prison+ - # into +animal_prison+. + # Receives a task name (can be nil), and try to get a map from it. + # If a map can't be found use the sent name or the default task. def normalize_task_name(meth) #:nodoc: - return default_task.to_s.gsub('-', '_') unless meth + meth = map[meth.to_s] || find_subcommand_and_update_argv(meth) || meth || default_task + meth.to_s.gsub('-','_') # treat foo-bar > foo_bar + end + + # terrible hack that overwrites ARGV + def find_subcommand_and_update_argv(subcmd_name) #:nodoc: + return unless subcmd_name + cmd = find_subcommand(subcmd_name) + ARGV[0] = cmd if cmd + cmd + end - possibilities = find_task_possibilities(meth) + def find_subcommand(subcmd_name) + possibilities = find_subcommand_possibilities subcmd_name if possibilities.size > 1 - raise ArgumentError, "Ambiguous task #{meth} matches [#{possibilities.join(', ')}]" + raise "Ambiguous subcommand #{subcmd_name} matches [#{possibilities.join(', ')}]" elsif possibilities.size < 1 - meth = meth || default_task - elsif map[meth] - meth = map[meth] - else - meth = possibilities.first + return nil end - meth.to_s.gsub('-','_') # treat foo-bar as foo_bar + possibilities.first end - # this is the logic that takes the task name passed in by the user - # and determines whether it is an unambiguous prefix of a task or - # alias name. - def find_task_possibilities(meth) - len = meth.to_s.length - possibilities = all_tasks.merge(map).keys.select { |n| meth == n[0, len] }.sort - unique_possibilities = possibilities.map { |k| map[k] || k }.uniq - - if possibilities.include?(meth) - [meth] - elsif unique_possibilities.size == 1 - unique_possibilities - else - possibilities - end + def find_subcommand_possibilities(subcmd_name) + len = subcmd_name.length + all_tasks.map {|t| t.first}.select { |n| subcmd_name == n[0, len] } end def subcommand_help(cmd) diff --git a/lib/bundler/vendor/thor/actions/create_link.rb b/lib/bundler/vendor/thor/actions/create_link.rb index 864a1e99..1975644a 100644 --- a/lib/bundler/vendor/thor/actions/create_link.rb +++ b/lib/bundler/vendor/thor/actions/create_link.rb @@ -41,7 +41,7 @@ class Thor invoke_with_conflict_check do FileUtils.mkdir_p(File.dirname(destination)) # Create a symlink by default - config[:symbolic] = true if config[:symbolic].nil? + config[:symbolic] ||= true File.unlink(destination) if exists? if config[:symbolic] File.symlink(render, destination) diff --git a/lib/bundler/vendor/thor/actions/file_manipulation.rb b/lib/bundler/vendor/thor/actions/file_manipulation.rb index dee9fbdd..ad049b3c 100644 --- a/lib/bundler/vendor/thor/actions/file_manipulation.rb +++ b/lib/bundler/vendor/thor/actions/file_manipulation.rb @@ -187,7 +187,7 @@ class Thor # # ==== Examples # - # inject_into_class "app/controllers/application_controller.rb", ApplicationController, " filter_parameter :password\n" + # inject_into_class "app/controllers/application_controller.rb", " filter_parameter :password\n" # # inject_into_class "app/controllers/application_controller.rb", ApplicationController do # " filter_parameter :password\n" diff --git a/lib/bundler/vendor/thor/base.rb b/lib/bundler/vendor/thor/base.rb index 62706f72..65399ffb 100644 --- a/lib/bundler/vendor/thor/base.rb +++ b/lib/bundler/vendor/thor/base.rb @@ -19,7 +19,7 @@ class Thor action add_file create_file in_root inside run run_ruby_script) module Base - attr_accessor :options, :parent_options, :args + attr_accessor :options # It receives arguments in an Array and two hashes, one for options and # other for configuration. @@ -38,43 +38,22 @@ class Thor # config<Hash>:: Configuration for this Thor class. # def initialize(args=[], options={}, config={}) - parse_options = self.class.class_options + args = Thor::Arguments.parse(self.class.arguments, args) + args.each { |key, value| send("#{key}=", value) } - # The start method splits inbound arguments at the first argument - # that looks like an option (starts with - or --). It then calls - # new, passing in the two halves of the arguments Array as the - # first two parameters. + parse_options = self.class.class_options if options.is_a?(Array) task_options = config.delete(:task_options) # hook for start parse_options = parse_options.merge(task_options) if task_options array_options, hash_options = options, {} else - # Handle the case where the class was explicitly instantiated - # with pre-parsed options. array_options, hash_options = [], options end - # Let Thor::Options parse the options first, so it can remove - # declared options from the array. This will leave us with - # a list of arguments that weren't declared. opts = Thor::Options.new(parse_options, hash_options) self.options = opts.parse(array_options) - - # If unknown options are disallowed, make sure that none of the - # remaining arguments looks like an option. opts.check_unknown! if self.class.check_unknown_options?(config) - - # Add the remaining arguments from the options parser to the - # arguments passed in to initialize. Then remove any positional - # arguments declared using #argument (this is primarily used - # by Thor::Group). Tis will leave us with the remaining - # positional arguments. - thor_args = Thor::Arguments.new(self.class.arguments) - thor_args.parse(args + opts.remaining).each { |k,v| send("#{k}=", v) } - args = thor_args.remaining - - @args = args end class << self @@ -426,8 +405,8 @@ class Thor end end - def handle_no_task_error(task, has_namespace = $thor_runner) #:nodoc: - if has_namespace + def handle_no_task_error(task) #:nodoc: + if $thor_runner raise UndefinedTaskError, "Could not find task #{task.inspect} in #{namespace.inspect} namespace." else raise UndefinedTaskError, "Could not find task #{task.inspect}." @@ -527,7 +506,6 @@ class Thor # and file into baseclass. def inherited(klass) Thor::Base.register_klass_file(klass) - klass.instance_variable_set(:@no_tasks, false) end # Fire this callback whenever a method is added. Added methods are diff --git a/lib/bundler/vendor/thor/group.rb b/lib/bundler/vendor/thor/group.rb index e948b9ae..3dbab98a 100644 --- a/lib/bundler/vendor/thor/group.rb +++ b/lib/bundler/vendor/thor/group.rb @@ -187,9 +187,9 @@ class Thor::Group human_name = value.respond_to?(:classify) ? value.classify : value 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[human_name] += klass.class_options.values.select do |option| + base_options[option.name.to_sym].nil? && option.group.nil? && + !group_options.values.flatten.any? { |i| i.name == option.name } end yield klass if block_given? @@ -220,14 +220,10 @@ class Thor::Group args, opts = Thor::Options.split(given_args) opts = given_opts || opts - instance = new(args, opts, config) - yield instance if block_given? - args = instance.args - if task - instance.invoke_task(all_tasks[task]) + new(args, opts, config).invoke_task(all_tasks[task]) else - instance.invoke_all + new(args, opts, config).invoke_all end end diff --git a/lib/bundler/vendor/thor/invocation.rb b/lib/bundler/vendor/thor/invocation.rb index 9c645472..6315dd42 100644 --- a/lib/bundler/vendor/thor/invocation.rb +++ b/lib/bundler/vendor/thor/invocation.rb @@ -106,9 +106,7 @@ class Thor raise "Expected Thor class, got #{klass}" unless klass <= Thor::Base args, opts, config = _parse_initialization_options(args, opts, config) - klass.send(:dispatch, task, args, opts, config) do |instance| - instance.parent_options = options - end + klass.send(:dispatch, task, args, opts, config) end # Invoke the given task if the given args. diff --git a/lib/bundler/vendor/thor/parser/arguments.rb b/lib/bundler/vendor/thor/parser/arguments.rb index 12db2b23..888ef692 100644 --- a/lib/bundler/vendor/thor/parser/arguments.rb +++ b/lib/bundler/vendor/thor/parser/arguments.rb @@ -49,10 +49,6 @@ class Thor @assigns end - def remaining - @pile - end - private def no_or_skip?(arg) diff --git a/lib/bundler/vendor/thor/parser/options.rb b/lib/bundler/vendor/thor/parser/options.rb index c6829c0b..9b1d042d 100644 --- a/lib/bundler/vendor/thor/parser/options.rb +++ b/lib/bundler/vendor/thor/parser/options.rb @@ -38,7 +38,7 @@ class Thor @non_assigned_required.delete(hash_options[key]) end - @shorts, @switches, @extra = {}, {}, [] + @shorts, @switches, @unknown = {}, {}, [] options.each do |option| @switches[option.switch_name] = option @@ -49,19 +49,14 @@ class Thor end end - def remaining - @extra - end - def parse(args) @pile = args.dup while peek match, is_switch = current_is_switch? - shifted = shift if is_switch - case shifted + case shift when SHORT_SQ_RE unshift($1.split('').map { |f| "-#{f}" }) next @@ -76,10 +71,9 @@ class Thor option = switch_option(switch) @assigns[option.human_name] = parse_peek(switch, option) elsif match - @extra << shifted - @extra << shift while peek && peek !~ /^-/ + @unknown << shift else - @extra << shifted + shift end end @@ -91,9 +85,9 @@ class Thor end def check_unknown! - # an unknown option starts with - or -- and has no more --'s afterward. - unknown = @extra.select { |str| str =~ /^--?(?:(?!--).)*$/ } - raise UnknownArgumentError, "Unknown switches '#{unknown.join(', ')}'" unless unknown.empty? + unless ARGV.include?("exec") || ARGV.include?("config") + raise UnknownArgumentError, "Unknown switches '#{@unknown.join(', ')}'" unless @unknown.empty? + end end protected diff --git a/lib/bundler/vendor/thor/rake_compat.rb b/lib/bundler/vendor/thor/rake_compat.rb index c86e8405..0d0757fd 100644 --- a/lib/bundler/vendor/thor/rake_compat.rb +++ b/lib/bundler/vendor/thor/rake_compat.rb @@ -1,5 +1,4 @@ require 'rake' -require 'rake/dsl_definition' class Thor # Adds a compatibility layer to your Thor classes which allows you to use @@ -17,8 +16,6 @@ class Thor # end # module RakeCompat - include Rake::DSL if defined?(Rake::DSL) - def self.rake_classes @rake_classes ||= [] end @@ -32,12 +29,12 @@ class Thor end end -# override task on (main), for compatibility with Rake 0.9 -self.instance_eval do - alias rake_namespace namespace +class Object #:nodoc: + alias :rake_task :task + alias :rake_namespace :namespace - def task(*) - task = super + def task(*args, &block) + task = rake_task(*args, &block) if klass = Thor::RakeCompat.rake_classes.last non_namespaced_name = task.name.split(':').last @@ -46,8 +43,7 @@ self.instance_eval do description << task.arg_names.map{ |n| n.to_s.upcase }.join(' ') description.strip! - klass.desc description, Rake.application.last_description || non_namespaced_name - Rake.application.last_description = nil + klass.desc description, task.comment || non_namespaced_name klass.send :define_method, non_namespaced_name do |*args| Rake::Task[task.name.to_sym].invoke(*args) end @@ -56,7 +52,7 @@ self.instance_eval do task end - def namespace(name) + def namespace(name, &block) if klass = Thor::RakeCompat.rake_classes.last const_name = Thor::Util.camel_case(name.to_s).to_sym klass.const_set(const_name, Class.new(Thor)) @@ -64,8 +60,7 @@ self.instance_eval do Thor::RakeCompat.rake_classes << new_klass end - super + rake_namespace(name, &block) Thor::RakeCompat.rake_classes.pop end end - diff --git a/lib/bundler/vendor/thor/runner.rb b/lib/bundler/vendor/thor/runner.rb index 18c63c43..0d9e3c05 100644 --- a/lib/bundler/vendor/thor/runner.rb +++ b/lib/bundler/vendor/thor/runner.rb @@ -17,7 +17,6 @@ class Thor::Runner < Thor #:nodoc: if meth && !self.respond_to?(meth) initialize_thorfiles(meth) klass, task = Thor::Util.find_class_and_task_by_namespace(meth) - self.class.handle_no_task_error(task, false) if klass.nil? klass.start(["-h", task].compact, :shell => self.shell) else super @@ -31,7 +30,6 @@ class Thor::Runner < Thor #:nodoc: meth = meth.to_s initialize_thorfiles(meth) klass, task = Thor::Util.find_class_and_task_by_namespace(meth) - self.class.handle_no_task_error(task, false) if klass.nil? args.unshift(task) if task klass.start(args, :shell => self.shell) end diff --git a/lib/bundler/vendor/thor/shell.rb b/lib/bundler/vendor/thor/shell.rb index 784fde95..b52c9da2 100644 --- a/lib/bundler/vendor/thor/shell.rb +++ b/lib/bundler/vendor/thor/shell.rb @@ -8,7 +8,7 @@ class Thor def self.shell @shell ||= if ENV['THOR_SHELL'] && ENV['THOR_SHELL'].size > 0 Thor::Shell.const_get(ENV['THOR_SHELL']) - elsif ((RbConfig::CONFIG['host_os'] =~ /mswin|mingw/) && !(ENV['ANSICON'])) + elsif RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ Thor::Shell::Basic else Thor::Shell::Color diff --git a/lib/bundler/vendor/thor/shell/basic.rb b/lib/bundler/vendor/thor/shell/basic.rb index a7c464ad..c8411d3d 100644 --- a/lib/bundler/vendor/thor/shell/basic.rb +++ b/lib/bundler/vendor/thor/shell/basic.rb @@ -5,10 +5,10 @@ class Thor class Basic attr_accessor :base, :padding - # Initialize base, mute and padding to nil. + # Initialize base and padding to nil. # def initialize #:nodoc: - @base, @mute, @padding = nil, false, 0 + @base, @padding = nil, 0 end # Mute everything that's inside given block diff --git a/lib/bundler/vendor/thor/task.rb b/lib/bundler/vendor/thor/task.rb index f94d5b6b..6db3b608 100644 --- a/lib/bundler/vendor/thor/task.rb +++ b/lib/bundler/vendor/thor/task.rb @@ -18,15 +18,8 @@ class Thor # By default, a task invokes a method in the thor class. You can change this # implementation to create custom tasks. def run(instance, args=[]) - if private_method?(instance) - instance.class.handle_no_task_error(name) - elsif public_method?(instance) - instance.send(name, *args) - elsif local_method?(instance, :method_missing) - instance.send(:method_missing, name.to_sym, *args) - else - instance.class.handle_no_task_error(name) - end + public_method?(instance) ? + instance.send(name, *args) : instance.class.handle_no_task_error(name) rescue ArgumentError => e handle_argument_error?(instance, e, caller) ? instance.class.handle_argument_error(self, e) : (raise e) @@ -77,15 +70,6 @@ class Thor !(instance.public_methods & [name.to_s, name.to_sym]).empty? end - def private_method?(instance) - !(instance.private_methods & [name.to_s, name.to_sym]).empty? - end - - def local_method?(instance, name) - methods = instance.public_methods(false) + instance.private_methods(false) + instance.protected_methods(false) - !(methods & [name.to_s, name.to_sym]).empty? - end - def sans_backtrace(backtrace, caller) #:nodoc: saned = backtrace.reject { |frame| frame =~ FILE_REGEXP } saned -= caller diff --git a/lib/bundler/vendor/thor/version.rb b/lib/bundler/vendor/thor/version.rb index 4a0e37ad..7de92f16 100644 --- a/lib/bundler/vendor/thor/version.rb +++ b/lib/bundler/vendor/thor/version.rb @@ -1,3 +1,3 @@ class Thor - VERSION = "0.15.0.rc2".freeze + VERSION = "0.14.6".freeze end |