lib/yargs.rb
def option(*aliases)
    result = nil
    aliases_pattern = "(?:#{aliases.join('|')})"

    @remaining.dup.each_with_index do |arg, index|
      if /^(?:-{1,2})#{aliases_pattern}(=|\z)(.*)/ === arg
        if !$1.empty?
          @remaining.delete_at(index)
          result = $2
        elsif (index + 1) < @remaining.length
          val =  @remaining[index + 1]
          @remaining.delete_at(index + 1)
          @remaining.delete_at(index)
          result = val
        end
      end
    end

    if block_given? && result
      yield result
    else
      return result
    end
  end
# Returns or yields the value provided for the option with the given aliases.
# Returns an empty string (indicating a provided option with no value) if
#   - The option is provided with an equal sign but no value: `--value=`
# Returns nil (indicating that the option wasn't provided, or looked like a flag) if
#   - The options simply isn't present in the argv
#   - There is no following argument:
#        yargs = Yargs.new(%w[--last-arg])
#        yargs.value('last-arg') #=> nil
#        yargs.flag('last-arg') #=> true
# Returns the provided value in all other cases.
Returns or yields the value provided for the option with the given aliases.
Returns or yields the value provided for the option with the given aliases .
def option(*aliases)
    result = nil
    aliases_pattern = "(?:#{aliases.join('|')})"
    @remaining.dup.each_with_index do |arg, index|
      if /^(?:-{1,2})#{aliases_pattern}(=|\z)(.*)/ === arg
        if !$1.empty?
          @remaining.delete_at(index)
          result = $2
        elsif (index + 1) < @remaining.length
          val =  @remaining[index + 1]
          @remaining.delete_at(index + 1)
          @remaining.delete_at(index)
          result = val
        end
      end
    end
    if block_given? && result
      yield result
    else
      return result
    end
  end
def option ( * aliases ) result = nil aliases_pattern = "(?:#{aliases.join('|')})" @remaining . dup . each_with_index do | arg , index | if / ^(?:-{1,2}) #{ aliases_pattern } (=| \z )(.*) / === arg if ! $1 . empty? @remaining . delete_at ( index ) result = $2 elsif ( index + 1 ) < @remaining . length val = @remaining [ index + 1 ] @remaining . delete_at ( index + 1 ) @remaining . delete_at ( index ) result = val end end end if block_given? && result yield result else return result end end
Returns or yields the value provided for the option with the given aliases.
Returns or yields the value provided for the option with the given aliases .
aliases