summaryrefslogtreecommitdiff
path: root/lib/bundler/vendor
diff options
context:
space:
mode:
authorAndre Arko <andre@arko.net>2010-05-23 10:55:19 -0700
committerAndre Arko <andre@arko.net>2010-05-23 11:34:47 -0700
commit3f1f9ad447cee0f305cb456afa62268630bdaff5 (patch)
treecd8d66367036e72277b9dc1f35f8be574e84c22f /lib/bundler/vendor
parent7ef704d19604f1b60b482badc3a4fb6ef2e32488 (diff)
downloadbundler-3f1f9ad447cee0f305cb456afa62268630bdaff5.tar.gz
Update bundled Thor, adding long_desc for tasks
Diffstat (limited to 'lib/bundler/vendor')
-rw-r--r--lib/bundler/vendor/thor.rb25
-rw-r--r--lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb2
-rw-r--r--lib/bundler/vendor/thor/invocation.rb2
-rw-r--r--lib/bundler/vendor/thor/parser/arguments.rb17
-rw-r--r--lib/bundler/vendor/thor/parser/options.rb5
-rw-r--r--lib/bundler/vendor/thor/shell/basic.rb28
-rw-r--r--lib/bundler/vendor/thor/task.rb12
-rw-r--r--lib/bundler/vendor/thor/util.rb27
-rw-r--r--lib/bundler/vendor/thor/version.rb2
9 files changed, 86 insertions, 34 deletions
diff --git a/lib/bundler/vendor/thor.rb b/lib/bundler/vendor/thor.rb
index df6ea7bf35..a9ba7dfdd8 100644
--- a/lib/bundler/vendor/thor.rb
+++ b/lib/bundler/vendor/thor.rb
@@ -35,6 +35,20 @@ class Thor
end
end
+ # Defines the long description of the next task.
+ #
+ # ==== Parameters
+ # long description<String>
+ #
+ def long_desc(long_description, options={})
+ if options[:for]
+ task = find_and_refresh_task(options[:for])
+ task.long_description = long_description if long_description
+ else
+ @long_desc = long_description
+ end
+ end
+
# Maps an input to a task. If you define:
#
# map "-T" => "list"
@@ -153,7 +167,12 @@ class Thor
shell.say " #{banner(task)}"
shell.say
class_options_help(shell, nil => task.options.map { |_, o| o })
- shell.say task.description
+ if task.long_description
+ shell.say "Description:"
+ shell.print_wrapped(task.long_description, :ident => 2)
+ else
+ shell.say task.description
+ end
end
# Prints help information for this class.
@@ -205,8 +224,8 @@ class Thor
def create_task(meth) #:nodoc:
if @usage && @desc
- tasks[meth.to_s] = Thor::Task.new(meth, @desc, @usage, method_options)
- @usage, @desc, @method_options = nil
+ tasks[meth.to_s] = Thor::Task.new(meth, @desc, @long_desc, @usage, method_options)
+ @usage, @desc, @long_desc, @method_options = nil
true
elsif self.all_tasks[meth.to_s] || meth.to_sym == :method_missing
true
diff --git a/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb b/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb
index 40d201d9e4..78bc5cf4bf 100644
--- a/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb
+++ b/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb
@@ -65,7 +65,7 @@ class Thor
else
self[$1] == args.first
end
- else
+ else
self[method]
end
end
diff --git a/lib/bundler/vendor/thor/invocation.rb b/lib/bundler/vendor/thor/invocation.rb
index 6fa1d6d3ec..4a081839ff 100644
--- a/lib/bundler/vendor/thor/invocation.rb
+++ b/lib/bundler/vendor/thor/invocation.rb
@@ -11,7 +11,7 @@ class Thor
def prepare_for_invocation(key, name) #:nodoc:
case name
when Symbol, String
- Thor::Util.find_class_and_task_by_namespace(name.to_s)
+ Thor::Util.find_class_and_task_by_namespace(name.to_s, !key)
else
name
end
diff --git a/lib/bundler/vendor/thor/parser/arguments.rb b/lib/bundler/vendor/thor/parser/arguments.rb
index 15791ae95b..07850836c4 100644
--- a/lib/bundler/vendor/thor/parser/arguments.rb
+++ b/lib/bundler/vendor/thor/parser/arguments.rb
@@ -51,6 +51,11 @@ class Thor
private
+ def no_or_skip?(arg)
+ arg =~ /^--(no|skip)-([-\w]+)$/
+ $2
+ end
+
def last?
@pile.empty?
end
@@ -114,7 +119,7 @@ class Thor
array
end
- # Check if the peel is numeric ofrmat and return a Float or Integer.
+ # Check if the peek is numeric format and return a Float or Integer.
# Otherwise raises an error.
#
def parse_numeric(name)
@@ -127,10 +132,16 @@ class Thor
$&.index('.') ? shift.to_f : shift.to_i
end
- # Parse string, i.e., just return the current value in the pile.
+ # Parse string:
+ # for --string-arg, just return the current value in the pile
+ # for --no-string-arg, nil
#
def parse_string(name)
- shift
+ if no_or_skip?(name)
+ nil
+ else
+ shift
+ end
end
# Raises an error if @non_assigned_required array is not empty.
diff --git a/lib/bundler/vendor/thor/parser/options.rb b/lib/bundler/vendor/thor/parser/options.rb
index 199fc44211..dda23f9ea1 100644
--- a/lib/bundler/vendor/thor/parser/options.rb
+++ b/lib/bundler/vendor/thor/parser/options.rb
@@ -124,11 +124,6 @@ class Thor
end
end
- def no_or_skip?(arg)
- arg =~ /^--(no|skip)-([-\w]+)$/
- $2
- end
-
# Check if the given argument is actually a shortcut.
#
def normalize_switch(arg)
diff --git a/lib/bundler/vendor/thor/shell/basic.rb b/lib/bundler/vendor/thor/shell/basic.rb
index 828ea4f51d..2cf4d5309e 100644
--- a/lib/bundler/vendor/thor/shell/basic.rb
+++ b/lib/bundler/vendor/thor/shell/basic.rb
@@ -109,6 +109,34 @@ class Thor
end
end
+ # Prints a long string, word-wrapping the text to the current width of the
+ # terminal display. Ideal for printing heredocs.
+ #
+ # ==== Parameters
+ # String
+ #
+ # ==== Options
+ # ident<Integer>:: Indent each line of the printed paragraph by ident value.
+ #
+ def print_wrapped(message, options={})
+ ident = options[:ident] || 0
+ width = terminal_width - ident
+ 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")}
+ end
+
+ paras.each do |para|
+ para.split("\n").each do |line|
+ $stdout.puts line.insert(0, " " * ident)
+ end
+ $stdout.puts unless para == paras.last
+ end
+ end
+
# Deals with file collision and returns true if the file should be
# overwriten and false otherwise. If a block is given, it uses the block
# response as the content for the diff.
diff --git a/lib/bundler/vendor/thor/task.rb b/lib/bundler/vendor/thor/task.rb
index 856ef16a22..ebb2d5a556 100644
--- a/lib/bundler/vendor/thor/task.rb
+++ b/lib/bundler/vendor/thor/task.rb
@@ -1,11 +1,11 @@
class Thor
- class Task < Struct.new(:name, :description, :usage, :options)
+ class Task < Struct.new(:name, :description, :long_description, :usage, :options)
FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/
# A dynamic task that handles method missing scenarios.
class Dynamic < Task
def initialize(name, options=nil)
- super(name.to_s, "A dynamically-generated task", name.to_s, options)
+ super(name.to_s, "A dynamically-generated task", name.to_s, name.to_s, options)
end
def run(instance, args=[])
@@ -17,8 +17,8 @@ class Thor
end
end
- def initialize(name, description, usage, options=nil)
- super(name.to_s, description, usage, options || {})
+ def initialize(name, description, long_description, usage, options=nil)
+ super(name.to_s, description, long_description, usage, options || {})
end
def initialize_copy(other) #:nodoc:
@@ -39,7 +39,7 @@ class Thor
instance.class.handle_no_task_error(name) : (raise e)
end
- # Returns the formatted usage by injecting given required arguments
+ # Returns the formatted usage by injecting given required arguments
# and required options into the given usage.
def formatted_usage(klass, namespace=true)
namespace = klass.namespace unless namespace == false
@@ -99,4 +99,4 @@ class Thor
end
end
-end
+end \ No newline at end of file
diff --git a/lib/bundler/vendor/thor/util.rb b/lib/bundler/vendor/thor/util.rb
index d2c6a150c8..690d74076b 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
diff --git a/lib/bundler/vendor/thor/version.rb b/lib/bundler/vendor/thor/version.rb
index 6ebaa3f6ea..5bd0788897 100644
--- a/lib/bundler/vendor/thor/version.rb
+++ b/lib/bundler/vendor/thor/version.rb
@@ -1,3 +1,3 @@
class Thor
- VERSION = "0.13.4".freeze
+ VERSION = "0.13.6".freeze
end