aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bundler/vendor/thor.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler/vendor/thor.rb')
-rw-r--r--lib/bundler/vendor/thor.rb70
1 files changed, 25 insertions, 45 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)