You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🌈 (Not sure if that's needed for issues, but whatever)
Hey, All.
I was giving Thor a test run, and noticed that options that are not specified for a method are included in the parameters passed to it.
Version deets:
Ruby: 2.6.0
Thor: 1.0.1
Here's a basic file that will cause the issue (com_test.rb):
require 'thor'
class CLI < Thor
def self.exit_on_failure?
true
end
desc "hello NAME", "say hello to NAME"
option :to, :type => :string
def hello(*params)
puts params.to_s
puts options
end
end
CLI.start(ARGV)
Results:
$ ruby com_test.rb hello one two three
["one", "two", "three"]
{}
$ ruby com_test.rb hello --to you
[]
{"to"=>"you"}
Here's where things get weird.
$ ruby com_test.rb hello --to you --from me
["--from", "me"]
{"to"=>"you"}
What is the reasoning behind this behavior, as opposed to silently ignoring the extra option or throwing an exception?
I took a glance through the docs for anything regarding a situation like this, but came up empty-handed. Apologies if this is clearly spelled out somewhere in there.
Thanks!
The text was updated successfully, but these errors were encountered:
I believe this only works when you have def hello(*params). It won't work when you have def hello. With *params you're effectively saying "Send any additional input to the method for this command. I want to use them for something.". Given that, it's a bit strange to wonder why the framework is doing what you're telling it to do.
🌈 (Not sure if that's needed for issues, but whatever)
Hey, All.
I was giving Thor a test run, and noticed that options that are not specified for a method are included in the parameters passed to it.
Version deets:
Here's a basic file that will cause the issue (com_test.rb):
Results:
Here's where things get weird.
What is the reasoning behind this behavior, as opposed to silently ignoring the extra option or throwing an exception?
I took a glance through the docs for anything regarding a situation like this, but came up empty-handed. Apologies if this is clearly spelled out somewhere in there.
Thanks!
The text was updated successfully, but these errors were encountered: