Hi Gunnar, On Fri, Jun 15, 2012 at 06:26:43PM -0500, Gunnar Wolf wrote: > Hi, > CommandLine::Application has a very nice API and used to work quite > fine for me, but it is not 1.9.1-compatible (it even fails to fail - > #676125, #676248). The last release was in 2005, and it does not exist > in Gem form (which means, it's very unlikely Ruby people care about it > at all). > Now, the question: Should we drop this package? Or should we build it > for 1.8 only? Of course, keeping it runnable under 1.9.1 is just not a > good idea (as it silently fails). > I don't think there is much value in keeping an equivalent option > parser given there is a functionally equivalent version in the > stdlib... but before filing for removal, I'd like your input. I investigated a few days ago this problem, and found at least why it silently fails with Ruby1.9: with Ruby 1.9, private_instance_methods returns a list of symbols, not a list of strings, so the machinery to initialize the application in lib/commandline/application.rb fails. I had two patches (attached) to go just a little further. But I still got errors. I am afraid I may not have time to look deeper into this defore a couple of days, but I hope it can help —at least, now commandline succeeds in failing with Ruby 1.9 ;). Best, Cédric
--- a/lib/commandline/optionparser/option.rb +++ b/lib/commandline/optionparser/option.rb @@ -180,6 +180,10 @@ Marshal.load(Marshal.dump(@properties)) end + def to_ary + nil + end + end#class Option end#module CommandLine
--- a/lib/commandline/application.rb +++ b/lib/commandline/application.rb @@ -50,9 +50,9 @@ __initialize_text_formatting # Call the child usurped initialize - __child_initialize if - self.class.private_instance_methods(false).include?("__child_initialize") + __child_initialize if + self.class.private_instance_methods(false).map{|m| m.to_s}.include?("__child_initialize") @option_parser ||= CommandLine::OptionParser.new(@options) end @@ -238,7 +238,7 @@ def self.run(argv=ARGV) # Usurp an existing initialize so ours can be called first. # We rename it __child_initialize and call it from initialize. - if self.private_instance_methods(false).include?("initialize") + if self.private_instance_methods(false).map{|m| m.to_s }.include?("initialize") $VERBOSE, verbose = nil, $VERBOSE self.class_eval { alias :__child_initialize :initialize @@ -259,7 +259,8 @@ end def self.inherited(child_class) - @@appname = caller[0][/.*:/][0..-2] + #@@appname = caller[0][/.*:/][0..-2] + @@appname = caller[0].sub(/:\d+(:in `<.*>')?\Z/, "") @@child_class = child_class if @@appname == $0 __set_auto_run @@ -273,6 +274,7 @@ def main #raise(MissingMainError, "Method #main must be defined in class #{@@child_class}.") @@child_class.class_eval %{ def main; end } + #self.class_eval %{ def main; end } end @@ -416,7 +419,8 @@ Application_wo_AutoRun = Class.new(Application) class Application_wo_AutoRun def self.inherited(child_class) - @@appname = caller[0][/.*:/][0..-2] + #@@appname = caller[0][/.*:/][0..-2] + @@appname = caller[0].sub(/:\d+(:in `<.*>')?\Z/, "") @@child_class = child_class end end
Attachment:
signature.asc
Description: Digital signature