aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bundler/vendor/thor/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler/vendor/thor/base.rb')
-rw-r--r--lib/bundler/vendor/thor/base.rb36
1 files changed, 26 insertions, 10 deletions
diff --git a/lib/bundler/vendor/thor/base.rb b/lib/bundler/vendor/thor/base.rb
index 9798cb7e..6412ace6 100644
--- a/lib/bundler/vendor/thor/base.rb
+++ b/lib/bundler/vendor/thor/base.rb
@@ -53,7 +53,7 @@ class Thor
opts = Thor::Options.new(parse_options, hash_options)
self.options = opts.parse(array_options)
- opts.check_unknown! if self.class.check_unknown_options?
+ opts.check_unknown! if self.class.check_unknown_options?(config)
end
class << self
@@ -114,8 +114,12 @@ class Thor
@check_unknown_options = true
end
- def check_unknown_options? #:nodoc:
- @check_unknown_options || false
+ def check_unknown_options #:nodoc:
+ @check_unknown_options ||= from_superclass(:check_unknown_options, false)
+ end
+
+ def check_unknown_options?(config) #:nodoc:
+ !!check_unknown_options
end
# Adds an argument to the class and creates an attr_accessor for it.
@@ -364,19 +368,25 @@ class Thor
#
def namespace(name=nil)
case name
- when nil
- @namespace ||= Thor::Util.namespace_from_thor_class(self)
- else
- @namespace = name.to_s
+ when nil
+ @namespace ||= Thor::Util.namespace_from_thor_class(self)
+ else
+ @namespace = name.to_s
end
end
- # Default way to start generators from the command line.
+ # Parses the task and options from the given args, instantiate the class
+ # and invoke the task. This method is used when the arguments must be parsed
+ # from an array. If you are inside Ruby and want to use a Thor class, you
+ # can simply initialize it:
+ #
+ # script = MyScript.new(args, options, config)
+ # script.invoke(:task, first_arg, second_arg, third_arg)
#
def start(given_args=ARGV, config={})
- self.debugging = given_args.include?("--debug")
+ self.debugging = given_args.delete("--debug")
config[:shell] ||= Thor::Base.shell.new
- yield(given_args.dup)
+ dispatch(nil, given_args.dup, nil, config)
rescue Thor::Error => e
debugging ? (raise e) : config[:shell].error(e.message)
exit(1) if exit_on_failure?
@@ -535,6 +545,12 @@ class Thor
# class.
def initialize_added #:nodoc:
end
+
+ # SIGNATURE: The hook invoked by start.
+ def dispatch(task, given_args, given_opts, config) #:nodoc:
+ raise NotImplementedError
+ end
+
end
end
end