Skip to content

Extra options become parameters #725

Open
@zrewald

Description

🌈 (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!

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions