# File lib/getoptlong.rb, line 426def getoption_name,option_argument=nil,''## Check status.#returnnilif@error!=nilcase@statuswhenSTATUS_YET@status=STATUS_STARTEDwhenSTATUS_TERMINATEDreturnnilend## Get next option argument.#if0<@rest_singles.lengthargument='-'+@rest_singleselsif(ARGV.length==0)terminatereturnnilelsif@ordering==PERMUTEwhile0<ARGV.length&&ARGV[0]!~/^-./@non_option_arguments.push(ARGV.shift)endifARGV.length==0terminatereturnnilendargument=ARGV.shiftelsif@ordering==REQUIRE_ORDERif(ARGV[0]!~/^-./)terminatereturnnilendargument=ARGV.shiftelseargument=ARGV.shiftend## Check the special argument `--'.# `--' indicates the end of the option list.#ifargument=='--'&&@rest_singles.length==0terminatereturnnilend## Check for long and short options.#ifargument=~/^(--[^=]+)/&&@rest_singles.length==0## This is a long style option, which start with `--'.#pattern=$1if@canonical_names.include?(pattern)option_name=patternelse## The option `option_name' is not registered in `@canonical_names'.# It may be an abbreviated.#matches=[]@canonical_names.each_keydo|key|ifkey.index(pattern)==0option_name=keymatches<<keyendendif2<=matches.lengthset_error(AmbiguousOption,"option `#{argument}' is ambiguous between #{matches.join(', ')}")elsifmatches.length==0set_error(InvalidOption,"unrecognized option `#{argument}'")endend## Check an argument to the option.#if@argument_flags[option_name]==REQUIRED_ARGUMENTifargument=~/=(.*)$/option_argument=$1elsif0<ARGV.lengthoption_argument=ARGV.shiftelseset_error(MissingArgument,"option `#{argument}' requires an argument")endelsif@argument_flags[option_name]==OPTIONAL_ARGUMENTifargument=~/=(.*)$/option_argument=$1elsif0<ARGV.length&&ARGV[0]!~/^-./option_argument=ARGV.shiftelseoption_argument=''endelsifargument=~/=(.*)$/set_error(NeedlessArgument,"option `#{option_name}' doesn't allow an argument")endelsifargument=~/^(-(.))(.*)/## This is a short style option, which start with `-' (not `--').# Short options may be catenated (e.g. `-l -g' is equivalent to# `-lg').#option_name,ch,@rest_singles=$1,$2,$3if@canonical_names.include?(option_name)## The option `option_name' is found in `@canonical_names'.# Check its argument.#if@argument_flags[option_name]==REQUIRED_ARGUMENTif0<@rest_singles.lengthoption_argument=@rest_singles@rest_singles=''elsif0<ARGV.lengthoption_argument=ARGV.shiftelse# 1003.2 specifies the format of this message.set_error(MissingArgument,"option requires an argument -- #{ch}")endelsif@argument_flags[option_name]==OPTIONAL_ARGUMENTif0<@rest_singles.lengthoption_argument=@rest_singles@rest_singles=''elsif0<ARGV.length&&ARGV[0]!~/^-./option_argument=ARGV.shiftelseoption_argument=''endendelse## This is an invalid option.# 1003.2 specifies the format of this message.#ifENV.include?('POSIXLY_CORRECT')set_error(InvalidOption,"invalid option -- #{ch}")elseset_error(InvalidOption,"invalid option -- #{ch}")endendelse## This is a non-option argument.# Only RETURN_IN_ORDER falled into here.#return'',argumentendreturn@canonical_names[option_name],option_argumentend