builder/extra/cluster-home/lib/ruby/tungsten/util.rb
# Run the OptionParser object against @remaining_arguments or the 
# {arguments} passed in. If no {arguments} value is given, the function
# will read from @remaining_arguments and update it with any remaining
# values
Run the OptionParser object against @remaining_arguments or the
{arguments} passed in. If no {arguments} value is given, the function
will read from @remaining_arguments and update it with any remaining
values
Run the OptionParser object against @remaining_arguments or the { arguments } passed in . If no { arguments } value is given the function will read from @remaining_arguments and update it with any remaining values
def run_option_parser(opts, arguments = nil, allow_invalid_options = true, invalid_option_prefix = nil)
    if arguments == nil
      use_remaining_arguments = true
      arguments = @remaining_arguments
    else
      use_remaining_arguments = false
    end
    option_lists = opts.stack()
    option_lists.shift()
    option_lists.shift()
    option_lists.each{
      |ol|
      ol.short.keys().each{
        |arg|
        if @previous_option_arguments.has_key?(arg)
          error("The -#{arg} argument has already been captured")
        end
        @previous_option_arguments[arg] = true
      }
      ol.long.keys().each{
        |arg|
        if @previous_option_arguments.has_key?(arg)
          error("The --#{arg} argument has already been captured")
        end
        @previous_option_arguments[arg] = true
      }
    }
    remainder = []
    while arguments.size() > 0
      begin
        arguments = opts.order!(arguments)
        if arguments.size() > 0 && (arguments[0] =~ /-.*/) != 0
          remainder << arguments.shift()
        end
      rescue OptionParser::InvalidOption => io
        if allow_invalid_options
          remainder = remainder + io.recover([])
          if arguments.size() > 0 && (arguments[0] =~ /-.*/) != 0
            remainder << arguments.shift()
          end
        else
          if invalid_option_prefix != nil
            io.reason = invalid_option_prefix
          end
          raise io
        end
      rescue => e
        exception(e)
        raise "Argument parsing failed: #{e.to_s()}"
      end
    end
    if use_remaining_arguments == true
      @remaining_arguments = remainder
      return nil
    else
      return remainder
    end
  end
def run_option_parser ( opts , arguments = nil , allow_invalid_options = true , invalid_option_prefix = nil ) if arguments == nil use_remaining_arguments = true arguments = @remaining_arguments else use_remaining_arguments = false end option_lists = opts . stack ( ) option_lists . shift ( ) option_lists . shift ( ) option_lists . each { | ol | ol . short . keys ( ) . each { | arg | if @previous_option_arguments . has_key? ( arg ) error ( "The -#{arg} argument has already been captured" ) end @previous_option_arguments [ arg ] = true } ol . long . keys ( ) . each { | arg | if @previous_option_arguments . has_key? ( arg ) error ( "The --#{arg} argument has already been captured" ) end @previous_option_arguments [ arg ] = true } } remainder = [ ] while arguments . size ( ) > 0 begin arguments = opts . order! ( arguments ) if arguments . size ( ) > 0 && ( arguments [ 0 ] =~ / -.* / ) != 0 remainder << arguments . shift ( ) end rescue OptionParser :: InvalidOption => io if allow_invalid_options remainder = remainder + io . recover ( [ ] ) if arguments . size ( ) > 0 && ( arguments [ 0 ] =~ / -.* / ) != 0 remainder << arguments . shift ( ) end else if invalid_option_prefix != nil io . reason = invalid_option_prefix end raise io end rescue => e exception ( e ) raise "Argument parsing failed: #{e.to_s()}" end end if use_remaining_arguments == true @remaining_arguments = remainder return nil else return remainder end end
Run the OptionParser object against @remaining_arguments or the
{arguments} passed in.
Run the OptionParser object against @remaining_arguments or the { arguments } passed in .
# Collect the list of options and remove the first two that are  # created by default # The next argument does not have a dash so the OptionParser # ignores it, we will add it to the stack and continue # Prepend the invalid option onto the arguments array # The next argument does not have a dash so the OptionParser # ignores it, we will add it to the stack and continue
opts
arguments
allow_invalid_options
invalid_option_prefix