Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: optparse.rb
#
[0] Fix | Delete
# optparse.rb - command-line option analysis with the OptionParser class.
[1] Fix | Delete
#
[2] Fix | Delete
# Author:: Nobu Nakada
[3] Fix | Delete
# Documentation:: Nobu Nakada and Gavin Sinclair.
[4] Fix | Delete
#
[5] Fix | Delete
# See OptionParser for documentation.
[6] Fix | Delete
#
[7] Fix | Delete
[8] Fix | Delete
[9] Fix | Delete
# == Developer Documentation (not for RDoc output)
[10] Fix | Delete
#
[11] Fix | Delete
# === Class tree
[12] Fix | Delete
#
[13] Fix | Delete
# - OptionParser:: front end
[14] Fix | Delete
# - OptionParser::Switch:: each switches
[15] Fix | Delete
# - OptionParser::List:: options list
[16] Fix | Delete
# - OptionParser::ParseError:: errors on parsing
[17] Fix | Delete
# - OptionParser::AmbiguousOption
[18] Fix | Delete
# - OptionParser::NeedlessArgument
[19] Fix | Delete
# - OptionParser::MissingArgument
[20] Fix | Delete
# - OptionParser::InvalidOption
[21] Fix | Delete
# - OptionParser::InvalidArgument
[22] Fix | Delete
# - OptionParser::AmbiguousArgument
[23] Fix | Delete
#
[24] Fix | Delete
# === Object relationship diagram
[25] Fix | Delete
#
[26] Fix | Delete
# +--------------+
[27] Fix | Delete
# | OptionParser |<>-----+
[28] Fix | Delete
# +--------------+ | +--------+
[29] Fix | Delete
# | ,-| Switch |
[30] Fix | Delete
# on_head -------->+---------------+ / +--------+
[31] Fix | Delete
# accept/reject -->| List |<|>-
[32] Fix | Delete
# | |<|>- +----------+
[33] Fix | Delete
# on ------------->+---------------+ `-| argument |
[34] Fix | Delete
# : : | class |
[35] Fix | Delete
# +---------------+ |==========|
[36] Fix | Delete
# on_tail -------->| | |pattern |
[37] Fix | Delete
# +---------------+ |----------|
[38] Fix | Delete
# OptionParser.accept ->| DefaultList | |converter |
[39] Fix | Delete
# reject |(shared between| +----------+
[40] Fix | Delete
# | all instances)|
[41] Fix | Delete
# +---------------+
[42] Fix | Delete
#
[43] Fix | Delete
# == OptionParser
[44] Fix | Delete
#
[45] Fix | Delete
# === Introduction
[46] Fix | Delete
#
[47] Fix | Delete
# OptionParser is a class for command-line option analysis. It is much more
[48] Fix | Delete
# advanced, yet also easier to use, than GetoptLong, and is a more Ruby-oriented
[49] Fix | Delete
# solution.
[50] Fix | Delete
#
[51] Fix | Delete
# === Features
[52] Fix | Delete
#
[53] Fix | Delete
# 1. The argument specification and the code to handle it are written in the
[54] Fix | Delete
# same place.
[55] Fix | Delete
# 2. It can output an option summary; you don't need to maintain this string
[56] Fix | Delete
# separately.
[57] Fix | Delete
# 3. Optional and mandatory arguments are specified very gracefully.
[58] Fix | Delete
# 4. Arguments can be automatically converted to a specified class.
[59] Fix | Delete
# 5. Arguments can be restricted to a certain set.
[60] Fix | Delete
#
[61] Fix | Delete
# All of these features are demonstrated in the examples below.
[62] Fix | Delete
#
[63] Fix | Delete
# === Minimal example
[64] Fix | Delete
#
[65] Fix | Delete
# require 'optparse'
[66] Fix | Delete
#
[67] Fix | Delete
# options = {}
[68] Fix | Delete
# OptionParser.new do |opts|
[69] Fix | Delete
# opts.banner = "Usage: example.rb [options]"
[70] Fix | Delete
#
[71] Fix | Delete
# opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
[72] Fix | Delete
# options[:verbose] = v
[73] Fix | Delete
# end
[74] Fix | Delete
# end.parse!
[75] Fix | Delete
#
[76] Fix | Delete
# p options
[77] Fix | Delete
# p ARGV
[78] Fix | Delete
#
[79] Fix | Delete
# === Complete example
[80] Fix | Delete
#
[81] Fix | Delete
# The following example is a complete Ruby program. You can run it and see the
[82] Fix | Delete
# effect of specifying various options. This is probably the best way to learn
[83] Fix | Delete
# the features of +optparse+.
[84] Fix | Delete
#
[85] Fix | Delete
# require 'optparse'
[86] Fix | Delete
# require 'optparse/time'
[87] Fix | Delete
# require 'ostruct'
[88] Fix | Delete
# require 'pp'
[89] Fix | Delete
#
[90] Fix | Delete
# class OptparseExample
[91] Fix | Delete
#
[92] Fix | Delete
# CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
[93] Fix | Delete
# CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
[94] Fix | Delete
#
[95] Fix | Delete
# #
[96] Fix | Delete
# # Return a structure describing the options.
[97] Fix | Delete
# #
[98] Fix | Delete
# def self.parse(args)
[99] Fix | Delete
# # The options specified on the command line will be collected in *options*.
[100] Fix | Delete
# # We set default values here.
[101] Fix | Delete
# options = OpenStruct.new
[102] Fix | Delete
# options.library = []
[103] Fix | Delete
# options.inplace = false
[104] Fix | Delete
# options.encoding = "utf8"
[105] Fix | Delete
# options.transfer_type = :auto
[106] Fix | Delete
# options.verbose = false
[107] Fix | Delete
#
[108] Fix | Delete
# opts = OptionParser.new do |opts|
[109] Fix | Delete
# opts.banner = "Usage: example.rb [options]"
[110] Fix | Delete
#
[111] Fix | Delete
# opts.separator ""
[112] Fix | Delete
# opts.separator "Specific options:"
[113] Fix | Delete
#
[114] Fix | Delete
# # Mandatory argument.
[115] Fix | Delete
# opts.on("-r", "--require LIBRARY",
[116] Fix | Delete
# "Require the LIBRARY before executing your script") do |lib|
[117] Fix | Delete
# options.library << lib
[118] Fix | Delete
# end
[119] Fix | Delete
#
[120] Fix | Delete
# # Optional argument; multi-line description.
[121] Fix | Delete
# opts.on("-i", "--inplace [EXTENSION]",
[122] Fix | Delete
# "Edit ARGV files in place",
[123] Fix | Delete
# " (make backup if EXTENSION supplied)") do |ext|
[124] Fix | Delete
# options.inplace = true
[125] Fix | Delete
# options.extension = ext || ''
[126] Fix | Delete
# options.extension.sub!(/\A\.?(?=.)/, ".") # Ensure extension begins with dot.
[127] Fix | Delete
# end
[128] Fix | Delete
#
[129] Fix | Delete
# # Cast 'delay' argument to a Float.
[130] Fix | Delete
# opts.on("--delay N", Float, "Delay N seconds before executing") do |n|
[131] Fix | Delete
# options.delay = n
[132] Fix | Delete
# end
[133] Fix | Delete
#
[134] Fix | Delete
# # Cast 'time' argument to a Time object.
[135] Fix | Delete
# opts.on("-t", "--time [TIME]", Time, "Begin execution at given time") do |time|
[136] Fix | Delete
# options.time = time
[137] Fix | Delete
# end
[138] Fix | Delete
#
[139] Fix | Delete
# # Cast to octal integer.
[140] Fix | Delete
# opts.on("-F", "--irs [OCTAL]", OptionParser::OctalInteger,
[141] Fix | Delete
# "Specify record separator (default \\0)") do |rs|
[142] Fix | Delete
# options.record_separator = rs
[143] Fix | Delete
# end
[144] Fix | Delete
#
[145] Fix | Delete
# # List of arguments.
[146] Fix | Delete
# opts.on("--list x,y,z", Array, "Example 'list' of arguments") do |list|
[147] Fix | Delete
# options.list = list
[148] Fix | Delete
# end
[149] Fix | Delete
#
[150] Fix | Delete
# # Keyword completion. We are specifying a specific set of arguments (CODES
[151] Fix | Delete
# # and CODE_ALIASES - notice the latter is a Hash), and the user may provide
[152] Fix | Delete
# # the shortest unambiguous text.
[153] Fix | Delete
# code_list = (CODE_ALIASES.keys + CODES).join(',')
[154] Fix | Delete
# opts.on("--code CODE", CODES, CODE_ALIASES, "Select encoding",
[155] Fix | Delete
# " (#{code_list})") do |encoding|
[156] Fix | Delete
# options.encoding = encoding
[157] Fix | Delete
# end
[158] Fix | Delete
#
[159] Fix | Delete
# # Optional argument with keyword completion.
[160] Fix | Delete
# opts.on("--type [TYPE]", [:text, :binary, :auto],
[161] Fix | Delete
# "Select transfer type (text, binary, auto)") do |t|
[162] Fix | Delete
# options.transfer_type = t
[163] Fix | Delete
# end
[164] Fix | Delete
#
[165] Fix | Delete
# # Boolean switch.
[166] Fix | Delete
# opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
[167] Fix | Delete
# options.verbose = v
[168] Fix | Delete
# end
[169] Fix | Delete
#
[170] Fix | Delete
# opts.separator ""
[171] Fix | Delete
# opts.separator "Common options:"
[172] Fix | Delete
#
[173] Fix | Delete
# # No argument, shows at tail. This will print an options summary.
[174] Fix | Delete
# # Try it and see!
[175] Fix | Delete
# opts.on_tail("-h", "--help", "Show this message") do
[176] Fix | Delete
# puts opts
[177] Fix | Delete
# exit
[178] Fix | Delete
# end
[179] Fix | Delete
#
[180] Fix | Delete
# # Another typical switch to print the version.
[181] Fix | Delete
# opts.on_tail("--version", "Show version") do
[182] Fix | Delete
# puts OptionParser::Version.join('.')
[183] Fix | Delete
# exit
[184] Fix | Delete
# end
[185] Fix | Delete
# end
[186] Fix | Delete
#
[187] Fix | Delete
# opts.parse!(args)
[188] Fix | Delete
# options
[189] Fix | Delete
# end # parse()
[190] Fix | Delete
#
[191] Fix | Delete
# end # class OptparseExample
[192] Fix | Delete
#
[193] Fix | Delete
# options = OptparseExample.parse(ARGV)
[194] Fix | Delete
# pp options
[195] Fix | Delete
#
[196] Fix | Delete
# === Further documentation
[197] Fix | Delete
#
[198] Fix | Delete
# The above examples should be enough to learn how to use this class. If you
[199] Fix | Delete
# have any questions, email me (gsinclair@soyabean.com.au) and I will update
[200] Fix | Delete
# this document.
[201] Fix | Delete
#
[202] Fix | Delete
class OptionParser
[203] Fix | Delete
# :stopdoc:
[204] Fix | Delete
RCSID = %w$Id: optparse.rb 22469 2009-02-20 11:43:35Z shyouhei $[1..-1].each {|s| s.freeze}.freeze
[205] Fix | Delete
Version = (RCSID[1].split('.').collect {|s| s.to_i}.extend(Comparable).freeze if RCSID[1])
[206] Fix | Delete
LastModified = (Time.gm(*RCSID[2, 2].join('-').scan(/\d+/).collect {|s| s.to_i}) if RCSID[2])
[207] Fix | Delete
Release = RCSID[2]
[208] Fix | Delete
[209] Fix | Delete
NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
[210] Fix | Delete
RequiredArgument = [REQUIRED_ARGUMENT = :REQUIRED, true].freeze
[211] Fix | Delete
OptionalArgument = [OPTIONAL_ARGUMENT = :OPTIONAL, false].freeze
[212] Fix | Delete
# :startdoc:
[213] Fix | Delete
[214] Fix | Delete
#
[215] Fix | Delete
# Keyword completion module. This allows partial arguments to be specified
[216] Fix | Delete
# and resolved against a list of acceptable values.
[217] Fix | Delete
#
[218] Fix | Delete
module Completion
[219] Fix | Delete
def complete(key, icase = false, pat = nil)
[220] Fix | Delete
pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'),
[221] Fix | Delete
icase)
[222] Fix | Delete
canon, sw, k, v, cn = nil
[223] Fix | Delete
candidates = []
[224] Fix | Delete
each do |k, *v|
[225] Fix | Delete
(if Regexp === k
[226] Fix | Delete
kn = nil
[227] Fix | Delete
k === key
[228] Fix | Delete
else
[229] Fix | Delete
kn = defined?(k.id2name) ? k.id2name : k
[230] Fix | Delete
pat === kn
[231] Fix | Delete
end) or next
[232] Fix | Delete
v << k if v.empty?
[233] Fix | Delete
candidates << [k, v, kn]
[234] Fix | Delete
end
[235] Fix | Delete
candidates = candidates.sort_by {|k, v, kn| kn.size}
[236] Fix | Delete
if candidates.size == 1
[237] Fix | Delete
canon, sw, * = candidates[0]
[238] Fix | Delete
elsif candidates.size > 1
[239] Fix | Delete
canon, sw, cn = candidates.shift
[240] Fix | Delete
candidates.each do |k, v, kn|
[241] Fix | Delete
next if sw == v
[242] Fix | Delete
if String === cn and String === kn
[243] Fix | Delete
if cn.rindex(kn, 0)
[244] Fix | Delete
canon, sw, cn = k, v, kn
[245] Fix | Delete
next
[246] Fix | Delete
elsif kn.rindex(cn, 0)
[247] Fix | Delete
next
[248] Fix | Delete
end
[249] Fix | Delete
end
[250] Fix | Delete
throw :ambiguous, key
[251] Fix | Delete
end
[252] Fix | Delete
end
[253] Fix | Delete
if canon
[254] Fix | Delete
block_given? or return key, *sw
[255] Fix | Delete
yield(key, *sw)
[256] Fix | Delete
end
[257] Fix | Delete
end
[258] Fix | Delete
[259] Fix | Delete
def convert(opt = nil, val = nil, *)
[260] Fix | Delete
val
[261] Fix | Delete
end
[262] Fix | Delete
end
[263] Fix | Delete
[264] Fix | Delete
[265] Fix | Delete
#
[266] Fix | Delete
# Map from option/keyword string to object with completion.
[267] Fix | Delete
#
[268] Fix | Delete
class OptionMap < Hash
[269] Fix | Delete
include Completion
[270] Fix | Delete
end
[271] Fix | Delete
[272] Fix | Delete
[273] Fix | Delete
#
[274] Fix | Delete
# Individual switch class. Not important to the user.
[275] Fix | Delete
#
[276] Fix | Delete
# Defined within Switch are several Switch-derived classes: NoArgument,
[277] Fix | Delete
# RequiredArgument, etc.
[278] Fix | Delete
#
[279] Fix | Delete
class Switch
[280] Fix | Delete
attr_reader :pattern, :conv, :short, :long, :arg, :desc, :block
[281] Fix | Delete
[282] Fix | Delete
#
[283] Fix | Delete
# Guesses argument style from +arg+. Returns corresponding
[284] Fix | Delete
# OptionParser::Switch class (OptionalArgument, etc.).
[285] Fix | Delete
#
[286] Fix | Delete
def self.guess(arg)
[287] Fix | Delete
case arg
[288] Fix | Delete
when ""
[289] Fix | Delete
t = self
[290] Fix | Delete
when /\A=?\[/
[291] Fix | Delete
t = Switch::OptionalArgument
[292] Fix | Delete
when /\A\s+\[/
[293] Fix | Delete
t = Switch::PlacedArgument
[294] Fix | Delete
else
[295] Fix | Delete
t = Switch::RequiredArgument
[296] Fix | Delete
end
[297] Fix | Delete
self >= t or incompatible_argument_styles(arg, t)
[298] Fix | Delete
t
[299] Fix | Delete
end
[300] Fix | Delete
[301] Fix | Delete
def self.incompatible_argument_styles(arg, t)
[302] Fix | Delete
raise ArgumentError, "#{arg}: incompatible argument styles\n #{self}, #{t}"
[303] Fix | Delete
end
[304] Fix | Delete
[305] Fix | Delete
def self.pattern
[306] Fix | Delete
NilClass
[307] Fix | Delete
end
[308] Fix | Delete
[309] Fix | Delete
def initialize(pattern = nil, conv = nil,
[310] Fix | Delete
short = nil, long = nil, arg = nil,
[311] Fix | Delete
desc = ([] if short or long), block = Proc.new)
[312] Fix | Delete
raise if Array === pattern
[313] Fix | Delete
@pattern, @conv, @short, @long, @arg, @desc, @block =
[314] Fix | Delete
pattern, conv, short, long, arg, desc, block
[315] Fix | Delete
end
[316] Fix | Delete
[317] Fix | Delete
#
[318] Fix | Delete
# Parses +arg+ and returns rest of +arg+ and matched portion to the
[319] Fix | Delete
# argument pattern. Yields when the pattern doesn't match substring.
[320] Fix | Delete
#
[321] Fix | Delete
def parse_arg(arg)
[322] Fix | Delete
pattern or return nil, arg
[323] Fix | Delete
unless m = pattern.match(arg)
[324] Fix | Delete
yield(InvalidArgument, arg)
[325] Fix | Delete
return arg, nil
[326] Fix | Delete
end
[327] Fix | Delete
if String === m
[328] Fix | Delete
m = [s = m]
[329] Fix | Delete
else
[330] Fix | Delete
m = m.to_a
[331] Fix | Delete
s = m[0]
[332] Fix | Delete
return nil, m unless String === s
[333] Fix | Delete
end
[334] Fix | Delete
raise InvalidArgument, arg unless arg.rindex(s, 0)
[335] Fix | Delete
return nil, m if s.length == arg.length
[336] Fix | Delete
yield(InvalidArgument, arg) # didn't match whole arg
[337] Fix | Delete
return arg[s.length..-1], m
[338] Fix | Delete
end
[339] Fix | Delete
private :parse_arg
[340] Fix | Delete
[341] Fix | Delete
#
[342] Fix | Delete
# Parses argument, converts and returns +arg+, +block+ and result of
[343] Fix | Delete
# conversion. Yields at semi-error condition instead of raising an
[344] Fix | Delete
# exception.
[345] Fix | Delete
#
[346] Fix | Delete
def conv_arg(arg, val = nil)
[347] Fix | Delete
if conv
[348] Fix | Delete
val = conv.call(*val)
[349] Fix | Delete
else
[350] Fix | Delete
val = proc {|val| val}.call(*val)
[351] Fix | Delete
end
[352] Fix | Delete
return arg, block, val
[353] Fix | Delete
end
[354] Fix | Delete
private :conv_arg
[355] Fix | Delete
[356] Fix | Delete
#
[357] Fix | Delete
# Produces the summary text. Each line of the summary is yielded to the
[358] Fix | Delete
# block (without newline).
[359] Fix | Delete
#
[360] Fix | Delete
# +sdone+:: Already summarized short style options keyed hash.
[361] Fix | Delete
# +ldone+:: Already summarized long style options keyed hash.
[362] Fix | Delete
# +width+:: Width of left side (option part). In other words, the right
[363] Fix | Delete
# side (description part) starts after +width+ columns.
[364] Fix | Delete
# +max+:: Maximum width of left side -> the options are filled within
[365] Fix | Delete
# +max+ columns.
[366] Fix | Delete
# +indent+:: Prefix string indents all summarized lines.
[367] Fix | Delete
#
[368] Fix | Delete
def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "")
[369] Fix | Delete
sopts, lopts, s = [], [], nil
[370] Fix | Delete
@short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
[371] Fix | Delete
@long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
[372] Fix | Delete
return if sopts.empty? and lopts.empty? # completely hidden
[373] Fix | Delete
[374] Fix | Delete
left = [sopts.join(', ')]
[375] Fix | Delete
right = desc.dup
[376] Fix | Delete
[377] Fix | Delete
while s = lopts.shift
[378] Fix | Delete
l = left[-1].length + s.length
[379] Fix | Delete
l += arg.length if left.size == 1 && arg
[380] Fix | Delete
l < max or sopts.empty? or left << ''
[381] Fix | Delete
left[-1] << if left[-1].empty? then ' ' * 4 else ', ' end << s
[382] Fix | Delete
end
[383] Fix | Delete
[384] Fix | Delete
left[0] << arg if arg
[385] Fix | Delete
mlen = left.collect {|s| s.length}.max.to_i
[386] Fix | Delete
while mlen > width and l = left.shift
[387] Fix | Delete
mlen = left.collect {|s| s.length}.max.to_i if l.length == mlen
[388] Fix | Delete
yield(indent + l)
[389] Fix | Delete
end
[390] Fix | Delete
[391] Fix | Delete
while begin l = left.shift; r = right.shift; l or r end
[392] Fix | Delete
l = l.to_s.ljust(width) + ' ' + r if r and !r.empty?
[393] Fix | Delete
yield(indent + l)
[394] Fix | Delete
end
[395] Fix | Delete
[396] Fix | Delete
self
[397] Fix | Delete
end
[398] Fix | Delete
[399] Fix | Delete
def add_banner(to) # :nodoc:
[400] Fix | Delete
unless @short or @long
[401] Fix | Delete
s = desc.join
[402] Fix | Delete
to << " [" + s + "]..." unless s.empty?
[403] Fix | Delete
end
[404] Fix | Delete
to
[405] Fix | Delete
end
[406] Fix | Delete
[407] Fix | Delete
def match_nonswitch?(str) # :nodoc:
[408] Fix | Delete
@pattern =~ str unless @short or @long
[409] Fix | Delete
end
[410] Fix | Delete
[411] Fix | Delete
#
[412] Fix | Delete
# Main name of the switch.
[413] Fix | Delete
#
[414] Fix | Delete
def switch_name
[415] Fix | Delete
(long.first || short.first).sub(/\A-+(?:\[no-\])?/, '')
[416] Fix | Delete
end
[417] Fix | Delete
[418] Fix | Delete
#
[419] Fix | Delete
# Switch that takes no arguments.
[420] Fix | Delete
#
[421] Fix | Delete
class NoArgument < self
[422] Fix | Delete
[423] Fix | Delete
#
[424] Fix | Delete
# Raises an exception if any arguments given.
[425] Fix | Delete
#
[426] Fix | Delete
def parse(arg, argv)
[427] Fix | Delete
yield(NeedlessArgument, arg) if arg
[428] Fix | Delete
conv_arg(arg)
[429] Fix | Delete
end
[430] Fix | Delete
[431] Fix | Delete
def self.incompatible_argument_styles(*)
[432] Fix | Delete
end
[433] Fix | Delete
[434] Fix | Delete
def self.pattern
[435] Fix | Delete
Object
[436] Fix | Delete
end
[437] Fix | Delete
end
[438] Fix | Delete
[439] Fix | Delete
#
[440] Fix | Delete
# Switch that takes an argument.
[441] Fix | Delete
#
[442] Fix | Delete
class RequiredArgument < self
[443] Fix | Delete
[444] Fix | Delete
#
[445] Fix | Delete
# Raises an exception if argument is not present.
[446] Fix | Delete
#
[447] Fix | Delete
def parse(arg, argv)
[448] Fix | Delete
unless arg
[449] Fix | Delete
raise MissingArgument if argv.empty?
[450] Fix | Delete
arg = argv.shift
[451] Fix | Delete
end
[452] Fix | Delete
conv_arg(*parse_arg(arg) {|*exc| raise(*exc)})
[453] Fix | Delete
end
[454] Fix | Delete
end
[455] Fix | Delete
[456] Fix | Delete
#
[457] Fix | Delete
# Switch that can omit argument.
[458] Fix | Delete
#
[459] Fix | Delete
class OptionalArgument < self
[460] Fix | Delete
[461] Fix | Delete
#
[462] Fix | Delete
# Parses argument if given, or uses default value.
[463] Fix | Delete
#
[464] Fix | Delete
def parse(arg, argv, &error)
[465] Fix | Delete
if arg
[466] Fix | Delete
conv_arg(*parse_arg(arg, &error))
[467] Fix | Delete
else
[468] Fix | Delete
conv_arg(arg)
[469] Fix | Delete
end
[470] Fix | Delete
end
[471] Fix | Delete
end
[472] Fix | Delete
[473] Fix | Delete
#
[474] Fix | Delete
# Switch that takes an argument, which does not begin with '-'.
[475] Fix | Delete
#
[476] Fix | Delete
class PlacedArgument < self
[477] Fix | Delete
[478] Fix | Delete
#
[479] Fix | Delete
# Returns nil if argument is not present or begins with '-'.
[480] Fix | Delete
#
[481] Fix | Delete
def parse(arg, argv, &error)
[482] Fix | Delete
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
[483] Fix | Delete
return nil, block, nil
[484] Fix | Delete
end
[485] Fix | Delete
opt = (val = parse_arg(val, &error))[1]
[486] Fix | Delete
val = conv_arg(*val)
[487] Fix | Delete
if opt and !arg
[488] Fix | Delete
argv.shift
[489] Fix | Delete
else
[490] Fix | Delete
val[0] = nil
[491] Fix | Delete
end
[492] Fix | Delete
val
[493] Fix | Delete
end
[494] Fix | Delete
end
[495] Fix | Delete
end
[496] Fix | Delete
[497] Fix | Delete
#
[498] Fix | Delete
# Simple option list providing mapping from short and/or long option
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function