davetron5000 / gli

Make awesome command-line applications the easy way
http://davetron5000.github.io/gli
Apache License 2.0
1.26k stars 102 forks source link

to_sym error when using "subcommand_option_handling :normal" with ostruct #267

Closed slowbro closed 6 years ago

slowbro commented 6 years ago
$ GLI_DEBUG=true ./gli-test.rb add test
error: undefined method `to_sym' for #<Object:0x000008033eebe8>
Did you mean?  to_s
/home/kschiesser/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/ostruct.rb:96:in `block in initialize': undefined method `to_sym' for #<Object:0x000008033eebe8> (NoMethodError)
Did you mean?  to_s
        from /home/kschiesser/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/ostruct.rb:95:in `each_pair'
        from /home/kschiesser/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/ostruct.rb:95:in `initialize'
        from /home/kschiesser/.rvm/gems/ruby-2.4.1@blah/gems/gli-2.16.0/lib/gli/option_parsing_result.rb:10:in `new'
        from /home/kschiesser/.rvm/gems/ruby-2.4.1@blah/gems/gli-2.16.0/lib/gli/option_parsing_result.rb:10:in `convert_to_openstruct!'
        from /home/kschiesser/.rvm/gems/ruby-2.4.1@blah/gems/gli-2.16.0/lib/gli/app_support.rb:78:in `run'
        from ./gli-test.rb:17:in `<main>'
$ cat gli-test.rb
#!/usr/bin/env ruby

require 'gli'
include GLI::App

subcommand_option_handling :normal
use_openstruct true

command :add do |c|
  c.command :test do |t|
          t.action do |global_options,options,args|
                puts "t"
          end
  end
end

exit run(ARGV)

It seems like GLI is putting in a blank Object (GLI::Command::PARENT) for tracking back but this is not kosher with the conversion to a symbol:

$ pry
[1] pry(main)> Object.new.to_sym
NoMethodError: undefined method `to_sym' for #<Object:0x00000804a4bbe8>
Did you mean?  to_s
from (pry):1:in `__pry__'

Is there some workaround or solution for this? Been scratching my head for a bit now and can't see anything right now.

slowbro commented 6 years ago

The same thing happens with the latest GLI, 2.17.0, as well.

davetron5000 commented 6 years ago

Does it work with out use_openstruct true?

Yeah, it does use a blank object so as not to squash anything, but I admit to not having thought about the openstruct case

slowbro commented 6 years ago

Yes, it works as expected without use_openstruct true

davetron5000 commented 6 years ago

Fixed and released as 2.17.1.

slowbro commented 6 years ago

Thank you very much!