diff options
Diffstat (limited to 'lib/bundler/vendor/thor/util.rb')
-rw-r--r-- | lib/bundler/vendor/thor/util.rb | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/bundler/vendor/thor/util.rb b/lib/bundler/vendor/thor/util.rb index d2c6a150..690d7407 100644 --- a/lib/bundler/vendor/thor/util.rb +++ b/lib/bundler/vendor/thor/util.rb @@ -128,38 +128,37 @@ class Thor # ==== Parameters # namespace<String> # - def self.find_class_and_task_by_namespace(namespace) - if namespace.include?(?:) + def self.find_class_and_task_by_namespace(namespace, fallback = true) + if namespace.include?(?:) # look for a namespaced task pieces = namespace.split(":") task = pieces.pop klass = Thor::Util.find_by_namespace(pieces.join(":")) end - - unless klass + unless klass # look for a Thor::Group with the right name klass, task = Thor::Util.find_by_namespace(namespace), nil end - - return klass, task - end - - # The same as namespace_to_thor_class_and_task!, but raises an error if a klass - # could not be found. - def self.find_class_and_task_by_namespace!(namespace) - klass, task = find_class_and_task_by_namespace(namespace) - raise Error, "Could not find namespace or task #{namespace.inspect}." unless klass + if !klass && fallback # try a task in the default namespace + task = namespace + klass = Thor::Util.find_by_namespace('') + end return klass, task end # Receives a path and load the thor file in the path. The file is evaluated # inside the sandbox to avoid namespacing conflicts. # - def self.load_thorfile(path, content=nil) + def self.load_thorfile(path, content=nil, debug=false) content ||= File.binread(path) begin Thor::Sandbox.class_eval(content, path) rescue Exception => e $stderr.puts "WARNING: unable to load thorfile #{path.inspect}: #{e.message}" + if debug + $stderr.puts *e.backtrace + else + $stderr.puts e.backtrace.first + end end end |