* lib/optparse.rb (OptionParser::Switch::PlacedArgument): added.
if the next argument doesn't start with '-', use it as the value. * lib/optparse.rb (OptionParser::make_switch): fixed a bug of pattern. * lib/optparse.rb (Array): no need to guard. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b18b4423c9
commit
4cad680bc2
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
Thu Jan 30 16:46:43 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* lib/optparse.rb (OptionParser::Switch::PlacedArgument): added.
|
||||||
|
if the next argument doesn't start with '-', use it as the
|
||||||
|
value.
|
||||||
|
|
||||||
|
* lib/optparse.rb (OptionParser::make_switch): fixed a bug of
|
||||||
|
pattern.
|
||||||
|
|
||||||
|
* lib/optparse.rb (Array): no need to guard.
|
||||||
|
|
||||||
Thu Jan 30 08:27:19 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
Thu Jan 30 08:27:19 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
* file.c (rb_file_s_expand_path): removed a sludge.
|
* file.c (rb_file_s_expand_path): removed a sludge.
|
||||||
|
@ -142,12 +142,20 @@ Individual switch class.
|
|||||||
def self.guess(arg)
|
def self.guess(arg)
|
||||||
case arg
|
case arg
|
||||||
when ""
|
when ""
|
||||||
self
|
t = self
|
||||||
when /\A[=\s]?\[/
|
when /\A=?\[/
|
||||||
Switch::OptionalArgument
|
t = Switch::OptionalArgument
|
||||||
|
when /\A\s+\[/
|
||||||
|
t = Switch::PlacedArgument
|
||||||
else
|
else
|
||||||
Switch::RequiredArgument
|
t = Switch::RequiredArgument
|
||||||
end
|
end
|
||||||
|
self >= t or incompatible_argument_styles(arg, t)
|
||||||
|
t
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.incompatible_argument_styles(arg, t)
|
||||||
|
raise ArgumentError, "#{arg}: incompatible argument styles\n #{self}, #{t}"
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin private
|
=begin private
|
||||||
@ -284,6 +292,8 @@ Switch that takes no arguments.
|
|||||||
yield(NeedlessArgument, arg) if arg
|
yield(NeedlessArgument, arg) if arg
|
||||||
super(arg)
|
super(arg)
|
||||||
end
|
end
|
||||||
|
def self.incompatible_argument_styles(*)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin private
|
=begin private
|
||||||
@ -303,11 +313,6 @@ Switch that takes an argument.
|
|||||||
end
|
end
|
||||||
super(*parse_arg(arg, &error))
|
super(*parse_arg(arg, &error))
|
||||||
end
|
end
|
||||||
def self.guess(arg)
|
|
||||||
self >= (t = super) or
|
|
||||||
raise ArgumentError, "#{arg}: incompatible argument styles\n #{self}, #{t}"
|
|
||||||
t
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin private
|
=begin private
|
||||||
@ -327,10 +332,14 @@ Switch that can omit argument.
|
|||||||
super(arg)
|
super(arg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def self.guess(arg)
|
end
|
||||||
self >= (t = super) or
|
|
||||||
raise ArgumentError, "#{arg}: incompatible argument styles\n #{self}, #{t}"
|
class PlacedArgument < self
|
||||||
t
|
def parse(arg, argv, &error)
|
||||||
|
unless arg or argv.empty? or /\A-/ =~ argv[0]
|
||||||
|
arg = argv.shift
|
||||||
|
end
|
||||||
|
super(*parse_arg(arg, &error))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -954,15 +963,17 @@ Default options, which never appear in option summary.
|
|||||||
not_pattern, not_conv = search(:atype, o) unless not_style
|
not_pattern, not_conv = search(:atype, o) unless not_style
|
||||||
not_style = (not_style || default_style).guess(arg = a) if a
|
not_style = (not_style || default_style).guess(arg = a) if a
|
||||||
default_style = Switch::NoArgument
|
default_style = Switch::NoArgument
|
||||||
default_pattern, conv = search(:atype, FalseClass)
|
default_pattern, conv = search(:atype, FalseClass) unless default_pattern
|
||||||
ldesc << "--no-#{q}"
|
ldesc << "--no-#{q}"
|
||||||
long << 'no-' + (q = q.downcase)
|
long << 'no-' + (q = q.downcase)
|
||||||
nolong << q
|
nolong << q
|
||||||
when /^--\[no-\]([^][=\s]*)(.+)?/
|
when /^--\[no-\]([^][=\s]*)(.+)?/
|
||||||
q, a = $1, $2
|
q, a = $1, $2
|
||||||
o = notwice(a ? Object : TrueClass, klass, 'type')
|
o = notwice(a ? Object : TrueClass, klass, 'type')
|
||||||
default_style = default_style.guess(arg = a) if a
|
if a
|
||||||
default_pattern, conv = search(:atype, o)
|
default_style = default_style.guess(arg = a)
|
||||||
|
default_pattern, conv = search(:atype, o) unless default_pattern
|
||||||
|
end
|
||||||
ldesc << "--#{q}"
|
ldesc << "--#{q}"
|
||||||
long << (o = q.downcase)
|
long << (o = q.downcase)
|
||||||
not_pattern, not_conv = search(:atype, FalseClass) unless not_style
|
not_pattern, not_conv = search(:atype, FalseClass) unless not_style
|
||||||
@ -971,32 +982,39 @@ Default options, which never appear in option summary.
|
|||||||
when /^--([^][=\s]*)(.+)?/
|
when /^--([^][=\s]*)(.+)?/
|
||||||
q, a = $1, $2
|
q, a = $1, $2
|
||||||
o = notwice(a ? NilClass : TrueClass, klass, 'type')
|
o = notwice(a ? NilClass : TrueClass, klass, 'type')
|
||||||
default_style = default_style.guess(arg = a) if a
|
if a
|
||||||
default_pattern, conv = search(:atype, o)
|
default_style = default_style.guess(arg = a)
|
||||||
|
default_pattern, conv = search(:atype, o) unless default_pattern
|
||||||
|
end
|
||||||
ldesc << "--#{q}"
|
ldesc << "--#{q}"
|
||||||
long << (o = q.downcase)
|
long << (o = q.downcase)
|
||||||
when /^-(\[\^?\]?(?:[^\\\]]|\\.)*\])(.+)?/
|
when /^-(\[\^?\]?(?:[^\\\]]|\\.)*\])(.+)?/
|
||||||
q, a = $1, $2
|
q, a = $1, $2
|
||||||
o = notwice(Object, klass, 'type')
|
o = notwice(Object, klass, 'type')
|
||||||
default_style = default_style.guess(arg = a) if a
|
if a
|
||||||
default_pattern, conv = search(:atype, o)
|
default_style = default_style.guess(arg = a)
|
||||||
|
default_pattern, conv = search(:atype, o) unless default_pattern
|
||||||
|
end
|
||||||
sdesc << "-#{q}"
|
sdesc << "-#{q}"
|
||||||
short << Regexp.new(q)
|
short << Regexp.new(q)
|
||||||
when /^-(.)(.+)?/
|
when /^-(.)(.+)?/
|
||||||
q, a = $1, $2
|
q, a = $1, $2
|
||||||
o = notwice((a ? Object : TrueClass), klass, 'type')
|
o = notwice((a ? Object : TrueClass), klass, 'type')
|
||||||
default_style = default_style.guess(arg = a) if a
|
if a
|
||||||
default_pattern, conv = search(:atype, o)
|
default_style = default_style.guess(arg = a)
|
||||||
|
default_pattern, conv = search(:atype, o) unless default_pattern
|
||||||
|
end
|
||||||
sdesc << "-#{q}"
|
sdesc << "-#{q}"
|
||||||
short << q
|
short << q
|
||||||
when /^=/
|
when /^=/
|
||||||
style = notwice(default_style.guess(arg = o), style, 'style')
|
style = notwice(default_style.guess(arg = o), style, 'style')
|
||||||
default_pattern, conv = search(:atype, Object)
|
default_pattern, conv = search(:atype, Object) unless default_pattern
|
||||||
else
|
else
|
||||||
desc.push(o)
|
desc.push(o)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
default_pattern, conv = search(:atype, Object) unless default_pattern
|
||||||
s = if short.empty? and long.empty?
|
s = if short.empty? and long.empty?
|
||||||
raise ArgumentError, "no switch given" if style or pattern or block
|
raise ArgumentError, "no switch given" if style or pattern or block
|
||||||
desc
|
desc
|
||||||
@ -1382,7 +1400,6 @@ Default options, which never appear in option summary.
|
|||||||
accept(Array) do |s|
|
accept(Array) do |s|
|
||||||
if s
|
if s
|
||||||
s = s.split(',').collect {|s| s unless s.empty?}
|
s = s.split(',').collect {|s| s unless s.empty?}
|
||||||
s.size > 1 or s = [s] # guard empty or single.
|
|
||||||
end
|
end
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user