From: Jim Morris Date: 2008-07-04T02:22:39+09:00 Subject: Re: Lost with OptionParser I love Main, but it does not seem to work under JRuby, any ideas? This is the error I always get... F, [2008-07-03T10:24:48.827600 #9761] FATAL -- : could not reopen: null (IOError) /opt/jruby-1.1.2/lib/ruby/gems/1.8/gems/main-2.8.0/lib/main/base.rb:318:in `setup_io_restoration' /opt/jruby-1.1.2/lib/ruby/gems/1.8/gems/main-2.8.0/lib/main/base.rb:318:in `call' /opt/jruby-1.1.2/lib/ruby/gems/1.8/gems/main-2.8.0/lib/main/base.rb:318:in `finalize' /opt/jruby-1.1.2/lib/ruby/gems/1.8/gems/main-2.8.0/lib/main/base.rb:29:in `run' /opt/jruby-1.1.2/lib/ruby/gems/1.8/gems/main-2.8.0/lib/main/base.rb:12:in `catch' /opt/jruby-1.1.2/lib/ruby/gems/1.8/gems/main-2.8.0/lib/main/base.rb:12:in `run' /opt/jruby-1.1.2/lib/ruby/gems/1.8/gems/main-2.8.0/lib/main/factories.rb:11:in `run' /opt/jruby-1.1.2/lib/ruby/gems/1.8/gems/main-2.8.0/lib/main/factories.rb:16:in `Main' ara.t.howard wrote: > > cfp:~ > cat a.rb > require 'yaml' > require 'rubygems' ### gem install rubygems > require 'main' > > Main { > option('environment', 'e'){ > synopsis 'specify run time environment' > default 'development' > argument :required > validate{|arg| %w[ production development test ].include? arg} > } > > def run > environment = params['environment'] > > y :given => environment.given?, > :value => environment.value > end > } > > > > cfp:~ > ruby a.rb > --- > :value: development > :given: > > > cfp:~ > ruby a.rb --environment=foobar > invalid: option(--environment)="foobar" > > cfp:~ > ruby a.rb --environment=test > --- > :value: test > :given: true > > > > cfp:~ > ruby a.rb --help > NAME > a.rb > > SYNOPSIS > a.rb [options]+ > > DESCRIPTION > main.rb takes the pain of argument parsing away > > PARAMETERS > specify run time environment > --help, -h > > > > the packages ships with a tons of examples. > > a @ http://codeforpeople.com/ > -- > we can deny everything, except that we have the possibility of being > better. simply reflect on that. > h.h. the 14th dalai lama > > > > > -- Jim Morris, http://blog.wolfman.com