Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Thor should not steal ARGV.

  • Loading branch information...
commit 636e4965d785b15f4e4877cd33bc208c9a75b8b8 1 parent dca8f99
@josevalim josevalim authored
View
4 lib/thor.rb
@@ -120,8 +120,8 @@ def method_option(name, options={})
# script = MyScript.new(args, options, config)
# script.invoke(:task, first_arg, second_arg, third_arg)
#
- def start(given_args=ARGV, config={})
- super do
+ def start(original_args=ARGV, config={})
+ super do |given_args|
meth = normalize_task_name(given_args.shift)
task = all_tasks[meth]
View
2  lib/thor/base.rb
@@ -375,7 +375,7 @@ def namespace(name=nil)
def start(given_args=ARGV, config={})
self.debugging = given_args.include?("--debug")
config[:shell] ||= Thor::Base.shell.new
- yield
+ yield(given_args.dup)
rescue Thor::Error => e
debugging ? (raise e) : config[:shell].error(e.message)
exit(1) if exit_on_failure?
View
4 lib/thor/group.rb
@@ -25,8 +25,8 @@ def desc(description=nil)
# Start works differently in Thor::Group, it simply invokes all tasks
# inside the class.
#
- def start(given_args=ARGV, config={})
- super do
+ def start(original_args=ARGV, config={})
+ super do |given_args|
if Thor::HELP_MAPPINGS.include?(given_args.first)
help(config[:shell])
return
View
6 spec/base_spec.rb
@@ -233,6 +233,12 @@ def hello
}.must raise_error(Thor::UndefinedTaskError, 'Could not find task "what" in "my_script" namespace.')
end
+ it "does not steal args" do
+ args = ["foo", "bar", "--force", "true"]
+ MyScript.start(args)
+ args.must == ["foo", "bar", "--force", "true"]
+ end
+
it "checks unknown options" do
capture(:stderr) {
MyScript.start(["foo", "bar", "--force", "true", "--unknown", "baz"])
Please sign in to comment.
Something went wrong with that request. Please try again.