rails / thor

Thor is a toolkit for building powerful command-line interfaces.
http://whatisthor.com/
MIT License
5.13k stars 552 forks source link

Wrong options parsing #659

Closed Yegorov closed 5 years ago

Yegorov commented 5 years ago

When i run this script, some options not parsed correctly, for example:

Script:

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'thor', '= 0.20.3'
end

class ExampleThor < Thor
  include Thor::Actions
  default_command :example

  class_option :cls_opt, default: 'test'

  desc 'example', 'Example command'
  method_option :flag1,
                default: false,
                type: :boolean,
                aliases: '-D'
  method_option :flag2,
                default: false,
                type: :boolean,
                aliases: '-F'
  def example
    say 'Test, test, test!!!', :green
  end
end

ExampleThor.start(ARGV)

How i run it:

# It's ok!
$ ruby ./thor-bug.rb -F -D
Test, test, test!!!

# Error! Why?
$ ruby ./thor-bug.rb -D -F
Could not find command "_F".

# It's ok!
$ ruby ./thor-bug.rb --flag1 --flag2
Test, test, test!!!

# Error! Why?
$ ruby ./thor-bug.rb -D --flag2
Could not find command "__flag2".
snowe2010 commented 5 years ago

-D is marked as a help flag for some reason https://github.com/erikhuda/thor/blob/master/lib/thor/base.rb#L17

Yegorov commented 5 years ago

@snowe2010 ok, thanks, for help me!