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