On May 30, 2006, at 12:29 PM, Michael Keller wrote:

> Hi tony,
>
> if I use order!() instead of parse!() then it works the way I need
>
> I took a look in optparse.rb (that's why i love open source :-) :
>
>  def parse!(argv = ARGV)
>     if ENV.include?('POSIXLY_CORRECT')
>       order!(argv)
>     else
>       permute!(argv)
>     end
>   end
>
> and POSIXLY_CORRECT' is not set on my system...
>
>
>
> Thanks for your help.
>
>   Michael
>

And here's how I did it, not bothering to look at the source

( warning: Excessive sillyness follows)

% cat oparse.rb
args = ARGV.dup
cc = callcc { |x| x }
begin
   old_verbose = $VERBOSE
   $VERBOSE = nil
   require 'optparse'
ensure
   $VERBOSE = old_verbose
end


ARGV.options do |opts|
   opts.separator  "Required:"
   opts.on("-f", "--ffmpeg PATH", String, "ffmpeg's path") { |val|  
ffmpeg = val }
end

begin
leftOver = ARGV.parse!
rescue OptionParser::InvalidOption => ex
i = nil
args.each_with_index do |v, idx|
    if v == ex.args.first
      i = idx
      break
    end
end

args.insert(i, "--")
begin
    old_verbose = $VERBOSE
    $VERBOSE = nil
    ARGV = args
ensure
    $VERBOSE = old_verbose
end
$LOADED_FEATURES.delete('optparse.rb')
cc.call
end

p leftOver

% ruby oparse.rb
["Tool/to/call/from/example.rb", "--toolsOption", "value"]