Skip to content

Commit

Permalink
Thor should not steal ARGV.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Feb 16, 2010
1 parent dca8f99 commit 636e496
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion lib/thor/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions lib/thor/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit 636e496

Please sign in to comment.